From f951483cf4b7ef3d704e1900e4b353880bc64b49 Mon Sep 17 00:00:00 2001 From: frxz751113 <156018267+frxz751113@users.noreply.github.com> Date: Sun, 18 Aug 2024 10:47:11 +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 | 81 +++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 23 deletions(-) diff --git a/py/iptv流畅度检测.py b/py/iptv流畅度检测.py index 5d68385..8fe1439 100644 --- a/py/iptv流畅度检测.py +++ b/py/iptv流畅度检测.py @@ -149,6 +149,9 @@ 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)) @@ -156,6 +159,9 @@ 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) # 创建正则表达式模式,匹配任意一个关键字 @@ -165,18 +171,22 @@ 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('\niHOT系列,#genre#\n') #写入临时文件名$GD + c1.write('\n组播剧场,#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) # 创建正则表达式模式,匹配任意一个关键字 @@ -186,6 +196,8 @@ 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 = ['湖南', '广东', '广州', '河南', '河北'] # 需要提取的关键字列表 pattern = '|'.join(keywords) # 创建正则表达式模式,匹配任意一个关键字 #pattern = r"^(.*?),(?!#genre#)(.*?)$" #以分类直接复制 @@ -195,6 +207,9 @@ with open('组播源.txt', 'r', encoding='utf-8') as file, open('df1.txt', 'w', 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 = ['河北', '石家庄', '丰宁', '临漳', '井陉', '井陉矿区', '保定', '元氏', '兴隆', '内丘', '南宫', '吴桥', '唐县', '唐山', '安平', '定州', '大厂', '张家口', '徐水', '成安', \ '承德', '故城', '康保', '廊坊', '晋州', '景县', '武安', '枣强', '柏乡', '涉县', '涞水', '涞源', '涿州', '深州', '深泽', '清河', '秦皇岛', '衡水', '遵化', '邢台', '邯郸', \ @@ -207,6 +222,9 @@ with open('组播源.txt', 'r', encoding='utf-8') as file, open('i0.txt', 'w', e 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 = ['河南', '焦作', '开封', '卢氏', '洛阳', '孟津', '安阳', '宝丰', '邓州', '渑池', '南阳', '内黄', '平顶山', '淇县', '郏县', '封丘', '获嘉', '巩义', '杞县', '汝阳', '三门峡', '卫辉', '淅川', \ '新密', '新乡', '信阳', '新郑', '延津', '叶县', '义马', '永城', '禹州', '原阳', '镇平', '郑州', '周口'] # 需要提取的关键字列表 @@ -220,6 +238,7 @@ with open('组播源.txt', 'r', encoding='utf-8') as file, open('f1.txt', 'w', e f1.write(line) # 将该行写入输出文件 +################################################################################################## #从整理好的文本中按类别进行特定关键词提取# keywords = ['广东', '广州', '汕头'] # 需要提取的关键字列表 pattern = '|'.join(keywords) # 创建正则表达式模式,匹配任意一个关键字 @@ -231,6 +250,7 @@ with open('组播源.txt', 'r', encoding='utf-8') as file, open('f2.txt', 'w', e if re.search(pattern, line): # 如果行中有任意关键字 f2.write(line) # 将该行写入输出文件 +################################################################################################## #从整理好的文本中按类别进行特定关键词提取# keywords = ['广东', '广东'] # 需要提取的关键字列表 pattern = '|'.join(keywords) # 创建正则表达式模式,匹配任意一个关键字 @@ -242,17 +262,16 @@ with open('组播源.txt', 'r', encoding='utf-8') as file, open('f3.txt', 'w', e 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" #源采集地址 @@ -300,7 +319,10 @@ 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#' @@ -339,9 +361,10 @@ 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 = [] @@ -353,8 +376,10 @@ 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() # 使用列表来存储唯一的行的顺序 @@ -368,7 +393,10 @@ 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-综合,") @@ -408,7 +436,10 @@ for line in fileinput.input("综合源.txt", inplace=True): #打开临时文 line = line.replace("[720p]", "") line = line.replace("[1080p]", "") print(line, end="") -#简体转繁体# + + + +################################################################################################## #简体转繁体 # 创建一个OpenCC对象,指定转换的规则为繁体字转简体字 converter = OpenCC('t2s.json')#繁转简 @@ -421,7 +452,9 @@ 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: @@ -447,6 +480,9 @@ 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"] @@ -456,17 +492,16 @@ for file in files_to_remove: 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):