From ec7b71578588a446179db5df8bb366a833106788 Mon Sep 17 00:00:00 2001 From: frxz751113 <156018267+frxz751113@users.noreply.github.com> Date: Mon, 19 Aug 2024 03:36:05 +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 | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/py/iptv流畅度检测.py b/py/iptv流畅度检测.py index f554627..d30f0e4 100644 --- a/py/iptv流畅度检测.py +++ b/py/iptv流畅度检测.py @@ -594,11 +594,23 @@ with open('组播优选.txt', 'w', encoding="utf-8") as file: # 定义要排除的关键词列表 excluded_keywords = ['CCTV', '卫视', '关键词3'] +# 定义例外关键词列表,即使它们的行在排除列表中,也应该被保留 +exception_keywords = ['4K', '例外关键词2'] # 打开原始文本文件并读取内容 with open('组播优选.txt', 'r', encoding='utf-8') as file: lines = file.readlines() -# 过滤掉包含关键词的行 -filtered_lines = [line for line in lines if not any(keyword in line for keyword in excluded_keywords)] +# 过滤掉包含关键词的行,但保留包含例外关键词的行 +filtered_lines = [] +for line in lines: + # 检查行是否包含任何排除关键词 + contains_excluded = any(keyword in line for keyword in excluded_keywords) + # 检查行是否包含任何例外关键词 + contains_exception = any(keyword in line for keyword in exception_keywords) + # 如果行包含排除关键词但不含例外关键词,则不保留 + if contains_excluded and not contains_exception: + continue + # 否则保留该行 + filtered_lines.append(line) # 将过滤后的内容写入新的文本文件 with open('综合源.txt', 'a', encoding='utf-8') as file: file.writelines(filtered_lines)