From 754d335d982857e242c8529fdd7863df24bc7cbb Mon Sep 17 00:00:00 2001 From: frxz751113 <156018267+frxz751113@users.noreply.github.com> Date: Mon, 26 Aug 2024 00:59:10 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E4=B8=80=E9=94=85=E7=83=A9.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/一锅烩.py | 134 +++++++++++++++++++++++++-------------------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/py/一锅烩.py b/py/一锅烩.py index 14ce39c..1d681d6 100644 --- a/py/一锅烩.py +++ b/py/一锅烩.py @@ -344,73 +344,6 @@ with open('2.txt', 'w', encoding='utf-8') as new_file: new_file.write(line) # 写入新文件 print("新文件已保存。") # 打印完成信息 -######################################################################################################## -######################################################################################################## -# 函数:获取视频分辨率 -def get_video_resolution(video_path, timeout=0.8): - cap = cv2.VideoCapture(video_path) - if not cap.isOpened(): - return None - width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) - height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) - cap.release() - return (width, height) -# 函数:处理每一行 -def process_line(line, output_file, order_list, valid_count, invalid_count, total_lines): - parts = line.strip().split(',') - if '#genre#' in line: - # 如果行包含 '#genre#',直接写入新文件 - with threading.Lock(): - output_file.write(line) - print(f"已写入genre行:{line.strip()}") - elif len(parts) == 2: - channel_name, channel_url = parts - resolution = get_video_resolution(channel_url, timeout=8) - if resolution and resolution[1] >= 720: # 检查分辨率是否大于等于720p - with threading.Lock(): - output_file.write(f"{channel_name}[{resolution[1]}p],{channel_url}\n") - order_list.append((channel_name, resolution[1], channel_url)) - valid_count[0] += 1 - print(f"Channel '{channel_name}' accepted with resolution {resolution[1]}p at URL {channel_url}.") - else: - invalid_count[0] += 1 - with threading.Lock(): - print(f"有效: {valid_count[0]}, 无效: {invalid_count[0]}, 总数: {total_lines}, 进度: {(valid_count[0] + invalid_count[0]) / total_lines * 100:.2f}%") -# 函数:多线程工作 -def worker(task_queue, output_file, order_list, valid_count, invalid_count, total_lines): - while True: - try: - line = task_queue.get(timeout=1) - process_line(line, output_file, order_list, valid_count, invalid_count, total_lines) - except Queue.Empty: - break - finally: - task_queue.task_done() -# 主函数 -def main(source_file_path, output_file_path): - order_list = [] - valid_count = [0] - invalid_count = [0] - task_queue = Queue() - # 读取源文件 - with open(source_file_path, 'r', encoding='utf-8') as source_file: - lines = source_file.readlines() - with open(output_file_path + '.txt', 'w', encoding='utf-8') as output_file: - # 创建线程池 - with ThreadPoolExecutor(max_workers=64) as executor: - # 创建并启动工作线程 - for _ in range(64): - executor.submit(worker, task_queue, output_file, order_list, valid_count, invalid_count, len(lines)) - # 将所有行放入队列 - for line in lines: - task_queue.put(line) - # 等待队列中的所有任务完成 - task_queue.join() - print(f"任务完成,有效频道数:{valid_count[0]}, 无效频道数:{invalid_count[0]}, 总频道数:{len(lines)}") -if __name__ == "__main__": - source_file_path = '2.txt' # 替换为你的源文件路径 - output_file_path = '2' # 替换为你的输出文件路径,不要后缀名 - main(source_file_path, output_file_path) @@ -564,6 +497,73 @@ for line in lines: with open('回收站.txt', 'w', encoding="utf-8") as file: file.writelines(unique_lines) +######################################################################################################## +######################################################################################################## +# 函数:获取视频分辨率 +def get_video_resolution(video_path, timeout=0.8): + cap = cv2.VideoCapture(video_path) + if not cap.isOpened(): + return None + width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) + height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) + cap.release() + return (width, height) +# 函数:处理每一行 +def process_line(line, output_file, order_list, valid_count, invalid_count, total_lines): + parts = line.strip().split(',') + if '#genre#' in line: + # 如果行包含 '#genre#',直接写入新文件 + with threading.Lock(): + output_file.write(line) + print(f"已写入genre行:{line.strip()}") + elif len(parts) == 2: + channel_name, channel_url = parts + resolution = get_video_resolution(channel_url, timeout=8) + if resolution and resolution[1] >= 720: # 检查分辨率是否大于等于720p + with threading.Lock(): + output_file.write(f"{channel_name}[{resolution[1]}p],{channel_url}\n") + order_list.append((channel_name, resolution[1], channel_url)) + valid_count[0] += 1 + print(f"Channel '{channel_name}' accepted with resolution {resolution[1]}p at URL {channel_url}.") + else: + invalid_count[0] += 1 + with threading.Lock(): + print(f"有效: {valid_count[0]}, 无效: {invalid_count[0]}, 总数: {total_lines}, 进度: {(valid_count[0] + invalid_count[0]) / total_lines * 100:.2f}%") +# 函数:多线程工作 +def worker(task_queue, output_file, order_list, valid_count, invalid_count, total_lines): + while True: + try: + line = task_queue.get(timeout=1) + process_line(line, output_file, order_list, valid_count, invalid_count, total_lines) + except Queue.Empty: + break + finally: + task_queue.task_done() +# 主函数 +def main(source_file_path, output_file_path): + order_list = [] + valid_count = [0] + invalid_count = [0] + task_queue = Queue() + # 读取源文件 + with open(source_file_path, 'r', encoding='utf-8') as source_file: + lines = source_file.readlines() + with open(output_file_path + '.txt', 'w', encoding='utf-8') as output_file: + # 创建线程池 + with ThreadPoolExecutor(max_workers=64) as executor: + # 创建并启动工作线程 + for _ in range(1): + executor.submit(worker, task_queue, output_file, order_list, valid_count, invalid_count, len(lines)) + # 将所有行放入队列 + for line in lines: + task_queue.put(line) + # 等待队列中的所有任务完成 + task_queue.join() + print(f"任务完成,有效频道数:{valid_count[0]}, 无效频道数:{invalid_count[0]}, 总频道数:{len(lines)}") +if __name__ == "__main__": + source_file_path = '回收站.txt' # 替换为你的源文件路径 + output_file_path = '回收站' # 替换为你的输出文件路径,不要后缀名 + main(source_file_path, output_file_path) ################################################################################################任务结束,删除不必要的过程文件