From b6c6187d5131e5de0a7d97b1e02950921d4faec4 Mon Sep 17 00:00:00 2001 From: frxz751113 <156018267+frxz751113@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:44:06 +0800 Subject: [PATCH] =?UTF-8?q?Update=20IPTV+=E6=B5=8B=E7=BB=98=E7=AB=99?= =?UTF-8?q?=E9=87=87=E9=9B=86.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/IPTV+测绘站采集.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/py/IPTV+测绘站采集.py b/py/IPTV+测绘站采集.py index 735aa5e..7b4dd4a 100644 --- a/py/IPTV+测绘站采集.py +++ b/py/IPTV+测绘站采集.py @@ -59,7 +59,6 @@ def get_tonkiang(keyword): print(f"获取IP时发生错误: {e}") return [] -# 生成文件 def gen_files(valid_ips, province, isp): # 生成节目列表 省份运营商.txt index = 0 @@ -71,14 +70,17 @@ def gen_files(valid_ips, province, isp): with open(txt_filename, 'a', encoding='utf-8') as new_file: new_file.write(f'{province}{isp},#genre#\n') for url in valid_ips: - if index < 3: - original_protocol = data.split("://")[0] + "://" - new_data = data.replace("rtp://", f"http://{url[0]}/rtp/") - new_file.write(new_data) + if index < 5: + # 确保 url 是一个完整的 URL 字符串,并且以 'http://' 开头 + base_url = "rtp://" + if not url.startswith("http://"): + url = "http://" + url # 如果 url 不是以 'http://' 开头,则添加它 + new_data = data.replace(base_url, url + "/") # 替换并添加斜杠 + new_file.write(new_data.replace("\n", "")) # 替换后去掉末尾的换行符 new_file.write('\n') index += 1 else: - continue + break # 替换 continue 为 break,因为你只需要前5个 IP print(f'已生成播放列表,保存至{txt_filename}') # 遍历rtp文件夹中的所有文件