Update iptv流畅度检测.py

This commit is contained in:
frxz751113
2024-08-20 14:22:51 +08:00
committed by GitHub
parent 68b199ae40
commit 3779a29028
+68 -1
View File
@@ -156,6 +156,73 @@ def remove_duplicates_keep_order(folder_path):
folder_path = 'playlist' # 替换为你的文件夹路径
remove_duplicates_keep_order(folder_path)
print('文件去重完成!移除存储的旧文件!')
print('对playlist文件夹里面的所有txt文件进行IP有效性检测')
# 初始化酒店源字典
detected_ips = {}
def get_ip_key(url):
"""从URL中提取IP地址,并构造一个唯一的键"""
start = url.find('://') + 3
end = start
dot_count = 0
while dot_count < 3:
end = url.find('.', end)
if end == -1:
break
dot_count += 1
return url[start:end] if dot_count == 3 else None
# 设置固定的文件夹路径
folder_path = 'playlist'
# 确保文件夹路径存在
if not os.path.isdir(folder_path):
print("指定的文件夹不存在。")
sys.exit()
# 遍历文件夹中的所有.txt文件
for filename in os.listdir(folder_path):
if filename.endswith('.txt'):
file_path = os.path.join(folder_path, filename)
# 读取文件内容
with open(file_path, 'r', encoding='utf-8') as file:
lines = file.readlines()
# 准备写回文件
with open(file_path, 'w', encoding='utf-8') as output_file:
# 使用tqdm显示进度条
for i, line in tqdm(enumerate(lines), total=len(lines), desc=f"Processing {filename}", unit='line'):
if 'genre' in line:
output_file.write(line)
continue
parts = line.split(',', 1)
if len(parts) == 2:
channel_name, url = parts
channel_name = channel_name.strip()
url = url.strip()
ip_key = get_ip_key(url)
if ip_key in detected_ips and detected_ips[ip_key]['status'] == 'ok':
output_file.write(line)
elif ip_key:
# 尝试打开视频流
cap = cv2.VideoCapture(url)
start_time = time.time()
frame_count = 0
while frame_count < 20 and (time.time() - start_time) < 10:
ret, frame = cap.read()
if not ret:
break
frame_count += 1
cap.release()
if frame_count >= 20:
detected_ips[ip_key] = {'status': 'ok'}
output_file.write(line)
else:
detected_ips[ip_key] = {'status': 'fail'}
# 打印检测结果
for ip_key, result in detected_ips.items():
print(f"IP Key: {ip_key}, Status: {result['status']}")
######################################################################################################################
######################################################################################################################
######################################################################################################################
@@ -516,7 +583,7 @@ check_and_write_file('2.txt', 'a.txt', keywords="央视频道, CCTV, CHC, 全
check_and_write_file('2.txt', 'b.txt', keywords="卫视频道, 卫视, 凤凰, 星空")
check_and_write_file('2.txt', 'c0.txt', keywords="组播剧场, 第一剧场, 怀旧剧场, 风云音乐, 风云剧场, 欢笑剧场, 都市剧场, 高清电影, 家庭影院, 动作电影, 影迷, 峨眉, 重温, 女性, 地理")
check_and_write_file('2.txt', 'c.txt', keywords="组播剧场, 爱动漫, SiTV, 爱怀旧, 爱经典, 爱科幻, 爱青春, 爱悬疑, 爱幼教, 爱院线")
check_and_write_file('2.txt', 'd.txt', keywords="少儿频道, 少儿, 卡通, 动漫, 宝贝, 哈哈, 学堂")
#check_and_write_file('2.txt', 'd.txt', keywords="少儿频道, 少儿, 卡通, 动漫, 宝贝, 哈哈, 学堂")
check_and_write_file('2.txt', 'e0.txt', keywords="河南频道, 河南都市, 河南民生, 河南法治, 河南公共, 河南功夫, 河南影视, 中原, 河南国际, 河南梨园, 河南文, 河南武术, 河南戏曲, 河南乡村, 河南新闻, 河南移动")
check_and_write_file('2.txt', 'e.txt', keywords="河南频道, 河南")
check_and_write_file('2.txt', 'f0.txt', keywords="河北频道, 石家庄")