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

update #554

Merged
merged 3 commits into from
Nov 13, 2024
Merged
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
3 changes: 2 additions & 1 deletion config/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ hotel_num = 10
multicast_num = 10
subscribe_num = 10
online_search_num = 0
open_url_info = True
open_url_info = True
open_empty_category = True
1 change: 1 addition & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@
| subscribe_num | 10 | 结果中偏好的订阅源接口数量 |
| online_search_num | 10 | 结果中偏好的关键字搜索接口数量 |
| open_url_info | True | 开启显示接口说明信息,用于控制是否显示分辨率、接口协议类型等信息,为$符号后的内容,播放软件使用该信息对接口进行描述 |
| open_empty_category | True | 开启无结果频道分类,自动归类至底部 |
1 change: 1 addition & 0 deletions docs/config_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
26 changes: 22 additions & 4 deletions tkinter_ui/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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",
Expand Down
10 changes: 8 additions & 2 deletions utils/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -730,6 +734,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()
Expand All @@ -740,11 +745,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 ""
Expand Down
4 changes: 4 additions & 0 deletions utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading