Update iptv流畅度检测.py

This commit is contained in:
frxz751113
2024-08-15 19:34:32 +08:00
committed by GitHub
parent 5924430b75
commit ec34309f3a
+4 -4
View File
@@ -545,11 +545,11 @@ def filter_lines(input_file, output_file):
filter_lines("iptv.txt", "iptv.txt")
#################################################### 对整理好的频道列表测试HTTP连接
def test_connectivity(url, max_attempts=1): #定义测试HTTP连接的次数
def test_connectivity(url, max_attempts=2): #定义测试HTTP连接的次数
# 尝试连接指定次数
for _ in range(max_attempts):
try:
response = requests.head(url, timeout=3) # 发送HEAD请求,仅支持V4,修改此行数字可定义链接超时##////////////////////////////////////////////////////////////////////////////////////////////////////////////////
response = requests.head(url, timeout=1) # 发送HEAD请求,仅支持V4,修改此行数字可定义链接超时##////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#response = requests.get(url, timeout=1) # 发送get请求,支持V6,修改此行数字可定义链接超时##############################//////////////////////////////////////////////////////////////////////////////////////
return response.status_code == 200 # 返回True如果状态码为200
except requests.RequestException: # 捕获requests引发的异常
@@ -716,7 +716,7 @@ with open(output_file_path, 'w', encoding='utf-8') as output_file:
start_time = time.time()
frame_count = 0
# 尝试捕获5秒内的帧
while frame_count < 66 and (time.time() - start_time) < 3:#//////////////////////////////////////////////////////////////////////////////////////###########
while frame_count < 120 and (time.time() - start_time) < 5:#//////////////////////////////////////////////////////////////////////////////////////###########
ret, frame = cap.read()
if not ret:
break
@@ -724,7 +724,7 @@ with open(output_file_path, 'w', encoding='utf-8') as output_file:
# 释放资源
cap.release()
# 根据捕获的帧数判断状态并记录结果#////////////////////////////////////////////////////////////////////////////////////////////////////////////////###########
if frame_count >= 66: #5秒内超过100帧则写入#/////////////////////////////////////////////////////////////////////////////////////////////////////###########
if frame_count >= 120: #5秒内超过100帧则写入#/////////////////////////////////////////////////////////////////////////////////////////////////////###########
detected_ips[ip_key] = {'status': 'ok'}
output_file.write(line) # 写入检测通过的行
else: