Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore #300

Merged
merged 3 commits into from
Sep 5, 2024
Merged

chore #300

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions updates/fofa/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def get_fofa_urls_from_region_list():
"""
Get the FOFA url from region
"""
# region_list = config.get("Settings", "hotel_region_list").split(",")
region_list = config.get("Settings", "hotel_region_list").split(",")
urls = []
region_url = getattr(fofa_map, "region_url")
# if "all" in region_list or "ALL" in region_list or "全部" in region_list:
urls = [url for url_list in region_url.values() for url in url_list if url]
# else:
# for region in region_list:
# if region in region_url:
# urls.append(region_url[region])
if "all" in region_list or "ALL" in region_list or "全部" in region_list:
urls = [url for url_list in region_url.values() for url in url_list if url]
else:
for region in region_list:
if region in region_url:
urls.append(region_url[region])
return urls


Expand All @@ -53,12 +53,13 @@ async def get_channels_by_fofa(urls=None, multicast=False, callback=None):
proxy = None
open_proxy = config.getboolean("Settings", "open_proxy")
open_driver = config.getboolean("Settings", "open_driver")
open_sort = config.getboolean("Settings", "open_sort")
if open_proxy:
test_url = fofa_urls[0][0] if multicast else fofa_urls[0]
proxy = await get_proxy(test_url, best=True, with_test=True)

def process_fofa_channels(fofa_info):
nonlocal proxy, fofa_urls_len, open_driver
nonlocal proxy, fofa_urls_len, open_driver, open_sort
fofa_url = fofa_info[0] if multicast else fofa_info
results = defaultdict(lambda: defaultdict(list))
try:
Expand Down Expand Up @@ -88,7 +89,8 @@ def process_fofa_channels(fofa_info):
else:
with ThreadPoolExecutor(max_workers=100) as executor:
futures = [
executor.submit(process_fofa_json_url, url) for url in urls
executor.submit(process_fofa_json_url, url, open_sort)
for url in urls
]
for future in futures:
results = merge_objects(results, future.result())
Expand Down Expand Up @@ -120,7 +122,7 @@ def process_fofa_channels(fofa_info):
return fofa_results


def process_fofa_json_url(url):
def process_fofa_json_url(url, open_sort):
"""
Process the FOFA json url
"""
Expand All @@ -141,7 +143,11 @@ 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 = f"{url}{item_url}$cache:{url}"
total_url = (
f"{url}{item_url}$cache:{url}"
if open_sort
else f"{url}{item_url}"
)
if item_name not in channels:
channels[item_name] = [(total_url, None, None)]
else:
Expand Down
3 changes: 2 additions & 1 deletion updates/hotel/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ def process_region_by_hotel(region):
for result in search_region_result.values()
for url, _, _ in result
]
open_sort = config.getboolean("Settings", "open_sort")
channels = await get_channels_by_subscribe_urls(
urls, hotel=True, retry=False, error_print=False, with_cache=True
urls, hotel=True, retry=False, error_print=False, with_cache=open_sort
)
if not open_driver:
close_session()
Expand Down
7 changes: 6 additions & 1 deletion utils/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,15 @@ def get_channel_multicast_result(result, search_result):
Get the channel multicast info result by result and search result
"""
info_result = {}
open_sort = config.getboolean("Settings", "open_sort")
for name, result_obj in result.items():
info_list = [
(
f"http://{url}/rtp/{ip}$cache:{result_region}_{result_type}",
(
f"http://{url}/rtp/{ip}$cache:{result_region}_{result_type}"
if open_sort
else f"http://{url}/rtp/{ip}"
),
date,
resolution,
)
Expand Down
4 changes: 2 additions & 2 deletions utils/speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ async def get_speed_by_info(url_info, ffmpeg, semaphore, callback=None):
url, cache_info = url.split("$", 1)
if "cache:" in cache_info:
cache_key = cache_info.replace("cache:", "")
if cache_key in speed_cache:
return tuple(url_info), speed_cache[cache_key]
url = quote(url, safe=":/?&=$[]")
url_info[0] = url
if cache_key in speed_cache:
return (tuple(url_info), speed_cache[cache_key])
try:
if ".m3u8" not in url and ffmpeg:
speed = await check_stream_speed(url_info)
Expand Down
Loading