This commit is contained in:
guorong.zheng 2024-08-27 10:40:33 +08:00
parent 1876923050
commit 75b905e0ea
3 changed files with 22 additions and 22 deletions

@ -191,9 +191,9 @@ class UpdateSource:
self.pbar = tqdm(total=self.total, desc="Writing")
self.start_time = time()
write_channel_to_file(
channel_items_obj_items,
self.channel_data,
lambda: self.pbar_update(name="写入结果"),
items=channel_items_obj_items,
data=self.channel_data,
callback=lambda: self.pbar_update(name="写入结果"),
)
self.pbar.close()
user_final_file = config.get("Settings", "final_file")

@ -591,7 +591,9 @@ def append_all_method_data_keep_all(
return data
async def sort_channel_list(semaphore, cate, name, info_list, is_ffmpeg, callback):
async def sort_channel_list(
semaphore=None, cate=None, name=None, info_list=None, ffmpeg=False, callback=None
):
"""
Sort the channel list
"""
@ -600,7 +602,7 @@ async def sort_channel_list(semaphore, cate, name, info_list, is_ffmpeg, callbac
try:
if info_list:
sorted_data = await sort_urls_by_speed_and_resolution(
info_list, is_ffmpeg
data=info_list, ffmpeg=ffmpeg
)
if sorted_data:
for (
@ -618,7 +620,8 @@ async def sort_channel_list(semaphore, cate, name, info_list, is_ffmpeg, callbac
except Exception as e:
logging.error(f"Error: {e}")
finally:
callback()
if callback:
callback()
return {"cate": cate, "name": name, "data": data}
@ -635,12 +638,12 @@ async def process_sort_channel_list(data=None, callback=None):
tasks = [
asyncio.create_task(
sort_channel_list(
semaphore,
cate,
name,
info_list,
is_ffmpeg,
lambda: callback() if callback else None,
semaphore=semaphore,
cate=cate,
name=name,
info_list=info_list,
ffmpeg=is_ffmpeg,
callback=callback,
)
)
for cate, channel_obj in data.items()
@ -657,7 +660,7 @@ async def process_sort_channel_list(data=None, callback=None):
return data
def write_channel_to_file(items, data, callback):
def write_channel_to_file(items=None, data=None, callback=None):
"""
Write channel to file
"""
@ -669,7 +672,8 @@ def write_channel_to_file(items, data, callback):
print("write:", cate, name, "num:", len(channel_urls))
update_channel_urls_txt(cate, name, channel_urls)
finally:
callback()
if callback:
callback()
for handler in logging.root.handlers[:]:
handler.close()
logging.root.removeHandler(handler)

@ -129,23 +129,19 @@ async def get_info_with_speed(url_info):
return float("inf")
async def sort_urls_by_speed_and_resolution(infoList, ffmpeg=False):
async def sort_urls_by_speed_and_resolution(data=None, ffmpeg=False):
"""
Sort by speed and resolution
"""
if ffmpeg:
response = await asyncio.gather(
*(get_info_with_speed(url_info) for url_info in infoList)
*(get_info_with_speed(url_info) for url_info in data)
)
valid_response = [res for res in response if res != float("inf")]
else:
response_times = await asyncio.gather(
*(get_speed(url) for url, _, _ in infoList)
)
response_times = await asyncio.gather(*(get_speed(url) for url, _, _ in data))
valid_response = [
(info, rt)
for info, rt in zip(infoList, response_times)
if rt != float("inf")
(info, rt) for info, rt in zip(data, response_times) if rt != float("inf")
]
def extract_resolution(resolution_str):