Skip to content

Commit

Permalink
chore:remove source_channels config
Browse files Browse the repository at this point in the history
  • Loading branch information
Guovin committed Aug 29, 2024
1 parent eb59416 commit 72a8a1d
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 67 deletions.
1 change: 0 additions & 1 deletion config/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ open_update = True
open_use_old_result = True
source_file = config/demo.txt
final_file = output/result.txt
source_channels = 广东珠江,广东体育,广东新闻,广东卫视,大湾区卫视,江门综合,江门侨乡生活,新会综合,鹤山综合,佛山综合,佛山公共,佛山影视,深圳卫视,CCTV-1,CCTV-2,CCTV-3,CCTV-4,CCTV-5,CCTV-5+,CCTV-6,CCTV-7,CCTV-8,CCTV-9,CCTV-10,CCTV-11,CCTV-12,CCTV-13,CCTV-14,CCTV-15,CCTV-16,CCTV-17,广东卫视,浙江卫视,湖南卫视,北京卫视,湖北卫视,黑龙江卫视,安徽卫视,重庆卫视,东方卫视,东南卫视,甘肃卫视,广西卫视,贵州卫视,海南卫视,河北卫视,河南卫视,吉林卫视,江苏卫视,江西卫视,辽宁卫视,内蒙古卫视,宁夏卫视,青海卫视,山东卫视,山西卫视,陕西卫视,四川卫视,深圳卫视,三沙卫视,天津卫视,西藏卫视,新疆卫视,云南卫视,翡翠台,明珠台,星河台,凤凰中文,凤凰资讯,凤凰香港,TVBS亚洲,TVBS新闻,TVBS欢乐
open_online_search = False
online_search_page_num = 3
urls_limit = 15
Expand Down
1 change: 0 additions & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
| open_driver | False | 开启浏览器运行,若更新无数据可开启此模式,较消耗性能 |
| open_proxy | True | 开启代理,自动获取免费可用代理,若更新无数据可开启此模式 |
| source_file | config/demo.txt | 模板文件路径 |
| source_channels | | 获取更新的频道名称 |
| final_file | output/result.txt | 生成结果文件路径 |
| open_online_search | False | 开启线上检索源功能 |
| online_search_page_num | 5 | 在线检索频道获取分页数量 |
Expand Down
1 change: 0 additions & 1 deletion docs/config_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
| open_driver | False | Enable browser execution, If there are no updates, this mode can be enabled, which consumes more performance |
| open_proxy | True | Enable proxy, automatically obtains free available proxies, If there are no updates, this mode can be enabled |
| source_file | config/demo.txt | Template file path |
| source_channels | | The names of the channel to be updated |
| final_file | output/result.txt | Generated result file path |
| open_online_search | False | Enable online search source feature |
| online_search_page_num | 5 | Page retrieval quantity for online search channels |
Expand Down
31 changes: 0 additions & 31 deletions tkinter_ui/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,6 @@ def init_ui(self, root):
)
self.source_file_button.pack(side=tk.LEFT, padx=4, pady=0)

frame_default_source_channels = tk.Frame(root)
frame_default_source_channels.pack(fill=tk.X)

self.source_channels_label = tk.Label(
frame_default_source_channels, text="频道名称:", width=8
)
self.source_channels_label.pack(side=tk.LEFT, padx=4, pady=8)
self.source_channels_text = scrolledtext.ScrolledText(
frame_default_source_channels, height=5
)
self.source_channels_text.pack(
side=tk.LEFT, padx=4, pady=8, expand=True, fill=tk.BOTH
)
self.source_channels_text.insert(
tk.END, config.get("Settings", "source_channels")
)
self.source_channels_text.bind("<KeyRelease>", self.update_source_channels)

