feat:with_cache
This commit is contained in:
parent
09288d65e0
commit
56e94e1491
@ -122,7 +122,7 @@ def process_fofa_json_url(url):
|
||||
item_name = format_channel_name(item.get("name"))
|
||||
item_url = item.get("url").strip()
|
||||
if item_name and item_url:
|
||||
total_url = url + item_url
|
||||
total_url = f"{url}{item_url}$cache:{url}"
|
||||
if item_name not in channels:
|
||||
channels[item_name] = [(total_url, None, None)]
|
||||
else:
|
||||
|
@ -244,7 +244,7 @@ async def get_channels_by_hotel(callback):
|
||||
for url, _, _ in result
|
||||
]
|
||||
channels = await get_channels_by_subscribe_urls(
|
||||
urls, retry=False, error_print=False
|
||||
urls, retry=False, error_print=False, with_cache=True
|
||||
)
|
||||
if not open_driver:
|
||||
close_session()
|
||||
|
@ -13,7 +13,7 @@ timeout = 30
|
||||
|
||||
|
||||
async def get_channels_by_subscribe_urls(
|
||||
urls, multicast=False, retry=True, error_print=True, callback=None
|
||||
urls, multicast=False, retry=True, error_print=True, with_cache=False, callback=None
|
||||
):
|
||||
"""
|
||||
Get the channels by subscribe urls
|
||||
@ -68,6 +68,8 @@ async def get_channels_by_subscribe_urls(
|
||||
else None
|
||||
)
|
||||
url = matcher.group(2).strip()
|
||||
if with_cache:
|
||||
url = f"{url}$cache:{subscribe_url}"
|
||||
value = url if multicast else (url, None, resolution)
|
||||
name = format_channel_name(key)
|
||||
if name in channels:
|
||||
|
@ -223,7 +223,11 @@ def get_channel_multicast_result(result, search_result):
|
||||
info_result = {}
|
||||
for name, result_obj in result.items():
|
||||
info_list = [
|
||||
(f"http://{url}/rtp/{ip}${result_region}_{result_type}", date, resolution)
|
||||
(
|
||||
f"http://{url}/rtp/{ip}$cache:{result_region}_{result_type}",
|
||||
date,
|
||||
resolution,
|
||||
)
|
||||
for result_region, result_types in result_obj.items()
|
||||
if result_region in search_result
|
||||
for result_type, result_type_urls in result_types.items()
|
||||
|
@ -123,15 +123,16 @@ async def get_speed_by_info(url_info, ffmpeg, semaphore, callback=None):
|
||||
url, _, _ = url_info
|
||||
url_info = list(url_info)
|
||||
url_split = None
|
||||
cache_key = None
|
||||
if "$" in url:
|
||||
url_split = url.split("$")
|
||||
url = url_split[0]
|
||||
url = quote(url, safe=":/?&=$[]")
|
||||
url_info[0] = url
|
||||
if url_split and url_split[1] and "_" in url_split[1]:
|
||||
region_type = url_split[1]
|
||||
if speed_cache.get(region_type):
|
||||
return (tuple(url_info), speed_cache[region_type])
|
||||
if url_split and url_split[1] and "cache:" in url_split[1]:
|
||||
cache_key = url_split[1]
|
||||
if speed_cache.get(cache_key):
|
||||
return (tuple(url_info), speed_cache[cache_key])
|
||||
try:
|
||||
if ".m3u8" not in url and ffmpeg:
|
||||
speed = await check_stream_speed(url_info)
|
||||
@ -143,8 +144,8 @@ async def get_speed_by_info(url_info, ffmpeg, semaphore, callback=None):
|
||||
if url_speed != float("inf")
|
||||
else float("inf")
|
||||
)
|
||||
if region_type and speed_cache.get(region_type) is None:
|
||||
speed_cache[region_type] = url_speed
|
||||
if cache_key and speed_cache.get(cache_key) is None:
|
||||
speed_cache[cache_key] = url_speed
|
||||
return speed
|
||||
except Exception:
|
||||
return float("inf")
|
||||
|
Loading…
x
Reference in New Issue
Block a user