此教程作用:

    获取多个外部的直播源列表,并获取本地文件,生成直播源,合并成一个列表,提供给只有一个直播源输入的iptv壳子使用。


  1. 下载列表模板文件:file iconindex.rar,解压上传至将要列表的文件目录。

    image.png

  2. 修改文件权限

    image.png

  3. 使用webstation创建一个web服务,目录设置为文件所在目录,设置好端口

    image.png

    image.png

  4. 使用 ip:端口/?name=分类,查看结果,如需外网访问,则路由做好端口映射即可。

    *name=文件夹名称,输出指定文件夹列表

    *name=1输出所有文件,以#genre#进行分组

    输出效果如下:

    image.png


php文件内容:

plaintext
 'https://gitcode.net/ygbh66/test/-/raw/master/hzzb.txt',
	//"中央频道" => 'https://raw.githubusercontent.com/Moexin/IPTV/Files/CCTV.m3u',
	//"卫视频道" => 'https://raw.githubusercontent.com/Moexin/IPTV/Files/CNTV.m3u',

);

// 外部频道开关。
// 0关闭 1开启 
$costom_on = 1 ;


// 以下区域不可修改!!!

// 获取脚本所在目录路径
$script_dir = dirname(__FILE__);
$dir_name = $_GET['name'];

//遍历目标目录下媒体文件,并生成拼接列表
function read_to_txt($dir){
	global $script_dir;
	global $target_extensions;
	global $host;
	
	echo $dir . ',#genre#' ."\n";
	$resultArray= traverseDirectory($dir);		
}

function traverseDirectory($dir) {
	global $host;
	global $target_extensions;
    // 扫描目录中的文件和子目录
    $files = scandir($dir);
	$result = []; // 存储文件路径的数组;
	
    // 遍历文件和子目录
    foreach ($files as $file) {
        // 忽略当前目录(.)和上级目录(..)
        if ($file == '.' || $file == '..' || $file == '@eaDir') {
            continue;
        }

        // 构建文件或子目录的完整路径
        $path = $dir . '/' . $file;

        // 如果是目录,则递归调用 traverseDirectory()
        if (is_dir($path)) {
            traverseDirectory($path);
        } else {
        	// 获取文件扩展名
            $extension = pathinfo($file, PATHINFO_EXTENSION);
            // 检查是否为指定扩展名的文件
            if (in_array($extension, $target_extensions)) {
                // url编码
                $new_file_link = pathinfo($file, PATHINFO_FILENAME) . ',' . $host . rawurlencode($path) . PHP_EOL ;
                // echo '

' . $file . ',' . $host . urlencode($path) . PHP_EOL . '

';                 echo $new_file_link;                 //写入$result列表中                 $result[] = $new_file_link; // 存储文件路径的数组             }                      }     }     // print_r($result);     return $result; } //传参判断 function main(){ global $dir_name; global $script_dir; global $custom_url; // 自定义频道链接 global $costom_on; // 自定义频道判断开关 if($costom_on=="1"){ foreach ($custom_url as $name => $url) { // 获取文件扩展名 $fileInfo = pathinfo($url); $extension = strtolower($fileInfo['extension']); // 转换为小写以进行比较 // 判断文件类型 if ($extension == 'txt') { $fileContent = file_get_contents($url); // 判断外部源中是否包含genre,即diyp格式 if (strpos($fileContent, "#genre#") !== false) { // 如果包含,只输出内容  echo read_url($url) . "\n"; } else { // 如果不包含,则加个分类标签  echo $name . ',#genre#' ."\n";  echo read_url($url) . "\n"; } } elseif ($extension == 'm3u') { echo $name . ',#genre#' ."\n"; m3utotxt($url); } else { echo "未知文件类型\n"; } } }     $dirlist = json_decode(getdir(), true);     if (in_array($dir_name, $dirlist)) {         // echo $dir_name;         read_to_txt($dir_name);     }elseif($dir_name=="1"){      foreach ($dirlist as $dir){      read_to_txt($dir);      }     }else{      //返回404错误页         http_response_code(404);         echo "注意:无参数或参数错误,未获得本地目录有效信息!";     } } // 获取当前目录下的所有文件和文件夹列表 function getdir(){ // 获取当前目录下的所有文件和文件夹列表 $filesAndFolders = scandir(__DIR__); // 遍历列表并筛选出文件夹名称 $folders = array(); foreach ($filesAndFolders as $item) {     // 排除隐藏文件和文件夹以及名为".file"的文件夹     if ($item != '.' && $item != '..' && strpos($item, '.') !== 0 && strpos($item, '@eaDir') === false) {         if (is_dir($item)) {             $folders[] = $item;         }     } } return json_encode($folders, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); } // 自定义读取外部链接 function read_url($url,$user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3') {     $ch = curl_init();     curl_setopt($ch, CURLOPT_URL, $url);     curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);     curl_setopt($ch, CURLOPT_MAXREDIRS, 10);     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);     $data = curl_exec($ch);     curl_close($ch);     return $data; } // 将M3U文件转换为TXT文件 function m3utotxt($m3uFile){     // 读取M3U文件内容     $m3uContent = file_get_contents($m3uFile);     // 将内容按行拆分     $m3uLines = explode("\n", $m3uContent);     // 初始化频道数组     $channels = [];     // 遍历每一行     for ($i = 0; $i < count($m3uLines); $i++) {         // 检查是否是EXTINF标签行         if (strpos($m3uLines[$i], '#EXTINF:') === 0) {             // 解析EXTINF标签,提取频道名和链接             $infoParts = explode(',', $m3uLines[$i], 2);             $channelInfo = $infoParts[1]; // 获取频道信息部分             // 检查是否有频道链接             if (isset($m3uLines[$i + 1])) {                 $channelLink = trim($m3uLines[$i + 1]); // 获取频道链接                 $channels[] = ['name' => $channelInfo, 'link' => $channelLink];                 echo $channelInfo ."," . $channelLink . "\n";             }         }     }     return $channels; } main(); ?>