This commit is contained in:
guorong.zheng 2024-09-04 17:32:25 +08:00
parent 502aadeaae
commit 7f04e1a21d
6 changed files with 2184 additions and 41297 deletions

19
main.py

@ -111,14 +111,19 @@ class UpdateSource:
)
def get_urls_len(self):
return len(
[
url
for channel_obj in self.channel_data.values()
for url_list in channel_obj.values()
for url in url_list
]
def process_cache_url(url):
if "$cache:" in url:
cache_part = url.split("$cache:", 1)[1]
return cache_part.split("?")[0]
return url
processed_urls = set(
process_cache_url(url_info[0])
for channel_obj in self.channel_data.values()
for url_info_list in channel_obj.values()
for url_info in url_info_list
)
return len(processed_urls)
async def main(self):
try:

File diff suppressed because it is too large Load Diff

@ -7,7 +7,7 @@ from utils.channel import (
get_multicast_fofa_search_urls,
)
from utils.tools import get_pbar_remaining, get_soup
from utils.config import config, resource_path
from utils.config import config
from updates.proxy import get_proxy, get_proxy_next
from updates.fofa import get_channels_by_fofa
from time import time
@ -42,13 +42,7 @@ async def get_channels_by_multicast(names, callback=None):
page_num = config.getint("Settings", "multicast_page_num")
if open_proxy:
proxy = await get_proxy(pageUrl, best=True, with_test=True)
get_multicast_region_result_by_rtp_txt(callback=callback)
with open(
resource_path("updates/multicast/multicast_region_result.json"),
"r",
encoding="utf-8",
) as f:
multicast_region_result = json.load(f)
multicast_region_result = get_multicast_region_result_by_rtp_txt(callback=callback)
name_region_type_result = get_channel_multicast_name_region_type_result(
multicast_region_result, names
)

@ -102,45 +102,48 @@ def get_multicast_region_result_by_rtp_txt(callback=None):
"""
Get multicast region result by rtp txt
"""
rtp_file_list = []
rtp_path = resource_path("updates/multicast/rtp")
config_region_list = set(config.get("Settings", "multicast_region_list").split(","))
for filename in os.listdir(rtp_path):
if filename.endswith(".txt") and "_" in filename:
name = filename.rsplit(".", 1)[0]
if (
name in config_region_list
or "all" in config_region_list
or "ALL" in config_region_list
or "全部" in config_region_list
):
rtp_file_list.append(filename)
rtp_file_list_len = len(rtp_file_list)
pbar = tqdm(total=rtp_file_list_len, desc="Loading local multicast rtp files")
if callback:
callback(
f"正在加载本地组播数据, 共{rtp_file_list_len}个文件",
0,
rtp_file_list = [
filename.rsplit(".", 1)[0]
for filename in os.listdir(rtp_path)
if filename.endswith(".txt")
and "_" in filename
and (
filename.rsplit(".", 1)[0].split("_", 1)[0] in config_region_list
or config_region_list & {"all", "ALL", "全部"}
)
]
total_files = len(rtp_file_list)
if callback:
callback(f"正在加载本地组播数据, 共{total_files}个文件", 0)
pbar = tqdm(total=total_files, desc="Loading local multicast rtp files")
multicast_result = defaultdict(lambda: defaultdict(lambda: defaultdict(list)))
pattern = re.compile(r"^(.*?),(?!#genre#)(.*?)$")
start_time = time()
for filename in rtp_file_list:
region, type = filename.split("_")
with open(os.path.join(rtp_path, filename), "r", encoding="utf-8") as f:
region, type = filename.split("_", 1)
with open(
os.path.join(rtp_path, f"{filename}.txt"), "r", encoding="utf-8"
) as f:
for line in f:
matcher = pattern.match(line)
if matcher and len(matcher.groups()) == 2:
if matcher:
channel_name = format_channel_name(matcher.group(1).strip())
url = matcher.group(2).strip()
if url not in multicast_result[channel_name][region][type]:
multicast_result[channel_name][region][type].append(url)
pbar.update()
if callback:
callback(
f"正在加载{region}_{type}的组播数据, 剩余{rtp_file_list_len - pbar.n}个文件, 预计剩余时间: {get_pbar_remaining(n=pbar.n, total=pbar.total, start_time=start_time)}",
int((pbar.n / rtp_file_list_len) * 100),
)
pbar.update()
if callback:
remaining_files = total_files - pbar.n
estimated_time = get_pbar_remaining(pbar.n, total_files, start_time)
callback(
f"正在加载{region}_{type}的组播数据, 剩余{remaining_files}个文件, 预计剩余时间: {estimated_time}",
int((pbar.n / total_files) * 100),
)
with open(
resource_path("updates/multicast/multicast_region_result.json"),
@ -148,7 +151,9 @@ def get_multicast_region_result_by_rtp_txt(callback=None):
encoding="utf-8",
) as f:
json.dump(multicast_result, f, ensure_ascii=False, indent=4)
pbar.close()
return multicast_result
if __name__ == "__main__":

@ -106,7 +106,7 @@ def get_channel_name_matches(query=None, choices=None, threshold=80):
query = format_channel_name(query)
matches = process.extract(query, choices, limit=len(choices))
threshold = 100 if "cctv" in query else threshold
filtered_matches = [match for match in matches if match[1] >= threshold]
filtered_matches = [match[0] for match in matches if match[1] >= threshold]
return filtered_matches
@ -133,7 +133,7 @@ def get_channel_results_by_name(name, data):
get_channel_name_matches(name, data_keys)
+ get_channel_name_matches(name_s2t, data_keys)
)
result = [item for name_match in name_matches_set for item in data[name_match[0]]]
result = [item for name_match in name_matches_set for item in data[name_match]]
return result
@ -186,10 +186,9 @@ def get_channel_multicast_name_region_type_result(result, names):
for name in names:
matches = get_channel_name_matches(name, result.keys())
for match in matches:
match_name = match[0]
data = result.get(match_name)
if data and match_name not in name_region_type_result:
name_region_type_result[match_name] = data
data = result.get(match)
if data and match not in name_region_type_result:
name_region_type_result[match] = data
return name_region_type_result

@ -125,7 +125,7 @@ async def get_speed_by_info(url_info, ffmpeg, semaphore, callback=None):
url_split = None
cache_key = None
if "$" in url:
url_split = url.split("$")
url_split = url.split("$", 1)
url = url_split[0]
url = quote(url, safe=":/?&=$[]")
url_info[0] = url