抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

通过iptv直播源列表列表,检测列txt列表中m3u8直播源有效性,m3u格式播放列表可自行转换。检测代码包含phppython两个版本,无需安装其他框架、依赖,配合Code Runner插件在vscodeCode编辑器中直接执行,或保存为本地文件在终端中运行(需要安装运行环境)。

效果

iptv直播源列表批量检测有效性脚本运行效果
iptv直播源列表批量检测有效性脚本运行效果

代码

iptv_check.php
<?php
/**
* @author guogb
* @link https://okraworks.cn
*/
$remoteFilePath = 'https://domain.com/iptv.txt'; // 替换为你的远程文件URL
$fileContent = file_get_contents($remoteFilePath);

if ($fileContent === FALSE) {
die("无法读取远程文件");
}

$lines = explode("\n", $fileContent);

foreach ($lines as $line) {
$parts = explode(',', $line);
if (count($parts) >= 2) {
$name = trim($parts[0]);
$url = trim($parts[1]);

if (checkUrl($url)) {
echo "✅ 有效: $name - $url\n";
} else {
echo "❌ 无效: $name - $url\n";
}
}
}

function checkUrl($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

return $httpCode == 200;
}

iptv_check.py
import requests

def check_url(url):
try:
response = requests.head(url)
return response.status_code == 200
except requests.RequestException:
return False

remote_file_url = 'https://domain.com/iptv.txt'; // 替换为你的远程文件URL

# 读取远程文件内容
try:
response = requests.get(remote_file_url)
response.raise_for_status()
file_content = response.text
except requests.RequestException:
print("无法读取远程文件")
exit(1)

lines = file_content.split('\n')

for line in lines:
parts = line.split(',')
if len(parts) >= 2:
name = parts[0].strip()
url = parts[1].strip()

if check_url(url):
print(f"✅ 有效: {name} - {url}")
else:
print(f"❌ 无效: {name} - {url}")

评论