Skip to content

Commit

Permalink
chore:origin_type_prefer unset
Browse files Browse the repository at this point in the history
  • Loading branch information
Guovin committed Dec 20, 2024
1 parent 8008273 commit 81d1c37
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 219 deletions.
98 changes: 49 additions & 49 deletions README.md

Large diffs are not rendered by default.

98 changes: 49 additions & 49 deletions README_en.md

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions config/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ app_port = 8000
# 生成结果文件路径; 默认值: output/result.txt | Generate result file path; Default value: output/result.txt
final_file = output/result.txt
# 结果中偏好的酒店源接口数量 | Preferred number of hotel source interfaces in the result
hotel_num = 4
hotel_num = 10
# 酒店地区获取分页数量 | Number of hotel region acquisition pages
hotel_page_num = 1
# 酒店源地区列表,"全部"表示所有地区 | Hotel source region list, "all" means all regions
Expand All @@ -70,7 +70,7 @@ min_resolution = 1920x1080
# 接口最小速率(单位M/s),需要开启 open_filter_speed 才能生效 | Minimum rate of the interface (unit M/s), need to enable open_filter_speed to take effect
min_speed = 0.2
# 结果中偏好的组播源接口数量 | Preferred number of multicast source interfaces in the result
multicast_num = 3
multicast_num = 10
# 组播地区获取分页数量 | Number of multicast region acquisition pages
multicast_page_num = 1
# 组播源地区列表,"全部"表示所有地区 | Multicast source region list, "all" means all regions
Expand All @@ -79,8 +79,8 @@ multicast_region_list = 全部
online_search_num = 0
# 关键字搜索频道获取分页数量 | Number of keyword search channel acquisition pages
online_search_page_num = 1
# 结果偏好的接口来源,结果优先按该顺序进行排序,hotel:酒店源,multicast:组播源,subscribe:订阅源,online_search:关键字搜索 | Preferred interface source of the result, the result is sorted in this order, hotel: hotel source, multicast: multicast source, subscribe: subscription source, online_search: keyword search
origin_type_prefer = hotel,multicast,subscribe,online_search
# 结果偏好的接口来源,结果优先按该顺序进行排序,逗号分隔,例如:hotel,multicast,subscribe,online_search;hotel:酒店源,multicast:组播源,subscribe:订阅源,online_search:关键字搜索;不填写则表示不指定来源,按照接口速率排序 | Preferred interface source of the result, the result is sorted according to this order, separated by commas, for example: hotel, multicast, subscribe, online_search; hotel: hotel source, multicast: multicast source, subscribe: subscription source, online_search: keyword search; If not filled in, it means that the source is not specified, and it is sorted according to the interface rate
origin_type_prefer =
# 获取最近时间范围内更新的接口(单位天),适当减小可避免出现匹配问题 | Get the interface updated within the recent time range (unit day), appropriately reducing can avoid matching problems
recent_days = 30
# 查询请求超时时长,单位秒(s),用于控制查询接口文本链接的超时时长以及重试时长,调整此值能优化更新时间 | Query request timeout duration, unit seconds (s), used to control the timeout duration and retry duration of querying the interface text link, adjusting this value can optimize the update time
Expand All @@ -90,6 +90,6 @@ sort_timeout = 10
# 模板文件路径, 默认值: config/demo.txt | Template file path, Default value: config/demo.txt
source_file = config/demo.txt
# 结果中偏好的订阅源接口数量 | Preferred number of subscription source interfaces in the result
subscribe_num = 3
subscribe_num = 10
# 单个频道接口数量 | Number of interfaces per channel
urls_limit = 10
98 changes: 49 additions & 49 deletions docs/config.md

Large diffs are not rendered by default.

98 changes: 49 additions & 49 deletions docs/config_en.md

Large diffs are not rendered by default.

45 changes: 33 additions & 12 deletions tkinter_ui/prefer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import tkinter as tk
from tkinter import ttk

from utils.config import config


Expand All @@ -8,10 +9,9 @@ def init_ui(self, root=None):
"""
Init prefer UI
"""
origin_type_prefer = [item.lower() for item in config.origin_type_prefer]
config_options = [
{"label_text": f"结果来源优先{i+1}:", "combo_box_value": i}
for i in range(len(origin_type_prefer))
{"label_text": f"结果来源优先{i + 1}:", "combo_box_value": value}
for i, value in enumerate(self.get_origin_type_prefer_index(config.origin_type_prefer))
]
self.origin_type_prefer_options = []
for config_option in config_options:
Expand Down Expand Up @@ -48,6 +48,18 @@ def init_ui(self, root=None):
input.entry.bind("<KeyRelease>", input.update_input)
self.ipv_type_input.append(input)

def get_origin_type_prefer_index(self, origin_type_prefer):
index_list = [None, None, None, None]
origin_type_prefer_obj = {
"hotel": 0,
"multicast": 1,
"subscribe": 2,
"online_search": 3,
}
for i, item in enumerate(origin_type_prefer):
index_list[i] = origin_type_prefer_obj[item]
return index_list