frame_default_final_file = tk.Frame(root)
frame_default_final_file.pack(fill=tk.X)
frame_default_final_file_column1 = tk.Frame(frame_default_final_file)
Expand Down Expand Up @@ -349,18 +331,6 @@ def select_source_file(self):
self.source_file_entry.delete(0, tk.END)
self.source_file_entry.insert(0, filepath)
config.set("Settings", "source_file", filepath)
get_channel_items(change_source_path=True)
self.source_channels_text.delete(1.0, tk.END)
self.source_channels_text.insert(
tk.END, config.get("Settings", "source_channels")
)

def update_source_channels(self, event):
config.set(
"Settings",
"source_channels",
self.source_channels_text.get(1.0, tk.END),
)

def select_final_file(self):
filepath = filedialog.askopenfilename(
Expand Down Expand Up @@ -432,7 +402,6 @@ def change_entry_state(self, state):
"open_proxy_checkbutton",
"source_file_entry",
"source_file_button",
"source_channels_text",
"final_file_entry",
"final_file_button",
"open_keep_all_checkbutton",
Expand Down
3 changes: 1 addition & 2 deletions tkinter_ui/tkinter_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def save_config(self):
"open_update": self.default_ui.open_update_var.get(),
"open_use_old_result": self.default_ui.open_use_old_result_var.get(),
"source_file": self.default_ui.source_file_entry.get(),
"source_channels": self.default_ui.source_channels_text.get(1.0, tk.END),
"final_file": self.default_ui.final_file_entry.get(),
"urls_limit": self.default_ui.urls_limit_entry.get(),
"open_driver": self.default_ui.open_driver_var.get(),
Expand Down Expand Up @@ -200,7 +199,7 @@ def get_root_location(root):
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
width = 550
height = 750
height = 650
x = (screen_width / 2) - (width / 2)
y = (screen_height / 2) - (height / 2)
return (width, height, x, y)
Expand Down
35 changes: 4 additions & 31 deletions utils/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
)


def get_channel_data_from_file(
channels=None, file=None, names=None, from_result=False, change_source_path=False
):
def get_channel_data_from_file(channels=None, file=None, from_result=False):
"""
Get the channel data from the file
"""
Expand All @@ -46,56 +44,31 @@ def get_channel_data_from_file(
match = re.search(pattern, line)
if match is not None:
name = match.group(1).strip()
if not change_source_path and name not in names:
continue
url = match.group(2).strip()
if url and url not in channels[current_category][name]:
channels[current_category][name].append(url)
return channels


def get_channel_items(change_source_path=False):
def get_channel_items():
"""
Get the channel items from the source file
"""
user_source_file = config.get("Settings", "source_file")
user_final_file = config.get("Settings", "final_file")
channels = defaultdict(lambda: defaultdict(list))
source_channel_names = config.get("Settings", "source_channels").split(",")

if os.path.exists(resource_path(user_source_file)):
with open(resource_path(user_source_file), "r", encoding="utf-8") as file:
channels = get_channel_data_from_file(
channels=channels,
file=file,
names=source_channel_names,
change_source_path=change_source_path,
)
channels = get_channel_data_from_file(channels=channels, file=file)

if config.getboolean("Settings", "open_use_old_result") and os.path.exists(
resource_path(user_final_file)
):
with open(resource_path(user_final_file), "r", encoding="utf-8") as file:
channels = get_channel_data_from_file(
channels=channels,
file=file,
names=source_channel_names,
from_result=True,
change_source_path=change_source_path,
channels=channels, file=file, from_result=True
)

channel_names = [
name for channel_obj in channels.values() for name in channel_obj.keys()
]
if not change_source_path:
for source_name in source_channel_names:
if source_name not in channel_names:
channels["自定义频道"][source_name] = []
total_channel_names = ",".join(
[name for channel_obj in channels.values() for name in channel_obj.keys()]
)
config.set("Settings", "source_channels", total_channel_names)
save_config()
return channels


Expand Down

0 comments on commit 72a8a1d

Please sign in to comment.