Update iptv-get-check.py
This commit is contained in:
+3
-36
@@ -516,43 +516,10 @@ with open("iptv.txt", 'a', encoding='utf-8') as file: #打开文本以
|
|||||||
print("频道列表文件iptv.txt追加写入成功!")
|
print("频道列表文件iptv.txt追加写入成功!")
|
||||||
|
|
||||||
|
|
||||||
#这里排序IP段去重放在了原文件头
|
|
||||||
##########################################################IP段去重
|
|
||||||
import re
|
|
||||||
def deduplicate_lines(input_file_path, output_file_path):
|
|
||||||
seen_combinations = {}
|
|
||||||
unique_lines = []
|
|
||||||
with open(input_file_path, 'r', encoding='utf-8') as file:
|
|
||||||
for line in file:
|
|
||||||
# 使用正则表达式查找行中的所有URL,并捕获IP地址、端口号和端口号之后的部分
|
|
||||||
urls = re.findall(r'http://([\d.]+):(\d+)(/.*)?', line)
|
|
||||||
# 为每个URL生成一个去重键
|
|
||||||
for full_url in urls:
|
|
||||||
ip, port, path = full_url
|
|
||||||
ip_parts = ip.split('.')
|
|
||||||
if len(ip_parts) < 3:
|
|
||||||
continue
|
|
||||||
# 使用IP的前三个字段和端口号之后的部分生成去重键
|
|
||||||
combination_key = f"{ip_parts[0]}.{ip_parts[1]}.{ip_parts[2]}-{port}-{path or ''}"
|
|
||||||
# 检查这个组合是否已经出现过
|
|
||||||
if combination_key not in seen_combinations:
|
|
||||||
# 如果没有出现过,记录当前行和去重键
|
|
||||||
seen_combinations[combination_key] = line.strip()
|
|
||||||
else:
|
|
||||||
# 如果已经出现过,更新为最后出现的行
|
|
||||||
seen_combinations[combination_key] = line.strip()
|
|
||||||
# 将去重后的所有唯一行写入新文件
|
|
||||||
with open(output_file_path, 'w', encoding='utf-8') as file:
|
|
||||||
for line in seen_combinations.values():
|
|
||||||
file.write(line + '\n')
|
|
||||||
# 调用函数
|
|
||||||
input_file_path = 'iptv.txt'
|
|
||||||
output_file_path = 'iptv.txt'
|
|
||||||
deduplicate_lines(input_file_path, output_file_path)
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
|
|
||||||
###################################################去除列表中的组播地址以及CCTV和卫视
|
|
||||||
|
###################################################去除列表中的组播地址
|
||||||
def filter_lines(input_file, output_file):
|
def filter_lines(input_file, output_file):
|
||||||
with open(input_file, 'r', encoding='utf-8') as file:
|
with open(input_file, 'r', encoding='utf-8') as file:
|
||||||
lines = file.readlines()
|
lines = file.readlines()
|
||||||
@@ -596,7 +563,7 @@ def test_connectivity(url, max_attempts=1): #定义测试HTTP连接的次数
|
|||||||
# 尝试连接指定次数
|
# 尝试连接指定次数
|
||||||
for _ in range(max_attempts):
|
for _ in range(max_attempts):
|
||||||
try:
|
try:
|
||||||
response = requests.head(url, timeout=5) # 发送HEAD请求,仅支持V4,修改此行数字可定义链接超时
|
response = requests.head(url, timeout=25) # 发送HEAD请求,仅支持V4,修改此行数字可定义链接超时
|
||||||
#response = requests.get(url, timeout=1) # 发送get请求,支持V6,修改此行数字可定义链接超时
|
#response = requests.get(url, timeout=1) # 发送get请求,支持V6,修改此行数字可定义链接超时
|
||||||
return response.status_code == 200 # 返回True如果状态码为200
|
return response.status_code == 200 # 返回True如果状态码为200
|
||||||
except requests.RequestException: # 捕获requests引发的异常
|
except requests.RequestException: # 捕获requests引发的异常
|
||||||
|
|||||||
Reference in New Issue
Block a user