feat:url cache
This commit is contained in:
parent
c6c851d082
commit
c0d1f3c729
@ -5,7 +5,12 @@ from utils.channel import (
|
||||
get_results_from_soup,
|
||||
get_results_from_soup_requests,
|
||||
)
|
||||
from utils.tools import check_url_by_patterns, get_pbar_remaining, get_soup
|
||||
from utils.tools import (
|
||||
check_url_by_patterns,
|
||||
get_pbar_remaining,
|
||||
get_soup,
|
||||
format_url_with_cache,
|
||||
)
|
||||
from utils.config import config
|
||||
from updates.proxy import get_proxy, get_proxy_next
|
||||
from time import time
|
||||
@ -161,6 +166,7 @@ async def get_channels_by_online_search(names, callback=None):
|
||||
for result in results:
|
||||
url, date, resolution = result
|
||||
if url and check_url_by_patterns(url):
|
||||
url = format_url_with_cache(url)
|
||||
info_list.append((url, date, resolution))
|
||||
break
|
||||
else:
|
||||
|
@ -5,7 +5,7 @@ from requests import Session, exceptions
|
||||
from utils.retry import retry_func
|
||||
import re
|
||||
from utils.channel import format_channel_name
|
||||
from utils.tools import merge_objects, get_pbar_remaining
|
||||
from utils.tools import merge_objects, get_pbar_remaining, format_url_with_cache
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from collections import defaultdict
|
||||
|
||||
@ -83,6 +83,8 @@ async def get_channels_by_subscribe_urls(
|
||||
url = matcher.group(2).strip()
|
||||
if with_cache:
|
||||
url = f"{url}$cache:{subscribe_url}"
|
||||
else:
|
||||
url = format_url_with_cache(url)
|
||||
value = url if multicast else (url, None, resolution)
|
||||
name = format_channel_name(key)
|
||||
if name in channels:
|
||||
|
@ -336,3 +336,37 @@ def process_nested_dict(data, seen, flag=None):
|
||||
process_nested_dict(value, seen, flag)
|
||||
elif isinstance(value, list):
|
||||
data[key] = remove_duplicates_from_tuple_list(value, seen, flag)
|
||||
|
||||
|
||||
ip_pattern = re.compile(
|
||||
r"""
|
||||
(
|
||||
(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) # IPv4
|
||||
|([a-zA-Z0-9.-]+\.[a-zA-Z]{2,}) # Domain
|
||||
|(\[([0-9a-fA-F:]+)\]) # IPv6
|
||||
)
|
||||
(?::(\d+))? # Port
|
||||
""",
|
||||
re.VERBOSE,
|
||||
)
|
||||
|
||||
|
||||
def get_ip(url):
|
||||
"""
|
||||
Get the IP address with flags
|
||||
"""
|
||||
matcher = ip_pattern.search(url)
|
||||
if matcher:
|
||||
return matcher.group(1)
|
||||
return None
|
||||
|
||||
|
||||
def format_url_with_cache(url):
|
||||
"""
|
||||
Format the URL with cache
|
||||
"""
|
||||
ip = get_ip(url)
|
||||
if ip:
|
||||
return f"{url}$cache:{ip}"
|
||||
else:
|
||||
return url
|
||||
|
Loading…
x
Reference in New Issue
Block a user