Update 酒店源.py
This commit is contained in:
@@ -85,26 +85,59 @@ for url in urls:
|
|||||||
# urls = list(set(urls_all)) # 去重得到唯一的URL列表
|
# urls = list(set(urls_all)) # 去重得到唯一的URL列表
|
||||||
urls = set(urls_all) # 去重得到唯一的URL列表
|
urls = set(urls_all) # 去重得到唯一的URL列表
|
||||||
x_urls = []
|
x_urls = []
|
||||||
|
for url in urls: # 对urls进行处理,ip第四位修改为1,并去重
|
||||||
# 遍历网址列表,获取JSON文件并解析
|
url = url.strip()
|
||||||
results = []
|
ip_start_index = url.find("//") + 2
|
||||||
for url in urls:
|
ip_end_index = url.find(":", ip_start_index)
|
||||||
try:
|
ip_dot_start = url.find(".") + 1
|
||||||
response = requests.get(url, timeout=1)
|
ip_dot_second = url.find(".", ip_dot_start) + 1
|
||||||
json_data = response.content.decode('utf-8')
|
ip_dot_three = url.find(".", ip_dot_second) + 1
|
||||||
|
base_url = url[:ip_start_index] # http:// or https://
|
||||||
lines = json_data.split('\n')
|
ip_address = url[ip_start_index:ip_dot_three]
|
||||||
for line in lines:
|
port = url[ip_end_index:]
|
||||||
line = line.strip()
|
ip_end = "1"
|
||||||
if not line or ('udp' in line and 'rtp' in line):
|
modified_ip = f"{ip_address}{ip_end}"
|
||||||
continue
|
x_url = f"{base_url}{modified_ip}{port}"
|
||||||
if 'hls' in line:
|
x_urls.append(x_url)
|
||||||
name, channel_url = line.split(',')
|
urls = set(x_urls) # 去重得到唯一的URL列表
|
||||||
# 使用modify_urls函数替换IP地址和端口
|
valid_urls = []
|
||||||
for modified_url in modify_urls(channel_url):
|
# 多线程获取可用url
|
||||||
if is_url_accessible(modified_url):
|
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
|
||||||
# 替换频道名称中的特定文本
|
futures = []
|
||||||
if name:
|
for url in urls:
|
||||||
|
url = url.strip()
|
||||||
|
modified_urls = modify_urls(url)
|
||||||
|
for modified_url in modified_urls:
|
||||||
|
futures.append(executor.submit(is_url_accessible, modified_url))
|
||||||
|
for future in concurrent.futures.as_completed(futures):
|
||||||
|
result = future.result()
|
||||||
|
if result:
|
||||||
|
valid_urls.append(result)
|
||||||
|
for url in valid_urls:
|
||||||
|
print(url)
|
||||||
|
# 遍历网址列表,获取JSON文件并解析
|
||||||
|
for url in valid_urls:
|
||||||
|
try:
|
||||||
|
# 发送GET请求获取JSON文件,设置超时时间为0.5秒
|
||||||
|
json_url = f"{url}"
|
||||||
|
response = requests.get(json_url, timeout=1)################################
|
||||||
|
json_data = response.content.decode('utf-8')
|
||||||
|
try:
|
||||||
|
# 按行分割数据
|
||||||
|
lines = json_data.split('\n')
|
||||||
|
for line in lines:
|
||||||
|
if 'hls' in line and ('udp' not in line or 'rtp' not in line): #行中需包含m3u,但排除udp和trp
|
||||||
|
line = line.strip()
|
||||||
|
if line:
|
||||||
|
name, channel_url = line.split(',')
|
||||||
|
urls = channel_url.split('/', 3)
|
||||||
|
url_data = json_url.split('/', 3)
|
||||||
|
if len(urls) >= 3:
|
||||||
|
urld = (f"http://{urls[1]/{urls[2]/{urls[3]}")
|
||||||
|
else:
|
||||||
|
urld = (f"{urls[0]}//{url_data[2]}")
|
||||||
|
print(f"{name},{urld}")
|
||||||
|
if name and urld:
|
||||||
name = name.replace("高清电影", "影迷电影")
|
name = name.replace("高清电影", "影迷电影")
|
||||||
name = name.replace("中央", "CCTV")
|
name = name.replace("中央", "CCTV")
|
||||||
name = name.replace("高清", "")
|
name = name.replace("高清", "")
|
||||||
@@ -208,24 +241,21 @@ for url in urls:
|
|||||||
name = name.replace("影视剧", "影视")
|
name = name.replace("影视剧", "影视")
|
||||||
name = name.replace("电视剧", "影视")
|
name = name.replace("电视剧", "影视")
|
||||||
name = name.replace("奥运匹克", "")
|
name = name.replace("奥运匹克", "")
|
||||||
results.append(f"{name},{modified_url}")
|
results.append(f"{name},{urld}")
|
||||||
break # 找到可访问的URL后跳出循环
|
except:
|
||||||
|
continue
|
||||||
except requests.exceptions.RequestException as e:
|
except:
|
||||||
print(f"请求URL {url} 时发生错误: {e}")
|
continue
|
||||||
|
|
||||||
# 以下是处理results列表并写入文件的代码
|
|
||||||
channels = []
|
channels = []
|
||||||
for result in results:
|
for result in results:
|
||||||
|
line = result.strip()
|
||||||
if result:
|
if result:
|
||||||
channel_name, channel_url = result.split(',')
|
channel_name, channel_url = result.split(',')
|
||||||
channels.append((channel_name, channel_url))
|
channels.append((channel_name, channel_url))
|
||||||
|
|
||||||
with open("iptv.txt", 'w', encoding='utf-8') as file:
|
with open("iptv.txt", 'w', encoding='utf-8') as file:
|
||||||
for channel_name, channel_url in channels:
|
for result in results:
|
||||||
file.write(f"{channel_name},{channel_url}\n")
|
file.write(result + "\n")
|
||||||
print(f"{channel_name},{channel_url}")
|
print(result)
|
||||||
|
|
||||||
print("频道列表文件iptv.txt获取完成!")
|
print("频道列表文件iptv.txt获取完成!")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user