From f3b09dcb7d49d24f45bf44407b87ee11ea181558 Mon Sep 17 00:00:00 2001 From: frxz751113 <156018267+frxz751113@users.noreply.github.com> Date: Sun, 18 Aug 2024 10:57:26 +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 | 140 +++++++++++++------------------------------ 1 file changed, 41 insertions(+), 99 deletions(-) diff --git a/py/iptv流畅度检测.py b/py/iptv流畅度检测.py index db07e8d..6dff097 100644 --- a/py/iptv流畅度检测.py +++ b/py/iptv流畅度检测.py @@ -133,15 +133,15 @@ for keyword in keywords: continue else: print(f"{current_time} 搜索IPTV频道源[],超时次数过多:{timeout_cnt} 次,停止处理") -print('节目表制作完成! 文件输出在playlist文件夹!') - - - +print('节目表制作完成! 文件输出在当前文件夹!') +###################################################################################################################### +###################################################################################################################### +###################################################################################################################### ###################################################################################################################### ###################################################################################################################### # 合并自定义频道文件,综合源整理 file_contents = [] -file_paths = ["playlist/四川电信.txt", "playlist/河南电信.txt", "playlist/河北电信.txt", "playlist/湖北电信.txt", "playlist/广东电信.txt"] # 替换为实际的文件路径列表 +file_paths = ["playlist/四川电信.txt", "playlist/河南电信.txt", "playlist/河北电信.txt"] # 替换为实际的文件路径列表 for file_path in file_paths: if os.path.exists(file_path): with open(file_path, 'r', encoding="utf-8") as file: @@ -149,9 +149,6 @@ for file_path in file_paths: file_contents.append(content) else: # 如果文件不存在,则提示异常并打印提示信息 print(f"文件 {file_path} 不存在,跳过") - - -################################################################################################## # 写入合并后的文件 with open("组播源.txt", "w", encoding="utf-8") as output: output.write('\n'.join(file_contents)) @@ -159,9 +156,6 @@ for line in fileinput.input("组播源.txt", inplace=True): #打开文件,并 line = line.replace("CHC电影", "CHC影迷电影") line = line.replace("高清电影", "影迷电影") print(line, end="") #设置end="",避免输出多余的换行符 - - -################################################################################################## #从整理好的文本中按类别进行特定关键词提取# keywords = ['CHC', '峨眉', '华语', '星光院线', '剧场', '家庭', '影迷', '动作', '星空', '凤凰'] # 需要提取的关键字列表 pattern = '|'.join(keywords) # 创建正则表达式模式,匹配任意一个关键字 @@ -171,22 +165,18 @@ with open('组播源.txt', 'r', encoding='utf-8') as file, open('c2.txt', 'w', e for line in file: if '$GD' not in line and '调解' not in line: if re.search(pattern, line): # 如果行中有任意关键字 - c2.write(line) # 将该行写入输出文件 - - -################################################################################################## + c2.write(line) # 将该行写入输出文件 #定义临时文件 #从整理好的文本中按类别进行特定关键词提取# keywords = ['爱动漫', '爱怀旧', '爱经典', '爱科幻', '爱幼教', '爱青春', '爱院线', '爱悬疑'] # 需要提取的关键字列表 pattern = '|'.join(keywords) # 创建正则表达式模式,匹配任意一个关键字 #pattern = r"^(.*?),(?!#genre#)(.*?)$" #以分类直接复制 with open('组播源.txt', 'r', encoding='utf-8') as file, open('c1.txt', 'w', encoding='utf-8') as c1: #定义临时文件名 - c1.write('\n组播剧场,#genre#\n') #写入临时文件名$GD + c1.write('\niHOT系列,#genre#\n') #写入临时文件名$GD for line in file: if '$GD' not in line and '4K' not in line: if re.search(pattern, line): # 如果行中有任意关键字 c1.write(line) # 将该行写入输出文件 #定义临时文件 - -################################################################################################## + #从整理好的文本中按类别进行特定关键词提取# keywords = ['4K', '8K'] # 需要提取的关键字列表 pattern = '|'.join(keywords) # 创建正则表达式模式,匹配任意一个关键字 @@ -196,35 +186,27 @@ with open('组播源.txt', 'r', encoding='utf-8') as file, open('DD.txt', 'w', e for line in file: if re.search(pattern, line): # 如果行中有任意关键字 DD.write(line) # 将该行写入输出文件 - -################################################################################################## -keywords = ['湖南', '广东', '广州', '汕头', '湖北', '武汉', '石家庄', '深圳', '河南', '河北'] # 需要提取的关键字列表 +keywords = ['湖南', '广东', '广州', '河南', '河北'] # 需要提取的关键字列表 pattern = '|'.join(keywords) # 创建正则表达式模式,匹配任意一个关键字 #pattern = r"^(.*?),(?!#genre#)(.*?)$" #以分类直接复制 with open('组播源.txt', 'r', encoding='utf-8') as file, open('df1.txt', 'w', encoding='utf-8') as df1: - #df1.write('\n组播省市,#genre#\n') + #df1.write('\n省市频道,#genre#\n') for line in file: if 'CCTV' not in line and '卫视' not in line and '影' not in line and '剧' not in line and '4K' not in line: if re.search(pattern, line): # 如果行中有任意关键字 df1.write(line) # 将该行写入输出文件 - - -################################################################################################## #从整理好的文本中按类别进行特定关键词提取# keywords = ['河北', '石家庄', '丰宁', '临漳', '井陉', '井陉矿区', '保定', '元氏', '兴隆', '内丘', '南宫', '吴桥', '唐县', '唐山', '安平', '定州', '大厂', '张家口', '徐水', '成安', \ '承德', '故城', '康保', '廊坊', '晋州', '景县', '武安', '枣强', '柏乡', '涉县', '涞水', '涞源', '涿州', '深州', '深泽', '清河', '秦皇岛', '衡水', '遵化', '邢台', '邯郸', \ '邱县', '隆化', '雄县', '阜平', '高碑店', '高邑', '魏县', '黄骅', '饶阳', '赵县', '睛彩河北', '滦南', '玉田', '崇礼', '平泉', '容城', '文安', '三河', '清河'] # 需要提取的关键字列表 pattern = '|'.join(keywords) # 创建正则表达式模式,匹配任意一个关键字 #pattern = r"^(.*?),(?!#genre#)(.*?)$" #以分类直接复制 -with open('组播源.txt', 'r', encoding='utf-8') as file, open('i0.txt', 'w', encoding='utf-8') as f: #定义临时文件名 +with open('组播源.txt', 'r', encoding='utf-8') as file, open('f.txt', 'w', encoding='utf-8') as f: #定义临时文件名 f.write('\n河北频道,#genre#\n') #写入临时文件名 for line in file: if 'CCTV' not in line and '卫视' not in line and 'CHC' not in line and '4K' not in line and 'genre' not in line: if re.search(pattern, line): # 如果行中有任意关键字 f.write(line) # 将该行写入输出文件 - - -################################################################################################## #从整理好的文本中按类别进行特定关键词提取# keywords = ['河南', '焦作', '开封', '卢氏', '洛阳', '孟津', '安阳', '宝丰', '邓州', '渑池', '南阳', '内黄', '平顶山', '淇县', '郏县', '封丘', '获嘉', '巩义', '杞县', '汝阳', '三门峡', '卫辉', '淅川', \ '新密', '新乡', '信阳', '新郑', '延津', '叶县', '义马', '永城', '禹州', '原阳', '镇平', '郑州', '周口'] # 需要提取的关键字列表 @@ -238,40 +220,17 @@ with open('组播源.txt', 'r', encoding='utf-8') as file, open('f1.txt', 'w', e f1.write(line) # 将该行写入输出文件 -################################################################################################## -#从整理好的文本中按类别进行特定关键词提取# -keywords = ['广东', '广州', '汕头'] # 需要提取的关键字列表 -pattern = '|'.join(keywords) # 创建正则表达式模式,匹配任意一个关键字 -#pattern = r"^(.*?),(?!#genre#)(.*?)$" #以分类直接复制 -with open('组播源.txt', 'r', encoding='utf-8') as file, open('f2.txt', 'w', encoding='utf-8') as f2: #定义临时文件名 - f2.write('\n广东频道,#genre#\n') #写入临时文件名 - for line in file: - if 'CCTV' not in line and '卫视' not in line and 'CHC' not in line and '4K' not in line and 'genre' not in line: - if re.search(pattern, line): # 如果行中有任意关键字 - f2.write(line) # 将该行写入输出文件 - -################################################################################################## -#从整理好的文本中按类别进行特定关键词提取# -keywords = ['广东', '广东'] # 需要提取的关键字列表 -pattern = '|'.join(keywords) # 创建正则表达式模式,匹配任意一个关键字 -#pattern = r"^(.*?),(?!#genre#)(.*?)$" #以分类直接复制 -with open('组播源.txt', 'r', encoding='utf-8') as file, open('f3.txt', 'w', encoding='utf-8') as f3: #定义临时文件名 - f3.write('\n广东频道,#genre#\n') #写入临时文件名 - for line in file: - if 'CCTV' not in line and '卫视' not in line and 'CHC' not in line and '4K' not in line and 'genre' not in line: - if re.search(pattern, line): # 如果行中有任意关键字 - f3.write(line) # 将该行写入输出文件 - - -################################################################################################## +# # 获取远程港澳台直播源文件 url = "https://raw.githubusercontent.com/frxz751113/AAAAA/main/TW.txt" #源采集地址 r = requests.get(url) open('港澳.txt','wb').write(r.content) #打开源文件并临时写入 +# + # + + - - -################################################################################################## +# #从文本中截取省市段生成两个新文件# # 获取远程港澳台直播源文件,打开文件并输出临时文件并替换关键词 url = "https://raw.githubusercontent.com/frxz751113/AAAAA/main/IPTV/汇总.txt" #源采集地址 @@ -319,10 +278,7 @@ with open(deleted_lines_file_path, 'w', encoding='utf-8') as file: file.writelines(deleted_lines) print('过滤完成,结果已保存到:', output_file_path) print('删除的行已保存到:', deleted_lines_file_path) - - - -################################################################################################## +# #从文本中截取少儿段并生成两个新文件# # 定义关键词 start_keyword = '少儿频道,#genre#' @@ -361,14 +317,13 @@ with open(deleted_lines_file_path, 'w', encoding='utf-8') as file: file.writelines(deleted_lines) print('过滤完成,结果已保存到:', output_file_path) print('删除的行已保存到:', deleted_lines_file_path) - - - -################################################################################################## +# +# + #合并所有频道文件# # 读取要合并的频道文件,并生成临时文件#合并所有频道文件# file_contents = [] -file_paths = ["a0.txt", "港澳.txt", "df0.txt", "df1.txt", "f.txt", "f1.txt", "f2.txt", "f3.txt"] # 替换为实际的文件路径列表# +file_paths = ["a0.txt", "港澳.txt", "df0.txt"] # 替换为实际的文件路径列表# for file_path in file_paths: # with open(file_path, 'r', encoding="utf-8") as file: # content = file.read() @@ -376,10 +331,8 @@ for file_path in file_paths: # 生成合并后的文件 with open("综合源.txt", "w", encoding="utf-8") as output: output.write(''.join(file_contents)) #加入\n则多一空行 - - - -##################################################################################################去重 +#去重# +#去重# with open('综合源.txt', 'r', encoding="utf-8") as file: lines = file.readlines() # 使用列表来存储唯一的行的顺序 @@ -393,10 +346,7 @@ for line in lines: # 将唯一的行写入新的文档 with open('综合源.txt', 'w', encoding="utf-8") as file: file.writelines(unique_lines) - - - -################################################################################################## +#再次规范频道名# #从整理好的文本中进行特定关键词替换以规范频道名# for line in fileinput.input("综合源.txt", inplace=True): #打开临时文件原地替换关键字 line = line.replace("CCTV1,", "CCTV1-综合,") @@ -436,10 +386,7 @@ for line in fileinput.input("综合源.txt", inplace=True): #打开临时文 line = line.replace("[720p]", "") line = line.replace("[1080p]", "") print(line, end="") - - - -################################################################################################## +#简体转繁体# #简体转繁体 # 创建一个OpenCC对象,指定转换的规则为繁体字转简体字 converter = OpenCC('t2s.json')#繁转简 @@ -452,9 +399,7 @@ simplified_text = converter.convert(traditional_text) # 将转换后的简体字写入txt文件 with open('综合源.txt', 'w', encoding='utf-8') as file: file.write(simplified_text) - - -########################################################################TXT转M3U# +#TXT转M3U# def txt_to_m3u(input_file, output_file): # 读取txt文件内容 with open(input_file, 'r', encoding='utf-8') as f: @@ -480,28 +425,26 @@ def txt_to_m3u(input_file, output_file): f.write(f'{channel_url}\n') # 将txt文件转换为m3u文件 txt_to_m3u('综合源.txt', '综合源.m3u') - - -################################################################################################## #任务结束,删除不必要的过程文件# -files_to_remove = ['组播源.txt', "TW.txt", "a.txt", "a0.txt", "b.txt", "b1.txt", "港澳.txt", "df0.txt", "di0.txt", "df1.txt", "sr1.txt", "sr2.txt", \ - "c2.txt", "c1.txt", "DD.txt", "i0.txt", "f.txt", "f1.txt", "f2.txt", "f3.txt"] +files_to_remove = ['组播源.txt', "TW.txt", "a.txt", "a0.txt", "b.txt", "b1.txt", "港澳.txt", "df0.txt", "df.txt", "df1.txt", "sr1.txt", "sr2.txt", \ + "c2.txt", "c1.txt", "DD.txt", "f.txt", "f1.txt"] for file in files_to_remove: if os.path.exists(file): os.remove(file) else: # 如果文件不存在,则提示异常并打印提示信息 print(f"文件 {file} 不存在,跳过删除。") print("任务运行完毕,分类频道列表可查看文件夹内综合源.txt文件!") - - -##############以下组播优选部分#########################以下组播优选部分#################################以下组播优选部分 -##############以下组播优选部分#########################以下组播优选部分#################################以下组播优选部分 #检测IP段第一个链接5秒内能否捕获80帧,来获得流畅源 from pypinyin import lazy_pinyin import re import os from opencc import OpenCC import fileinput +###################################################################################################################### +###################################################################################################################### +###################################################################################################################### +###################################################################################################################### +###################################################################################################################### # 合并自定义频道文件,优选源整理 # 假设filter_files是一个自定义函数,它返回playlist目录下所有.txt文件的路径列表 def filter_files(directory, extension): @@ -641,12 +584,11 @@ check_and_write_file('2.txt', 'b.txt', keywords="卫视频道, 卫视, 凤凰, check_and_write_file('2.txt', 'c.txt', keywords="影视频道, 爱动漫, SiTV, 爱怀旧, 爱经典, 爱科幻, 爱青春, 爱悬疑, 爱幼教, 爱院线, 影, 剧, 经典") check_and_write_file('2.txt', 'd.txt', keywords="少儿频道, 少儿, 卡通, 动漫, 宝贝, 哈哈") check_and_write_file('2.txt', 'e.txt', keywords="福建频道, 福建") -check_and_write_file('2.txt', 'g0.txt', keywords="广东频道, 广东民生, 广东体育, 广东新闻, 广东珠江, 深圳, 广州, 汕头, 佛山") +#check_and_write_file('2.txt', 'f.txt', keywords="湖南频道, 湖南") check_and_write_file('2.txt', 'g.txt', keywords="广东频道, 广东") check_and_write_file('2.txt', 'h.txt', keywords="广西频道, 广西") -check_and_write_file('2.txt', 'i0.txt', keywords="河南频道, 河南都市, 河南法治, 河南功夫, 河南公共, 河南国际, 中原, 河南移动, 河南梨园, 河南民生, 河南文, 河南武术, 河南戏曲, 河南乡村, 河南新闻") check_and_write_file('2.txt', 'i.txt', keywords="河南频道, 河南") -check_and_write_file('2.txt', 'j0.txt', keywords="河北频道, 石家庄, 睛彩河北, 河北都市, 河北农民, 河北经济") +check_and_write_file('2.txt', 'j0.txt', keywords="河北频道, 石家庄, 邢台") check_and_write_file('2.txt', 'j.txt', keywords="河北频道, 河北") check_and_write_file('2.txt', 'k.txt', keywords="北京频道, 北京") #check_and_write_file('2.txt', 'l.txt', keywords="山东频道, 山东") @@ -657,7 +599,7 @@ check_and_write_file('2.txt', 'p.txt', keywords="陕西频道, 陕西") ############################################################################################################################################################################################################################### ##############################################################对生成的文件进行合并 file_contents = [] -file_paths = ["a0.txt", "a.txt", "a1.txt", "b.txt", "c.txt", "d.txt", "j0.txt", "j.txt", "i0.txt", "i.txt", "g0.txt", "g.txt", "h.txt", "k.txt", "e.txt", "l.txt", "m.txt", "n.txt","o.txt", "p.txt"] # 替换为实际的文件路径列表 +file_paths = ["a0.txt", "a.txt", "a1.txt", "b.txt", "c.txt", "d.txt", "j0.txt", "j.txt", "e.txt", "f.txt", "g.txt", "h.txt", "i.txt", "k.txt", "l.txt", "m.txt", "n.txt","o.txt", "p.txt"] # 替换为实际的文件路径列表 for file_path in file_paths: if os.path.exists(file_path): with open(file_path, 'r', encoding="utf-8") as file: @@ -715,15 +657,15 @@ with open('组播优选.txt', 'w', encoding="utf-8") as file: for line in unique_lines: file.write(line + '\n') # 确保每行后面有换行符 # 将唯一的行追加到第二个文件 -#with open('综合源.txt', 'a', encoding="utf-8") as file: - #for line in unique_lines: - #file.write(line + '\n') # 确保每行后面有换行符 +with open('综合源.txt', 'a', encoding="utf-8") as file: + for line in unique_lines: + file.write(line + '\n') # 确保每行后面有换行符 ################################################################################################任务结束,删除不必要的过程文件 files_to_remove = ['去重.txt', '分类.txt', "2.txt", "4.txt", "5.txt", "playlist/3.txt", "a0.txt", "a.txt", "a1.txt", "b.txt", \ - "c.txt", "d.txt", "e.txt", "i0.txt", "g0.txt", "g.txt", "h.txt", "i.txt", "j0.txt", "j.txt", "k.txt", "l.txt", "m.txt", "n.txt","o.txt", "p.txt"] + "c.txt", "d.txt", "e.txt", "f.txt", "g.txt", "h.txt", "i.txt", "j0.txt", "j.txt", "k.txt", "l.txt", "m.txt", "n.txt","o.txt", "p.txt"] for file in files_to_remove: if os.path.exists(file): os.remove(file)