Skip to content

Commit

Permalink
refactor:config(Guovin#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guovin committed Aug 12, 2024
1 parent f656074 commit e46c025
Show file tree
Hide file tree
Showing 17 changed files with 320 additions and 272 deletions.
20 changes: 12 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ jobs:
run: |
echo "OPEN_DRIVER=$(python -c '
try:
import user_config as config
except ImportError:
import config
print(config.open_driver)')" >> $GITHUB_ENV
from utils.config import get_config
config = get_config()
open_driver = config.getboolean("Settings", "open_driver")
except:
open_driver = False
print(open_driver)')" >> $GITHUB_ENV
- name: Install Selenium
if: env.OPEN_DRIVER == 'True'
run: |
Expand Down Expand Up @@ -72,10 +74,12 @@ jobs:
git diff
final_file=$(python -c '
try:
import user_config as config
except ImportError:
import config
print(config.final_file)')
from utils.config import get_config
config = get_config()
final_file = config.get("Settings", "final_file")
except:
final_file = "output/result.txt"
print(final_file)')
if [[ -f "$final_file" ]]; then
git add -f "$final_file"
fi
Expand Down
41 changes: 0 additions & 41 deletions config.py

This file was deleted.

30 changes: 30 additions & 0 deletions config/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[Settings]
open_update = True
open_use_old_result = True
source_file = config/demo.txt
final_file = output/result.txt
favorite_list = 广东珠江,CCTV-1,CCTV-5,CCTV-5+,CCTV-13,广东体育,广东卫视,大湾区卫视,浙江卫视,湖南卫视,翡翠台

open_online_search = False
favorite_page_num = 5
default_page_num = 3
urls_limit = 15
open_keep_all = False
open_sort = True
response_time_weight = 0.5
resolution_weight = 0.5
recent_days = 30
ipv_type = ipv4
domain_blacklist = epg.pw

url_keywords_blacklist =

open_subscribe = False
subscribe_urls = https://m3u.ibert.me/txt/fmml_dv6.txt,https://m3u.ibert.me/txt/o_cn.txt,https://m3u.ibert.me/txt/j_iptv.txt,https://github.moeyy.xyz/https://raw.githubusercontent.com/PizazzGY/TVBox/main/live.txt

open_multicast = True
region_list = 广东

open_proxy = False
open_driver = False

File renamed without changes.
3 changes: 0 additions & 3 deletions driver/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from selenium import webdriver
from utils.config import get_config

config = get_config()


def setup_driver(proxy=None):
Expand Down
28 changes: 14 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

@app.route("/")
def show_result():
user_final_file = getattr(config, "final_file", "result.txt")
user_final_file = config.get("Settings", "final_file")
with open(user_final_file, "r", encoding="utf-8") as file:
content = file.read()
return render_template_string("<pre>{{ content }}</pre>", content=content)
Expand All @@ -51,19 +51,19 @@ def __init__(self):
self.start_time = None

async def visit_page(self, channel_names=None):
if config.open_subscribe:
if config.getboolean("Settings", "open_subscribe"):
subscribe_task = asyncio.create_task(
get_channels_by_subscribe_urls(callback=self.update_progress)
)
self.tasks.append(subscribe_task)
self.subscribe_result = await subscribe_task
if config.open_multicast:
if config.getboolean("Settings", "open_multicast"):
multicast_task = asyncio.create_task(
get_channels_by_multicast(channel_names, self.update_progress)
)
self.tasks.append(multicast_task)
self.multicast_result = await multicast_task
if config.open_online_search:
if config.getboolean("Settings", "open_online_search"):
online_search_task = asyncio.create_task(
get_channels_by_online_search(channel_names, self.update_progress)
)
Expand Down Expand Up @@ -94,7 +94,7 @@ async def main(self):
self.multicast_result,
self.online_search_result,
)
if config.open_sort:
if config.getboolean("Settings", "open_sort"):
is_ffmpeg = is_ffmpeg_installed()
if not is_ffmpeg:
print("FFmpeg is not installed, using requests for sorting.")
Expand Down Expand Up @@ -137,15 +137,15 @@ async def main(self):
lambda: self.pbar_update("写入结果"),
)
self.pbar.close()
user_final_file = getattr(config, "final_file", "result.txt")
update_file(user_final_file, "result_new.txt")
if config.open_sort:
user_log_file = (
user_final_file = config.get("Settings", "final_file")
update_file(user_final_file, "output/result_new.txt")
if config.getboolean("Settings", "open_sort"):
user_log_file = "output/" + (
"user_result.log"
if os.path.exists("user_config.py")
if os.path.exists("config/user_config.ini")
else "result.log"
)
update_file(user_log_file, "result_new.log")
update_file(user_log_file, "output/result_new.log")
print(f"Update completed! Please check the {user_final_file} file!")
if not os.environ.get("GITHUB_ACTIONS"):
print(f"You can access the result at {get_ip_address()}")
Expand All @@ -165,10 +165,10 @@ def default_callback(self, *args, **kwargs):

self.update_progress = callback or default_callback
self.run_ui = True if callback else False
if config.open_update:
if config.getboolean("Settings", "open_update"):
await self.main()
if self.run_ui:
if not config.open_update:
if not config.getboolean("Settings", "open_update"):
print(f"You can access the result at {get_ip_address()}")
self.update_progress(
f"服务启动成功, 可访问以下链接:",
Expand All @@ -187,7 +187,7 @@ def stop(self):


def scheduled_task():
if config.open_update:
if config.getboolean("Settings", "open_update"):
update_source = UpdateSource()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
Expand Down
1 change: 0 additions & 1 deletion requests_custom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import re
from bs4 import BeautifulSoup
from fake_useragent import UserAgent
from time import sleep

headers = {
"Accept": "*/*",
Expand Down
Loading

0 comments on commit e46c025

Please sign in to comment.