From ce27827c449cf43b84666b86e263e8754bc1578f Mon Sep 17 00:00:00 2001 From: frxz751113 <156018267+frxz751113@users.noreply.github.com> Date: Wed, 21 Aug 2024 00:41:15 +0800 Subject: [PATCH] =?UTF-8?q?Update=20and=20rename=20iptv=5Fudp.py=20to=20?= =?UTF-8?q?=E7=BB=84=E6=92=ADIP=E6=90=9C=E7=B4=A2=E5=8F=8A=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E7=89=87=E6=AE=B5.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/{iptv_udp.py => 组播IP搜索及检测片段.txt} | 81 ++++++++++++++++++++ 1 file changed, 81 insertions(+) rename py/{iptv_udp.py => 组播IP搜索及检测片段.txt} (74%) diff --git a/py/iptv_udp.py b/py/组播IP搜索及检测片段.txt similarity index 74% rename from py/iptv_udp.py rename to py/组播IP搜索及检测片段.txt index 6afde6c..9a11a28 100644 --- a/py/iptv_udp.py +++ b/py/组播IP搜索及检测片段.txt @@ -287,3 +287,84 @@ def remove_duplicates_keep_order(folder_path): # 使用示例 folder_path = 'playlist' # 替换为你的文件夹路径 remove_duplicates_keep_order(folder_path) + +############################################################################################################################################## +############################################################################################################################################## +############################################################################################################################################## +############################################################################################################################################## +############################################################################################################################################## +############################################################################################################################################## +############################################################################################################################################## +############################################################################################################################################## +############################################################################################################################################## + + + +以下为组播IP流畅性检测 +import cv2 +import time +from tqdm import tqdm +# 初始化酒店源字典 +detected_ips = {} +# 存储文件路径 +file_path = "5.txt" +output_file_path = "2.txt" +def get_ip_key(url): + """从URL中提取IP地址,并构造一个唯一的键""" + # 找到'//'到第三个'.'之间的字符串 + start = url.find('://') + 3 # '://'.length 是 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 +# 打开输入文件和输出文件 +with open(file_path, 'r', encoding='utf-8') as file: + lines = file.readlines() +# 获取总行数用于进度条 +total_lines = len(lines) +# 写入通过检测的行到新文件 +with open(output_file_path, 'w', encoding='utf-8') as output_file: + # 使用tqdm显示进度条 + for i, line in tqdm(enumerate(lines), total=total_lines, desc="Processing", unit='line'): + # 检查是否包含 'genre' + if 'genre' in line: + output_file.write(line) + continue + # 分割频道名称和URL,并去除空白字符 + parts = line.split(',', 1) + if len(parts) == 2: + channel_name, url = parts + channel_name = channel_name.strip() + url = url.strip() + # 构造IP键 + ip_key = get_ip_key(url) + if ip_key and ip_key in detected_ips: + # 如果IP键已存在,根据之前的结果决定是否写入新文件 + if detected_ips[ip_key]['status'] == 'ok': + output_file.write(line) + elif ip_key: # 新IP键,进行检测 + # 进行检测 + cap = cv2.VideoCapture(url) + start_time = time.time() + frame_count = 0 + # 尝试捕获10秒内的帧 + while frame_count < 60 and (time.time() - start_time) < 3: + ret, frame = cap.read() + if not ret: + break + frame_count += 1 + # 释放资源 + cap.release() + # 根据捕获的帧数判断状态并记录结果 + if frame_count >= 60: #10秒内超过230帧则写入 + 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']}")