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

feat #507

Merged
merged 7 commits into from
Nov 4, 2024
Merged

feat #507

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
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
echo "OPEN_DRIVER=$(python -c '
try:
from utils.config import config
open_driver = config.getboolean("Settings", "open_driver", fallback=True)
open_driver = config.open_driver
except:
open_driver = False
print(open_driver)')" >> $GITHUB_ENV
Expand All @@ -46,7 +46,7 @@ jobs:
echo "OPEN_FFMPEG=$(python -c '
try:
from utils.config import config
open_ffmpeg = config.getboolean("Settings", "open_ffmpeg", fallback=True)
open_ffmpeg = config.open_ffmpeg
except:
open_ffmpeg = False
print(open_ffmpeg)')" >> $GITHUB_ENV
Expand Down Expand Up @@ -75,15 +75,15 @@ jobs:
final_file=$(python -c '
try:
from utils.config import config
final_file = config.get("Settings", "final_file", fallback="output/result.txt")
final_file = config.final_file
except:
final_file = "output/result.txt"
print(final_file)')
final_m3u_file=$(python -c '
try:
from utils.config import config
import os
final_file = config.get("Settings", "final_file", fallback="output/result.txt")
final_file = config.final_file
final_m3u_file = os.path.splitext(final_file)[0] + ".m3u"
except:
final_m3u_file = "output/result.m3u"
Expand Down
1 change: 1 addition & 0 deletions config/demo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ CETV5
广东卫视
广东民生
大湾区卫视
广州综合
广州影视
广州竞赛
江门综合
Expand Down
214 changes: 100 additions & 114 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from utils.config import config, resource_path
from utils.config import config
from utils.channel import (
get_channel_items,
append_total_data,
Expand All @@ -19,6 +19,7 @@
process_nested_dict,
format_interval,
check_ipv6_support,
resource_path,
)
from updates.subscribe import get_channels_by_subscribe_urls
from updates.multicast import get_channels_by_multicast
Expand Down Expand Up @@ -82,35 +83,29 @@ def __init__(self):

async def visit_page(self, channel_names=None):
tasks_config = [
("open_hotel_fofa", get_channels_by_fofa, "hotel_fofa_result"),
("open_multicast", get_channels_by_multicast, "multicast_result"),
("open_hotel_tonkiang", get_channels_by_hotel, "hotel_tonkiang_result"),
("open_subscribe", get_channels_by_subscribe_urls, "subscribe_result"),
("hotel_fofa", get_channels_by_fofa, "hotel_fofa_result"),
("multicast", get_channels_by_multicast, "multicast_result"),
("hotel_tonkiang", get_channels_by_hotel, "hotel_tonkiang_result"),
("subscribe", get_channels_by_subscribe_urls, "subscribe_result"),
(
"open_online_search",
"online_search",
get_channels_by_online_search,
"online_search_result",
),
]

for setting, task_func, result_attr in tasks_config:
if (
setting == "open_hotel_tonkiang" or setting == "open_hotel_fofa"
) and config.getboolean("Settings", "open_hotel", fallback=True) == False:
setting == "hotel_tonkiang" or setting == "hotel_fofa"
) and config.open_hotel == False:
continue
if config.getboolean("Settings", setting, fallback=True):
if setting == "open_subscribe":
subscribe_urls = [
url.strip()
for url in config.get(
"Settings", "subscribe_urls", fallback=""
).split(",")
if url.strip()
]
if config.open_method[setting]:
if setting == "subscribe":
subscribe_urls = config.subscribe_urls
task = asyncio.create_task(
task_func(subscribe_urls, callback=self.update_progress)
)
elif setting == "open_hotel_tonkiang" or setting == "open_hotel_fofa":
elif setting == "hotel_tonkiang" or setting == "hotel_fofa":
task = asyncio.create_task(task_func(callback=self.update_progress))
else:
task = asyncio.create_task(
Expand Down Expand Up @@ -141,107 +136,103 @@ def get_urls_len(self, filter=False):

async def main(self):
try:
main_start_time = time()
self.channel_items = get_channel_items()
channel_names = [
name
for channel_obj in self.channel_items.values()
for name in channel_obj.keys()
]
await self.visit_page(channel_names)
self.tasks = []
append_total_data(
self.channel_items.items(),
channel_names,
self.channel_data,
self.hotel_fofa_result,
self.multicast_result,
self.hotel_tonkiang_result,
self.subscribe_result,
self.online_search_result,
)
urls_total = self.get_urls_len()
channel_data_cache = copy.deepcopy(self.channel_data)
ipv6_support = check_ipv6_support()
open_sort = config.getboolean("Settings", "open_sort", fallback=True)
if open_sort:
self.total = self.get_urls_len(filter=True)
print(f"Total urls: {urls_total}, need to sort: {self.total}")
sort_callback = lambda: self.pbar_update(name="测速")
self.update_progress(
f"正在测速排序, 共{urls_total}个接口, {self.total}个接口需要进行测速",
0,
if config.open_update:
setup_logging()
main_start_time = time()
self.channel_items = get_channel_items()
channel_names = [
name
for channel_obj in self.channel_items.values()
for name in channel_obj.keys()
]
await self.visit_page(channel_names)
self.tasks = []
append_total_data(
self.channel_items.items(),
channel_names,
self.channel_data,
self.hotel_fofa_result,
self.multicast_result,
self.hotel_tonkiang_result,
self.subscribe_result,
self.online_search_result,
)
channel_data_cache = copy.deepcopy(self.channel_data)
ipv6_support = check_ipv6_support()
open_sort = config.open_sort
if open_sort:
urls_total = self.get_urls_len()
self.total = self.get_urls_len(filter=True)
print(f"Total urls: {urls_total}, need to sort: {self.total}")
sort_callback = lambda: self.pbar_update(name="测速")
self.update_progress(
f"正在测速排序, 共{urls_total}个接口, {self.total}个接口需要进行测速",
0,
)
self.start_time = time()
self.pbar = tqdm_asyncio(total=self.total, desc="Sorting")
self.channel_data = await process_sort_channel_list(
self.channel_data,
ipv6=ipv6_support,
callback=sort_callback,
)
else:
format_channel_url_info(self.channel_data)
self.total = self.get_urls_len()
self.pbar = tqdm(total=self.total, desc="Writing")
self.start_time = time()
self.pbar = tqdm_asyncio(total=self.total, desc="Sorting")
self.channel_data = await process_sort_channel_list(
write_channel_to_file(
self.channel_data,
ipv6=ipv6_support,
callback=sort_callback,
callback=lambda: self.pbar_update(name="写入结果"),
)
else:
format_channel_url_info(self.channel_data)
self.total = self.get_urls_len()
self.pbar = tqdm(total=self.total, desc="Writing")
self.start_time = time()
write_channel_to_file(
self.channel_data,
ipv6=ipv6_support,
callback=lambda: self.pbar_update(name="写入结果"),
)
self.pbar.close()
user_final_file = config.get(
"Settings", "final_file", fallback="output/result.txt"
)
update_file(user_final_file, "output/result_new.txt")
if os.path.exists(user_final_file):
result_file = (
"user_result.txt"
if os.path.exists("config/user_config.ini")
else "result.txt"
)
shutil.copy(user_final_file, result_file)
if config.getboolean("Settings", "open_use_old_result", fallback=True):
self.pbar.close()
user_final_file = config.final_file
update_file(user_final_file, "output/result_new.txt")
if os.path.exists(user_final_file):
result_file = (
"user_result.txt"
if os.path.exists("config/user_config.ini")
else "result.txt"
)
shutil.copy(user_final_file, result_file)
if config.open_use_old_result:
if open_sort:
get_channel_data_cache_with_compare(
channel_data_cache, self.channel_data
)
with open(
resource_path("output/result_cache.pkl", persistent=True), "wb"
) as file:
pickle.dump(channel_data_cache, file)
if open_sort:
get_channel_data_cache_with_compare(
channel_data_cache, self.channel_data
user_log_file = "output/" + (
"user_result.log"
if os.path.exists("config/user_config.ini")
else "result.log"
)
with open(
resource_path("output/result_cache.pkl", persistent=True), "wb"
) as file:
pickle.dump(channel_data_cache, file)
if open_sort:
user_log_file = "output/" + (
"user_result.log"
if os.path.exists("config/user_config.ini")
else "result.log"
update_file(user_log_file, "output/result_new.log", copy=True)
convert_to_m3u()
total_time = format_interval(time() - main_start_time)
print(
f"🥳 Update completed! Total time spent: {total_time}. Please check the {user_final_file} file!"
)
update_file(user_log_file, "output/result_new.log", copy=True)
convert_to_m3u()
total_time = format_interval(time() - main_start_time)
print(
f"Update completed! Total time spent: {total_time}. Please check the {user_final_file} file!"
)
open_service = config.open_service
if self.run_ui:
open_service = config.getboolean(
"Settings", "open_service", fallback=True
)
service_tip = ", 可使用以下链接观看直播:" if open_service else ""
tip = (
f"服务启动成功{service_tip}"
if open_service
and config.getboolean("Settings", "open_update", fallback=True)
== False
else f"更新完成, 耗时: {total_time}, 请检查{user_final_file}文件{service_tip}"
f"✅ 服务启动成功{service_tip}"
if open_service and config.open_update == False
else f"🥳 更新完成, 耗时: {total_time}, 请检查{user_final_file}文件{service_tip}"
)
self.update_progress(
tip,
100,
True,
url=f"{get_ip_address()}" if open_service else None,
)
if open_service:
run_service()
if open_service:
run_service()
except asyncio.exceptions.CancelledError:
print("Update cancelled!")
finally:
Expand All @@ -253,9 +244,7 @@ def default_callback(self, *args, **kwargs):

self.update_progress = callback or default_callback
self.run_ui = True if callback else False
if config.getboolean("Settings", "open_update", fallback=True):
setup_logging()
await self.main()
await self.main()

def stop(self):
for task in self.tasks:
Expand All @@ -266,24 +255,21 @@ def stop(self):


def scheduled_task():
if config.getboolean("Settings", "open_update", fallback=True):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
update_source = UpdateSource()
loop.run_until_complete(update_source.start())
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
update_source = UpdateSource()
loop.run_until_complete(update_source.start())


def run_service():
if not os.environ.get("GITHUB_ACTIONS"):
ip_address = get_ip_address()
print(f"You can use this url to watch the live stream: {ip_address}")
print(f"Result detail: {ip_address}/result")
print(f"Log detail: {ip_address}/log")
print(f"📄 Result detail: {ip_address}/result")
print(f"📄 Log detail: {ip_address}/log")
print(f"✅ You can use this url to watch IPTV 📺: {ip_address}")
app.run(host="0.0.0.0", port=8000)


if __name__ == "__main__":
if len(sys.argv) == 1 or (len(sys.argv) > 1 and sys.argv[1] == "scheduled_task"):
scheduled_task()
if config.getboolean("Settings", "open_service", fallback=True):
run_service()
2 changes: 1 addition & 1 deletion tkinter_ui/about.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import tkinter as tk
from PIL import Image, ImageTk
import webbrowser
from utils.config import resource_path
from utils.tools import resource_path


class AboutUI:
Expand Down
Loading
Loading