From 53b8cffa18921b0cc02b988585c5aedfb2ab9df5 Mon Sep 17 00:00:00 2001 From: frxz751113 <156018267+frxz751113@users.noreply.github.com> Date: Mon, 19 Aug 2024 11:19:18 +0800 Subject: [PATCH] =?UTF-8?q?Update=20iptv=E6=B5=81=E7=95=85=E5=BA=A6?= =?UTF-8?q?=E6=A3=80=E6=B5=8B.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/iptv流畅度检测.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/py/iptv流畅度检测.py b/py/iptv流畅度检测.py index 2342a56..3e611c5 100644 --- a/py/iptv流畅度检测.py +++ b/py/iptv流畅度检测.py @@ -121,7 +121,7 @@ for keyword in keywords: with open(rtp_filename, 'r', encoding='utf-8') as file: data = file.read() txt_filename = f'playlist/{province}{isp}.txt' - with open(txt_filename, 'w') as new_file: + with open(txt_filename, 'a') as new_file: #以追加形式写入 for url in valid_ips: new_data = data.replace("rtp://", f"{url}/rtp/") new_file.write(new_data) @@ -134,6 +134,27 @@ for keyword in keywords: break else: print(f"{current_time} 搜索IPTV频道源[],超时次数过多:{timeout_cnt} 次,停止处理") + +# 打开文档并读取所有行 +with open(txt_filename, 'r', encoding="utf-8") as file: + lines = file.readlines() +# 使用列表来存储唯一的行的顺序 +unique_lines = [] +seen_lines = set() +# 打印去重前的行数 +print(f"去重前的行数: {len(lines)}") +# 遍历每一行,如果是新的就加入unique_lines +for line in lines: + line_stripped = line.strip() # 去除行尾的换行符 + if line_stripped not in seen_lines: + unique_lines.append(line) # 保持原始行的格式,包括换行符 + seen_lines.add(line_stripped) +# 将唯一的行写入新的文档 +with open(txt_filename, 'w', encoding="utf-8") as file: + file.writelines(unique_lines) +# 打印去重后的行数 +print(f"去重后的行数: {len(unique_lines)}") + print('节目表制作完成! 文件输出在playlist文件夹!') ###################################################################################################################### ######################################################################################################################