Update iptv流畅度检测.py

This commit is contained in:
frxz751113
2024-08-13 18:26:15 +08:00
committed by GitHub
parent 943b7186ef
commit f1f59fdc39
+20 -6
View File
@@ -527,13 +527,27 @@ for url in urls:
channels = []
for result in results:
line = result.strip()
if result:
channel_name, channel_url = result.split(',')
#if result:
#channel_name, channel_url = result.split(',')
#channels.append((channel_name, channel_url))
#with open("iptv.txt", 'a', encoding='utf-8') as file: #打开文本以追加的形式写入行到ZHGX文件
#for result in results:
#file.write(result + "\n")
#print(result)
try:
# 尝试分割字符串,如果格式不正确则引发 ValueError
channel_name, channel_url = line.split(',', 1) # 使用逗号分割一次
channels.append((channel_name, channel_url))
with open("iptv.txt", 'a', encoding='utf-8') as file: #打开文本以追加的形式写入行到ZHGX文件
for result in results:
file.write(result + "\n")
print(result)
except ValueError:
# 如果发生 ValueError 则打印错误信息并跳过该行
print(f"跳过无法解析的行: {line}")
# 打开文本文件以追加的形式写入
with open("iptv.txt", 'a', encoding='utf-8') as file:
for channel_name, channel_url in channels:
file.write(f"{channel_name},{channel_url}\n")
print("频道列表文件iptv.txt追加写入成功!")