diff --git a/utils/speed.py b/utils/speed.py index 1760357..143b69d 100644 --- a/utils/speed.py +++ b/utils/speed.py @@ -1,12 +1,14 @@ -from aiohttp import ClientSession, TCPConnector -from time import time import asyncio import re -from utils.config import config -import utils.constants as constants -from utils.tools import is_ipv6, remove_cache_info, get_resolution_value, get_logger import subprocess +from time import time + import yt_dlp +from aiohttp import ClientSession, TCPConnector + +import utils.constants as constants +from utils.config import config +from utils.tools import is_ipv6, remove_cache_info, get_resolution_value, get_logger logger = get_logger(constants.log_path) @@ -42,9 +44,9 @@ async def get_speed_yt_dlp(url, timeout=config.sort_timeout): if "width" in info and "height" in info else None ) - return (fps, resolution) + return fps, resolution except: - return (float("inf"), None) + return float("inf"), None async def get_speed_requests(url, timeout=config.sort_timeout, proxy=None): @@ -52,7 +54,7 @@ async def get_speed_requests(url, timeout=config.sort_timeout, proxy=None): Get the speed of the url by requests """ async with ClientSession( - connector=TCPConnector(verify_ssl=False), trust_env=True + connector=TCPConnector(verify_ssl=False), trust_env=True ) as session: start = time() end = None @@ -144,7 +146,7 @@ async def check_stream_speed(url_info): if frame is None or frame == float("inf"): return float("inf") url_info[2] = resolution - return (url_info, frame) + return url_info, frame except Exception as e: print(e) return float("inf") @@ -155,7 +157,7 @@ speed_cache = {} async def get_speed(url, ipv6_proxy=None, callback=None): """ - Get the speed of the url + Get the speed (response time and resolution) of the url """ try: cache_key = None @@ -168,14 +170,14 @@ async def get_speed(url, ipv6_proxy=None, callback=None): if cache_key in speed_cache: return speed_cache[cache_key][0] if ipv6_proxy and url_is_ipv6: - speed = 0 + speed = (0, None) else: speed = await get_speed_yt_dlp(url) if cache_key and cache_key not in speed_cache: speed_cache[cache_key] = speed return speed except: - return float("inf") + return float("inf"), None finally: if callback: callback() @@ -215,8 +217,8 @@ def sort_urls_by_speed_and_resolution(name, data, logger=None): else: resolution_value = get_resolution_value(resolution) if resolution else 0 return ( - config.response_time_weight * response_time - - config.resolution_weight * resolution_value + config.response_time_weight * response_time + - config.resolution_weight * resolution_value ) filter_data.sort(key=combined_key)