Update 酒店源.py

This commit is contained in:
frxz751113
2024-08-30 01:25:45 +08:00
committed by GitHub
parent 3a4bb9a62d
commit 37b19776b5
+15 -5
View File
@@ -111,27 +111,37 @@ for url in urls:
for url in valid_urls: for url in valid_urls:
print(url) print(url)
# 遍历网址列表,获取JSON文件并解析 # 遍历网址列表,获取JSON文件并解析
for url in valid_urls: for url in valid_urls:
# 遍历 valid_urls 列表中的每个 URL
try: try:
# 发送GET请求获取JSON文件,设置超时时间为0.5秒 # 发送 GET 请求获取 JSON 文件设置超时时间为 3 秒(你代码中此处 timeout 的值为 3,不是你注释里的 0.5 秒)
json_url = f"{url}" json_url = f"{url}"
response = requests.get(json_url, timeout=3)################################ response = requests.get(json_url, timeout=3)
json_data = response.content.decode('utf-8') json_data = response.content.decode('utf-8')
# 将获取到的响应内容解码为 UTF-8 格式的字符串
try: try:
# 按行分割数据 # 按行分割数据
lines = json_data.split('\n') lines = json_data.split('\n')
for line in lines: for line in lines:
if 'hls' in line and ('udp' not in line or 'rtp' not in line): #行中需包含m3u,但排除udptrp # 检查行中需包含'hls'但排除'udp'和'trp'
if 'hls' in line and ('udp' not in line or 'rtp' not in line):
line = line.strip() line = line.strip()
if line: if line:
# 如果行不为空,进行分割操作
name, channel_url = line.split(',') name, channel_url = line.split(',')
urls = channel_url.split('/', 5) urls = channel_url.split('/', 5)
url_data = json_url.split('/', 5) url_data = json_url.split('/', 5)
if len(urls) >= 3: if len(urls) >= 5:
# 构建新的 URL
urld = (f"{urls[0]}//{url_data[1]}/{urls[2]}/{urls[3]}/{urls[4]}") urld = (f"{urls[0]}//{url_data[1]}/{urls[2]}/{urls[3]}/{urls[4]}")
else: else:
urld = (f"{urls}") urld = (f"{urls}")
print(f"{name},{urld}") print(f"{name},{urld}")
except:
pass
except:
pass
if name and urld: if name and urld:
name = name.replace("高清电影", "影迷电影") name = name.replace("高清电影", "影迷电影")
name = name.replace("中央", "CCTV") name = name.replace("中央", "CCTV")