1
0
This commit is contained in:
guorong.zheng 2024-06-25 14:48:30 +08:00
parent 44d09a129e
commit 4e946e8f53
2 changed files with 27 additions and 16 deletions

19
main.py

@ -37,7 +37,6 @@ class UpdateSource:
self.tasks = []
self.channel_items = get_channel_items()
self.results = {}
self.semaphore = asyncio.Semaphore(10)
self.channel_data = {}
self.pbar = None
self.total = 0
@ -89,21 +88,26 @@ class UpdateSource:
def process_channel(self):
for cate, channel_obj in self.channel_items.items():
for name, old_urls in channel_obj.items():
format_name = format_channel_name(name)
formatName = format_channel_name(name)
if config.open_subscribe:
self.append_data_to_info_data(
cate, name, self.results["open_subscribe"].get(format_name, [])
cate, name, self.results["open_subscribe"].get(formatName, [])
)
if config.open_multicast:
self.append_data_to_info_data(
cate, name, self.results["open_multicast"].get(format_name, [])
cate, name, self.results["open_multicast"].get(formatName, [])
)
if config.open_online_search:
self.append_data_to_info_data(
cate,
name,
self.results["open_online_search"].get(format_name, []),
self.results["open_online_search"].get(formatName, []),
)
print(
name,
"total len:",
len(self.channel_data.get(cate, {}).get(name, [])),
)
if len(self.channel_data.get(cate, {}).get(name, [])) == 0:
self.append_data_to_info_data(
cate, name, [(url, None, None) for url in old_urls]
@ -118,6 +122,7 @@ class UpdateSource:
info_list = self.channel_data.get(cate, {}).get(name, [])
try:
channel_urls = get_total_urls_from_info_list(info_list)
print("write:", cate, name, len(channel_urls))
update_channel_urls_txt(cate, name, channel_urls)
finally:
self.pbar.update()
@ -227,4 +232,6 @@ class UpdateSource:
if __name__ == "__main__":
update_source = UpdateSource()
asyncio.run(update_source.start())
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(update_source.start())

@ -232,22 +232,23 @@ async def get_channels_by_subscribe_urls(callback):
content = response.text
lines = content.split("\n")
for line in lines:
if re.match(pattern, line) is not None:
key = re.match(pattern, line).group(1)
matcher = re.match(pattern, line)
if matcher is not None:
key = matcher.group(1)
resolution_match = re.search(r"_(\((.*?)\))", key)
resolution = (
resolution_match.group(2)
if resolution_match is not None
else None
)
key = format_channel_name(key)
url = re.match(pattern, line).group(2)
url = matcher.group(2)
value = (url, None, resolution)
if key in channels:
if value not in channels[key]:
channels[key].append(value)
name = format_channel_name(key)
if name in channels:
if value not in channels[name]:
channels[name].append(value)
else:
channels[key] = [value]
channels[name] = [value]
except Exception as e:
print(f"Error on {subscribe_url}: {e}")
finally:
@ -331,15 +332,18 @@ async def get_channels_by_online_search(names, callback):
soup = BeautifulSoup(source, "html.parser")
if soup:
results = get_results_from_soup(soup, name)
print(name, "page:", page, "results len:", len(results))
for result in results:
url, date, resolution = result
if url and check_url_by_patterns(url):
info_list.append((url, date, resolution))
else:
print(f"No results found for {name}")
except Exception as e:
# print(f"Error on page {page}: {e}")
print(f"Error on page {page}: {e}")
continue
except Exception as e:
# print(f"Error on search: {e}")
print(f"Error on search: {e}")
pass
finally:
channels[format_channel_name(name)] = info_list