iptv直播源列表批量检测有效性脚本
通过iptv
直播源列表列表,检测列txt
列表中m3u8
直播源有效性,m3u
格式播放列表可自行转换。检测代码包含php
和python
两个版本,无需安装其他框架、依赖,配合Code Runner
插件在vscodeCode
编辑器中直接执行,或保存为本地文件在终端中运行(需要安装运行环境)。
效果
代码
iptv_check.php<?php
$remoteFilePath = 'https://domain.com/iptv.txt'; $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.pyimport 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}")
|
条评论