From 9d569c99910dbc24a0494ef3c210bf37abd28c70 Mon Sep 17 00:00:00 2001 From: "guorong.zheng" <360996299@qq.com> Date: Thu, 19 Dec 2024 10:35:32 +0800 Subject: [PATCH] fix:sort infinite waiting(#705) --- utils/speed.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/utils/speed.py b/utils/speed.py index 56d02af786..aa3ca7e45a 100644 --- a/utils/speed.py +++ b/utils/speed.py @@ -48,7 +48,7 @@ async def get_speed_m3u8(url: str, timeout: int = config.sort_timeout) -> dict[s url = quote(url, safe=':/?$&=@[]').partition('$')[0] async with ClientSession(connector=TCPConnector(ssl=False), trust_env=True) as session: async with session.head(url, timeout=2) as response: - if response.headers.get('Content-Length'): + if response.headers.get('Content-Type') == 'application/vnd.apple.mpegurl': m3u8_obj = m3u8.load(url, timeout=2) speed_list = [] start_time = time() @@ -61,6 +61,9 @@ async def get_speed_m3u8(url: str, timeout: int = config.sort_timeout) -> dict[s if info['delay'] is None and download_info['delay'] is not None: info['delay'] = download_info['delay'] info['speed'] = sum(speed_list) / len(speed_list) if speed_list else 0 + elif response.headers.get('Content-Length'): + download_info = await get_speed_with_download(url, timeout) + info.update(download_info) else: return info except: @@ -193,8 +196,6 @@ async def get_speed(url, ipv6_proxy=None, callback=None): if ipv6_proxy and url_is_ipv6: data['speed'] = float("inf") data['delay'] = float("-inf") - elif '/rtp/' in url: - data.update(await get_speed_with_download(url)) else: data.update(await get_speed_m3u8(url)) if cache_key and cache_key not in cache: