From 55a9928cb314e451edb64017b58240358071627c Mon Sep 17 00:00:00 2001 From: "guorong.zheng" <360996299@qq.com> Date: Wed, 13 Nov 2024 10:44:48 +0800 Subject: [PATCH 1/2] feat:open_empty_category(#551) --- config/config.ini | 3 ++- docs/config.md | 1 + docs/config_en.md | 1 + tkinter_ui/default.py | 26 ++++++++++++++++++++++---- utils/channel.py | 6 ++++-- utils/config.py | 4 ++++ 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/config/config.ini b/config/config.ini index 8a470ddc300..0e688d45ee5 100644 --- a/config/config.ini +++ b/config/config.ini @@ -44,4 +44,5 @@ hotel_num = 10 multicast_num = 10 subscribe_num = 10 online_search_num = 0 -open_url_info = True \ No newline at end of file +open_url_info = True +open_empty_category = True \ No newline at end of file diff --git a/docs/config.md b/docs/config.md index af3f085dbe7..5845d5631c6 100644 --- a/docs/config.md +++ b/docs/config.md @@ -45,3 +45,4 @@ | subscribe_num | 10 | 结果中偏好的订阅源接口数量 | | online_search_num | 10 | 结果中偏好的关键字搜索接口数量 | | open_url_info | True | 开启显示接口说明信息,用于控制是否显示分辨率、接口协议类型等信息,为$符号后的内容,播放软件使用该信息对接口进行描述 | +| open_empty_category | True | 开启无结果频道分类,自动归类至底部 | diff --git a/docs/config_en.md b/docs/config_en.md index 0462d9c83f2..210ef54900d 100644 --- a/docs/config_en.md +++ b/docs/config_en.md @@ -45,3 +45,4 @@ | subscribe_num | 10 | The number of preferred subscribe source interfaces in the results | | online_search_num | 10 | The number of preferred keyword search interfaces in the results | | open_url_info | True | Enable display of API description information, used to control whether to show resolution, API protocol type, etc., the content after the $ symbol, playback software uses this information to describe the API | +| open_empty_category | True | Enable the No Results Channel Category, which will automatically categorize channels without results to the bottom | diff --git a/tkinter_ui/default.py b/tkinter_ui/default.py index 2a4c4ebc5df..f527ce73a10 100644 --- a/tkinter_ui/default.py +++ b/tkinter_ui/default.py @@ -341,25 +341,37 @@ def init_ui(self, root): onvalue=True, offvalue=False, command=self.update_open_update_time, - text="(结果顶部显示)", ) self.open_update_time_checkbutton.pack(side=tk.LEFT, padx=4, pady=8) self.open_url_info_label = tk.Label( - frame_default_open_update_info_column2, text="显示接口信息:", width=12 + frame_default_open_update_info_column1, text="显示接口信息:", width=12 ) self.open_url_info_label.pack(side=tk.LEFT, padx=4, pady=8) self.open_url_info_var = tk.BooleanVar(value=config.open_url_info) self.open_url_info_checkbutton = ttk.Checkbutton( - frame_default_open_update_info_column2, + frame_default_open_update_info_column1, variable=self.open_url_info_var, onvalue=True, offvalue=False, command=self.update_open_url_info, - text="(需要播放器支持)", ) self.open_url_info_checkbutton.pack(side=tk.LEFT, padx=4, pady=8) + self.open_empty_category_label = tk.Label( + frame_default_open_update_info_column2, text="无结果频道分类:", width=12 + ) + self.open_empty_category_label.pack(side=tk.LEFT, padx=4, pady=8) + self.open_empty_category_var = tk.BooleanVar(value=config.open_empty_category) + self.open_empty_category_checkbutton = ttk.Checkbutton( + frame_default_open_update_info_column2, + variable=self.open_empty_category_var, + onvalue=True, + offvalue=False, + command=self.update_open_empty_category, + ) + self.open_empty_category_checkbutton.pack(side=tk.LEFT, padx=4, pady=8) + frame_default_domain_blacklist = tk.Frame(root) frame_default_domain_blacklist.pack(fill=tk.X) @@ -476,6 +488,11 @@ def update_open_update_time(self): def update_open_url_info(self): config.set("Settings", "open_url_info", str(self.open_url_info_var.get())) + def update_open_empty_category(self): + config.set( + "Settings", "update_open_empty_category", str(self.open_url_info_var.get()) + ) + def update_ipv_type(self, event): config.set("Settings", "ipv_type", self.ipv_type_combo.get()) @@ -522,6 +539,7 @@ def change_entry_state(self, state): "resolution_weight_scale", "open_update_time_checkbutton", "open_url_info_checkbutton", + "open_empty_category_checkbutton", "ipv_type_combo", "domain_blacklist_text", "url_keywords_blacklist_text", diff --git a/utils/channel.py b/utils/channel.py index b5f2d13ed0e..910e715890c 100644 --- a/utils/channel.py +++ b/utils/channel.py @@ -730,6 +730,7 @@ def write_channel_to_file(data, ipv6=False, callback=None): update_time = now.strftime("%Y-%m-%d %H:%M:%S") update_channel_urls_txt("更新时间", f"{update_time}", ["url"]) no_result_name = [] + open_empty_category = config.open_empty_category for cate, channel_obj in data.items(): print(f"\n{cate}:", end=" ") channel_obj_keys = channel_obj.keys() @@ -740,11 +741,12 @@ def write_channel_to_file(data, ipv6=False, callback=None): end_char = ", " if i < names_len - 1 else "" print(f"{name}:", len(channel_urls), end=end_char) if not channel_urls: - no_result_name.append(name) + if open_empty_category: + no_result_name.append(name) continue update_channel_urls_txt(cate, name, channel_urls, callback=callback) print() - if no_result_name: + if open_empty_category and no_result_name: print("\n🈳 No result channel name:") for i, name in enumerate(no_result_name): end_char = ", " if i < len(no_result_name) - 1 else "" diff --git a/utils/config.py b/utils/config.py index 447039c8cc2..512f657322d 100644 --- a/utils/config.py +++ b/utils/config.py @@ -312,6 +312,10 @@ def response_time_weight(self): def resolution_weight(self): return self.config.getfloat("Settings", "resolution_weight", fallback=0.5) + @property + def open_empty_category(self): + return self.config.getboolean("Settings", "open_empty_category", fallback=True) + def load(self): """ Load the config From 4764255a1351b7244f6af4b00ceae55d95b917d2 Mon Sep 17 00:00:00 2001 From: "guorong.zheng" <360996299@qq.com> Date: Wed, 13 Nov 2024 13:50:46 +0800 Subject: [PATCH 2/2] fix:check soup descendants --- utils/channel.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utils/channel.py b/utils/channel.py index 910e715890c..b7d368c884f 100644 --- a/utils/channel.py +++ b/utils/channel.py @@ -287,6 +287,8 @@ def get_results_from_soup(soup, name): Get the results from the soup """ results = [] + if not soup.descendants: + return results for element in soup.descendants: if isinstance(element, NavigableString): text = element.get_text(strip=True) @@ -311,6 +313,8 @@ def get_results_from_multicast_soup(soup, hotel=False): Get the results from the multicast soup """ results = [] + if not soup.descendants: + return results for element in soup.descendants: if isinstance(element, NavigableString): text = element.strip()