$line) { // 去除空白字符 $line = trim($line); // 如果链接为空或已下载,则跳过 if (empty($line) || in_array($line, $downloaded_files)) { continue; } // 生成随机文件名 $file_name = generate_random_file_name(); // 下载视频文件 download_file($line, $download_dir . $file_name . '.mp4'); // 将已下载的文件名加入数组 $downloaded_files[] = $line; } /** * 生成随机文件名 */ function generate_random_file_name() { $characters = 'abcdefghijklmnopqrstuvwxyz'; $file_name = ''; for ($i = 0; $i < 8; $i++) { $file_name .= $characters[rand(0, strlen($characters) - 1)]; } return $file_name; } /** * 下载文件 */ function download_file($url, $file_path) { $ch = curl_init($url); $fp = fopen($file_path, 'wb'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_exec($ch); curl_close($ch); fclose($fp); } ?> 加一个判断功能第二次获取视频时候重复的不下载php 下载文件的目录$download_dir = ; 获取文件内容$file_content = file_get_contentshttpsapiuunlcnAPIapi-girlvideosmztxt; 将文件内容按行分割成数组$lines = exploden $file_content; 循环下载每一行的视频链接foreach $lines

原文地址: https://www.cveoy.top/t/topic/b3IR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录