def update_ipv_type_prefer(self, event):
config.set(
"Settings",
Expand Down Expand Up @@ -87,7 +99,7 @@ def __init__(self, master, ipv_type):
def update_input(self, event):
config.set(
"Settings",
f"{ self.ipv_type}_num",
f"{self.ipv_type}_num",
self.entry.get(),
)

Expand Down Expand Up @@ -123,33 +135,42 @@ def __init__(self, master, label_text, combo_box_value):
combo_box_values_name = list(self.origin_type_prefer_obj.keys())
self.combo_box["values"] = combo_box_values_name
self.combo_box.pack(side=tk.LEFT, padx=4, pady=8)
self.combo_box.current(combo_box_value)
origin_type_prefer = config.origin_type_prefer
if not origin_type_prefer or combo_box_value is None:
self.combo_box.current(None)
else:
self.combo_box.current(combo_box_value)

self.entry_label = tk.Label(self.column2, text="数量:", width=12)
self.entry_label.pack(side=tk.LEFT, padx=4, pady=8)

self.entry = tk.Entry(self.column2)
self.entry.insert(
0,
config.source_limits[self.origin_type_prefer_obj[self.combo_box.get()]],
)
if origin_type_prefer and combo_box_value is not None:
self.entry.insert(
0,
config.source_limits[self.origin_type_prefer_obj[self.combo_box.get()]],
)
self.entry.pack(side=tk.LEFT, padx=4, pady=8)

def update_select(self, key):
origin_type_prefer_list = [item.lower() for item in config.origin_type_prefer]
origin_type_prefer_list[self.combo_box_value] = self.origin_type_prefer_obj[
select_value = self.origin_type_prefer_obj[
self.combo_box.get()
]
if self.combo_box_value < len(origin_type_prefer_list):
origin_type_prefer_list[self.combo_box_value] = select_value
else:
origin_type_prefer_list.append(select_value)
config.set(
"Settings",
"origin_type_prefer",
(",").join(origin_type_prefer_list),
",".join(origin_type_prefer_list),
)

def update_input(self, event):
config.set(
"Settings",
f"{ self.origin_type_prefer_obj[self.combo_box.get()]}_num",
f"{self.origin_type_prefer_obj[self.combo_box.get()]}_num",
self.entry.get(),
)

Expand Down
2 changes: 1 addition & 1 deletion utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def origin_type_prefer(self):
for origin in self.config.get(
"Settings",
"origin_type_prefer",
fallback="hotel,multicast,subscribe,online_search",
fallback="",
).split(",")
if origin.strip().lower()
]
Expand Down
14 changes: 9 additions & 5 deletions utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ def get_total_urls(info_list, ipv_type_prefer, origin_type_prefer):
"""
Get the total urls from info list
"""
origin_prefer_bool = bool(origin_type_prefer)
if not origin_prefer_bool:
origin_type_prefer = ["all"]
categorized_urls = {
origin: {"ipv4": [], "ipv6": []} for origin in origin_type_prefer
}
Expand All @@ -163,7 +166,7 @@ def get_total_urls(info_list, ipv_type_prefer, origin_type_prefer):
if origin == "subscribe" and "/rtp/" in url:
origin = "multicast"

if origin not in origin_type_prefer:
if origin_prefer_bool and (origin not in origin_type_prefer):
continue

if config.open_filter_resolution and resolution:
Expand All @@ -184,6 +187,9 @@ def get_total_urls(info_list, ipv_type_prefer, origin_type_prefer):
if resolution:
url = add_url_info(url, resolution)

if not origin_prefer_bool:
origin = "all"

if url_is_ipv6:
categorized_urls[origin]["ipv6"].append(url)
else:
Expand All @@ -205,7 +211,7 @@ def get_total_urls(info_list, ipv_type_prefer, origin_type_prefer):
if not urls:
break
limit = min(
max(config.source_limits[origin] - ipv_num[ipv_type], 0),
max(config.source_limits.get(origin, urls_limit) - ipv_num[ipv_type], 0),
max(config.ipv_limit[ipv_type] - ipv_num[ipv_type], 0),
)
limit_urls = urls[:limit]
Expand All @@ -222,9 +228,7 @@ def get_total_urls(info_list, ipv_type_prefer, origin_type_prefer):
for ipv_type in ipv_type_total:
if len(total_urls) >= urls_limit:
break
extra_urls = categorized_urls[origin][ipv_type][
: config.source_limits[origin]
]
extra_urls = categorized_urls[origin][ipv_type][: config.source_limits.get(origin, urls_limit)]
total_urls.extend(extra_urls)
total_urls = list(dict.fromkeys(total_urls))[:urls_limit]

Expand Down

0 comments on commit 81d1c37

Please sign in to comment.