feat:format_channel_url_info

This commit is contained in:
guorong.zheng 2024-10-10 10:51:43 +08:00
parent 8cf901b475
commit d26179082e
3 changed files with 21 additions and 5 deletions

@ -8,6 +8,7 @@ from utils.channel import (
setup_logging,
cleanup_logging,
get_channel_data_cache_with_compare,
format_channel_url_info,
)
from utils.tools import (
update_file,
@ -169,6 +170,8 @@ class UpdateSource:
self.channel_data,
callback=sort_callback,
)
else:
format_channel_url_info(self.channel_data)
self.total = self.get_urls_len()
self.pbar = tqdm(total=self.total, desc="Writing")
self.start_time = time()

@ -8,7 +8,7 @@ from utils.tools import (
from utils.speed import (
sort_urls_by_speed_and_resolution,
is_ffmpeg_installed,
format_url,
add_info_url,
speed_cache,
)
import os
@ -693,7 +693,7 @@ async def process_sort_channel_list(data, callback=None):
response_time, resolution = cache
if response_time and response_time != float("inf"):
if resolution:
url = format_url(url, resolution)
url = add_info_url(url, resolution)
append_data_to_info_data(
sort_data,
cate,
@ -787,3 +787,16 @@ def get_channel_data_cache_with_compare(data, new_data):
resolution = new_urls[base_url]
updated_data.append((url, date, resolution))
data[cate][name] = updated_data
def format_channel_url_info(data):
"""
Format channel url info, remove cache, add resolution to url
"""
for obj in data.values():
for url_info in obj.values():
for i, (url, date, resolution) in enumerate(url_info):
url = url.split("$", 1)[0]
if resolution:
url = add_info_url(url, resolution)
url_info[i] = (url, date, resolution)

@ -106,7 +106,7 @@ async def check_stream_speed(url_info):
if frame is None or frame == float("inf"):
return float("inf")
if resolution:
url_info[0] = format_url(url, resolution)
url_info[0] = add_info_url(url, resolution)
url_info[2] = resolution
return (tuple(url_info), frame)
except Exception as e:
@ -114,7 +114,7 @@ async def check_stream_speed(url_info):
return float("inf")
def format_url(url, info):
def add_info_url(url, info):
"""
Format the url
"""
@ -142,7 +142,7 @@ async def get_speed_by_info(
cache_key = cache_info.replace("cache:", "")
url_is_ipv6 = is_ipv6(url)
if url_is_ipv6:
url = format_url(url, "IPv6")
url = add_info_url(url, "IPv6")
url_info[0] = url
if cache_key in speed_cache:
speed = speed_cache[cache_key][0]