From 6fd0f61aeef1dd15ce278d533be157af3769c899 Mon Sep 17 00:00:00 2001 From: frxz751113 <156018267+frxz751113@users.noreply.github.com> Date: Thu, 29 Aug 2024 19:17:36 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E9=85=92=E5=BA=97=E6=BA=90.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/酒店源.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/py/酒店源.py b/py/酒店源.py index 1a964f5..d853f8a 100644 --- a/py/酒店源.py +++ b/py/酒店源.py @@ -82,11 +82,25 @@ with open('iptv.txt', 'w', encoding='utf-8') as outfile: if 'hls' in line and ('udp' not in line and 'rtp' not in line): line = line.strip() if line: - # 直接使用原始URL,不进行IP变体生成 + # 解析json_url以提取IP和端口 + parsed_json_url = urlparse(json_url) + json_ip = parsed_json_url.hostname + json_port = ':' + parsed_json_url.port if parsed_json_url.port else '' + + # 分割行以获取频道名和原始URL + name, channel_url = line.split(',') + + # 替换原始URL中的IP地址和端口为json_url中的IP地址和端口 + new_channel_url = channel_url.replace(channel_url.split('/')[2], json_ip) + if json_port: + new_channel_url = new_channel_url.replace(f":{channel_url.split(':')[1]}", json_port) + # 写入到文件中 - outfile.write(line + '\n') + outfile.write(f"{name},{new_channel_url}\n") except requests.exceptions.RequestException as e: print(f"Error fetching or processing the JSON data: {e}") + +print("频道列表文件iptv.txt获取完成!") print("频道列表文件iptv.txt获取完成!")