chore:multicast sup
This commit is contained in:
parent
bc4c8f5d2f
commit
0c1a8b995b
@ -9,7 +9,7 @@ online_search_page_num = 3
|
||||
urls_limit = 15
|
||||
open_keep_all = False
|
||||
open_sort = True
|
||||
open_ffmpeg = False
|
||||
open_ffmpeg = True
|
||||
response_time_weight = 0.5
|
||||
resolution_weight = 0.5
|
||||
recent_days = 30
|
||||
@ -25,8 +25,8 @@ multicast_page_num = 3
|
||||
open_proxy = False
|
||||
open_driver = True
|
||||
open_hotel = True
|
||||
open_hotel_tonkiang = False
|
||||
open_hotel_tonkiang = True
|
||||
open_hotel_fofa = True
|
||||
hotel_region_list = 广东
|
||||
hotel_page_num = 5
|
||||
hotel_region_list = 全部
|
||||
hotel_page_num = 3
|
||||
|
||||
|
16
main.py
16
main.py
@ -60,10 +60,10 @@ class UpdateSource:
|
||||
self.run_ui = False
|
||||
self.tasks = []
|
||||
self.channel_items = {}
|
||||
self.subscribe_result = {}
|
||||
self.multicast_result = {}
|
||||
self.hotel_tonkiang_result = {}
|
||||
self.hotel_fofa_result = {}
|
||||
self.hotel_tonkiang_result = {}
|
||||
self.multicast_result = {}
|
||||
self.subscribe_result = {}
|
||||
self.online_search_result = {}
|
||||
self.channel_data = {}
|
||||
self.pbar = None
|
||||
@ -73,10 +73,10 @@ class UpdateSource:
|
||||
|
||||
async def visit_page(self, channel_names=None):
|
||||
tasks_config = [
|
||||
("open_subscribe", get_channels_by_subscribe_urls, "subscribe_result"),
|
||||
("open_hotel_fofa", get_channels_by_fofa, "hotel_fofa_result"),
|
||||
("open_multicast", get_channels_by_multicast, "multicast_result"),
|
||||
("open_hotel_tonkiang", get_channels_by_hotel, "hotel_tonkiang_result"),
|
||||
("open_hotel_fofa", get_channels_by_fofa, "hotel_fofa_result"),
|
||||
("open_subscribe", get_channels_by_subscribe_urls, "subscribe_result"),
|
||||
(
|
||||
"open_online_search",
|
||||
get_channels_by_online_search,
|
||||
@ -133,10 +133,10 @@ class UpdateSource:
|
||||
self.channel_data = append_total_data(
|
||||
channel_items_obj_items,
|
||||
self.channel_data,
|
||||
self.subscribe_result,
|
||||
self.hotel_fofa_result,
|
||||
self.multicast_result,
|
||||
self.hotel_tonkiang_result,
|
||||
self.hotel_fofa_result,
|
||||
self.subscribe_result,
|
||||
self.online_search_result,
|
||||
)
|
||||
if config.getboolean("Settings", "open_sort"):
|
||||
@ -161,7 +161,7 @@ class UpdateSource:
|
||||
print(
|
||||
f"No result found for {', '.join(no_result_names)}, try a supplementary online search..."
|
||||
)
|
||||
sup_results = await get_channels_by_online_search(
|
||||
sup_results = await get_channels_by_multicast(
|
||||
no_result_names, self.update_progress
|
||||
)
|
||||
sup_channel_items = defaultdict(lambda: defaultdict(list))
|
||||
|
@ -497,10 +497,10 @@ def append_total_data(*args, **kwargs):
|
||||
def append_all_method_data(
|
||||
items,
|
||||
data,
|
||||
subscribe_result=None,
|
||||
hotel_fofa_result=None,
|
||||
multicast_result=None,
|
||||
hotel_tonkiang_result=None,
|
||||
hotel_fofa_result=None,
|
||||
subscribe_result=None,
|
||||
online_search_result=None,
|
||||
):
|
||||
"""
|
||||
@ -509,10 +509,10 @@ def append_all_method_data(
|
||||
for cate, channel_obj in items:
|
||||
for name, old_urls in channel_obj.items():
|
||||
for method, result in [
|
||||
("subscribe", subscribe_result),
|
||||
("hotel_fofa", hotel_fofa_result),
|
||||
("multicast", multicast_result),
|
||||
("hotel_tonkiang", hotel_tonkiang_result),
|
||||
("hotel_fofa", hotel_fofa_result),
|
||||
("subscribe", subscribe_result),
|
||||
("online_search", online_search_result),
|
||||
]:
|
||||
if config.getboolean("Settings", f"open_{method}"):
|
||||
@ -554,10 +554,10 @@ def append_all_method_data(
|
||||
def append_all_method_data_keep_all(
|
||||
items,
|
||||
data,
|
||||
subscribe_result=None,
|
||||
hotel_fofa_result=None,
|
||||
multicast_result=None,
|
||||
hotel_tonkiang_result=None,
|
||||
hotel_fofa_result=None,
|
||||
subscribe_result=None,
|
||||
online_search_result=None,
|
||||
):
|
||||
"""
|
||||
@ -565,10 +565,10 @@ def append_all_method_data_keep_all(
|
||||
"""
|
||||
for cate, channel_obj in items:
|
||||
for method, result in [
|
||||
("subscribe", subscribe_result),
|
||||
("hotel_fofa", hotel_fofa_result),
|
||||
("multicast", multicast_result),
|
||||
("hotel_tonkiang", hotel_tonkiang_result),
|
||||
("hotel_fofa", hotel_fofa_result),
|
||||
("subscribe", subscribe_result),
|
||||
("online_search", online_search_result),
|
||||
]:
|
||||
if result and config.getboolean("Settings", f"open_{method}"):
|
||||
@ -592,7 +592,7 @@ def append_all_method_data_keep_all(
|
||||
|
||||
|
||||
async def sort_channel_list(
|
||||
semaphore, cate, name, info_list, ffmpeg=False, callback=None
|
||||
cate, name, info_list, semaphore, ffmpeg=False, callback=None
|
||||
):
|
||||
"""
|
||||
Sort the channel list
|
||||
@ -634,14 +634,14 @@ async def process_sort_channel_list(data, callback=None):
|
||||
if open_ffmpeg and not ffmpeg_installed:
|
||||
print("FFmpeg is not installed, using requests for sorting.")
|
||||
is_ffmpeg = open_ffmpeg and ffmpeg_installed
|
||||
semaphore = asyncio.Semaphore(1 if is_ffmpeg else 100)
|
||||
semaphore = asyncio.Semaphore(3)
|
||||
tasks = [
|
||||
asyncio.create_task(
|
||||
sort_channel_list(
|
||||
semaphore,
|
||||
cate,
|
||||
name,
|
||||
info_list,
|
||||
semaphore,
|
||||
ffmpeg=is_ffmpeg,
|
||||
callback=callback,
|
||||
)
|
||||
|
@ -43,7 +43,7 @@ def is_ffmpeg_installed():
|
||||
return False
|
||||
|
||||
|
||||
async def ffmpeg_url(url, timeout=timeout):
|
||||
async def ffmpeg_url(url):
|
||||
"""
|
||||
Get url info by ffmpeg
|
||||
"""
|
||||
@ -97,7 +97,7 @@ async def check_stream_speed(url_info):
|
||||
"""
|
||||
try:
|
||||
url = url_info[0]
|
||||
video_info = await ffmpeg_url(url, timeout=timeout)
|
||||
video_info = await ffmpeg_url(url)
|
||||
if video_info is None:
|
||||
return float("inf")
|
||||
frame, resolution = get_video_info(video_info)
|
||||
@ -112,37 +112,39 @@ async def check_stream_speed(url_info):
|
||||
return float("inf")
|
||||
|
||||
|
||||
async def get_info_with_speed(url_info):
|
||||
async def get_speed_by_info(url_info, ffmpeg, semaphore):
|
||||
"""
|
||||
Get the info with speed
|
||||
"""
|
||||
url, _, _ = url_info
|
||||
url_info = list(url_info)
|
||||
if "$" in url:
|
||||
url = url.split("$")[0]
|
||||
url = quote(url, safe=":/?&=$[]")
|
||||
url_info[0] = url
|
||||
try:
|
||||
speed = await check_stream_speed(url_info)
|
||||
return speed
|
||||
except Exception:
|
||||
return float("inf")
|
||||
async with semaphore:
|
||||
url, _, _ = url_info
|
||||
url_info = list(url_info)
|
||||
if "$" in url:
|
||||
url = url.split("$")[0]
|
||||
url = quote(url, safe=":/?&=$[]")
|
||||
url_info[0] = url
|
||||
try:
|
||||
if ".m3u8" not in url and ffmpeg:
|
||||
speed = await check_stream_speed(url_info)
|
||||
return speed
|
||||
else:
|
||||
speed = await get_speed(url)
|
||||
return (
|
||||
(tuple(url_info), speed) if speed != float("inf") else float("inf")
|
||||
)
|
||||
except Exception:
|
||||
return float("inf")
|
||||
|
||||
|
||||
async def sort_urls_by_speed_and_resolution(data, ffmpeg=False):
|
||||
"""
|
||||
Sort by speed and resolution
|
||||
"""
|
||||
if ffmpeg:
|
||||
response = await asyncio.gather(
|
||||
*(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 data))
|
||||
valid_response = [
|
||||
(info, rt) for info, rt in zip(data, response_times) if rt != float("inf")
|
||||
]
|
||||
semaphore = asyncio.Semaphore(10)
|
||||
response = await asyncio.gather(
|
||||
*(get_speed_by_info(url_info, ffmpeg, semaphore) for url_info in data)
|
||||
)
|
||||
valid_response = [res for res in response if res != float("inf")]
|
||||
|
||||
def extract_resolution(resolution_str):
|
||||
numbers = re.findall(r"\d+x\d+", resolution_str)
|
||||
|
Loading…
x
Reference in New Issue
Block a user