Skip to content

Commit

Permalink
feat:auto ipv_type_prefer
Browse files Browse the repository at this point in the history
  • Loading branch information
Guovin committed Oct 25, 2024
1 parent fa9b4e0 commit ba5ab3d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion config/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ response_time_weight = 0.5
resolution_weight = 0.5
recent_days = 30
ipv_type = 全部
ipv_type_prefer = IPv4
ipv_type_prefer = 自动
ipv4_num = 15
ipv6_num = 15
domain_blacklist = epg.pw,skype.serv00.net,iptv.yjxfz.com,live-hls-web-ajb.getaj.net,live.goodiptv.club,hc73k3dhwo5gfkt.wcetv.com
Expand Down
2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
| resolution_weight | 0.5 | 分辨率权重值 (所有权重值总和应为 1) |
| recent_days | 30 | 获取最近时间范围内更新的接口(单位天),适当减小可避免出现匹配问题 |
| ipv_type | ipv4 | 生成结果中接口的协议类型,可选值:ipv4、ipv6、全部 |
| ipv_type_prefer | IPv4 | 接口协议类型偏好,优先将该类型的接口排在结果前面,可选值:IPv4、IPv6、随机 |
| ipv_type_prefer | IPv4 | 接口协议类型偏好,优先将该类型的接口排在结果前面,可选值:IPv4、IPv6、自动 |
| ipv4_num | 15 | 结果中偏好的 IPv4 接口数量 |
| ipv6_num | 15 | 结果中偏好的 IPv6 接口数量 |
| domain_blacklist | epg.pw | 接口域名黑名单,用于过滤低质量含广告类域名的接口 |
Expand Down
2 changes: 1 addition & 1 deletion docs/config_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
| resolution_weight | 0.5 | Resolution weight value (the sum of all weight values should be 1) |
| recent_days | 30 | Retrieve interfaces updated within a recent time range (in days), reducing appropriately can avoid matching issues |
| ipv_type | ipv4 | The protocol type of interface in the generated result, optional values: ipv4, ipv6, all |
| ipv_type_prefer | IPv4 | Interface protocol type preference, prioritize interfaces of this type in the results, optional values: IPv4, IPv6, random |
| ipv_type_prefer | IPv4 | Interface protocol type preference, prioritize interfaces of this type in the results, optional values: IPv4, IPv6, auto |
| ipv4_num | 15 | The preferred number of IPv4 interfaces in the result |
| ipv6_num | 15 | The preferred number of IPv6 interfaces in the result |
| domain_blacklist | epg.pw | Interface domain blacklist, used to filter out interfaces with low-quality, ad-inclusive domains |
Expand Down
4 changes: 4 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
get_result_file_content,
process_nested_dict,
format_interval,
check_ipv6_support,
)
from updates.subscribe import get_channels_by_subscribe_urls
from updates.multicast import get_channels_by_multicast
Expand Down Expand Up @@ -161,6 +162,7 @@ async def main(self):
)
urls_total = self.get_urls_len()
channel_data_cache = copy.deepcopy(self.channel_data)
ipv6_support = check_ipv6_support()
open_sort = config.getboolean("Settings", "open_sort", fallback=True)
if open_sort:
self.total = self.get_urls_len(filter=True)
Expand All @@ -174,6 +176,7 @@ async def main(self):
self.pbar = tqdm_asyncio(total=self.total, desc="Sorting")
self.channel_data = await process_sort_channel_list(
self.channel_data,
ipv6=ipv6_support,
callback=sort_callback,
)
else:
Expand All @@ -184,6 +187,7 @@ async def main(self):
write_channel_to_file(
channel_items_obj_items,
self.channel_data,
ipv6=ipv6_support,
callback=lambda: self.pbar_update(name="写入结果"),
)
self.pbar.close()
Expand Down
2 changes: 1 addition & 1 deletion tkinter_ui/prefer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def init_ui(self, root=None):
self.prefer_ipv_type_label.pack(side=tk.LEFT, padx=4, pady=8)
self.prefer_ipv_type_combo = ttk.Combobox(frame_prefer_ipv_type)
self.prefer_ipv_type_combo.pack(side=tk.LEFT, padx=4, pady=8)
self.prefer_ipv_type_combo["values"] = ("IPv4", "IPv6", "随机")
self.prefer_ipv_type_combo["values"] = ("IPv4", "IPv6", "自动")
ipv_type_prefer = config.get(
"Settings", "ipv_type_prefer", fallback="IPv4"
).lower()
Expand Down
13 changes: 4 additions & 9 deletions utils/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from utils.tools import (
check_url_by_patterns,
get_total_urls_from_info_list,
check_ipv6_support,
process_nested_dict,
get_resolution_value,
)
Expand Down Expand Up @@ -687,7 +686,7 @@ async def sort_channel_list(
return {"cate": cate, "name": name, "data": data}


async def process_sort_channel_list(data, callback=None):
async def process_sort_channel_list(data, ipv6=False, callback=None):
"""
Processs the sort channel list
"""
Expand All @@ -700,11 +699,7 @@ async def process_sort_channel_list(data, callback=None):
config.get("Settings", "min_resolution", fallback="1920x1080")
)
open_ipv6 = "ipv6" in ipv_type or "all" in ipv_type or "全部" in ipv_type
ipv6_proxy = (
None
if not open_ipv6 or check_ipv6_support()
else "http://www.ipv6proxy.net/go.php?u="
)
ipv6_proxy = None if not open_ipv6 or ipv6 else "http://www.ipv6proxy.net/go.php?u="
ffmpeg_installed = is_ffmpeg_installed()
if open_ffmpeg and not ffmpeg_installed:
print("FFmpeg is not installed, using requests for sorting.")
Expand Down Expand Up @@ -775,7 +770,7 @@ async def process_sort_channel_list(data, callback=None):
return sort_data


def write_channel_to_file(items, data, callback=None):
def write_channel_to_file(items, data, ipv6=False, callback=None):
"""
Write channel to file
"""
Expand All @@ -792,7 +787,7 @@ def write_channel_to_file(items, data, callback=None):
names_len = len(list(channel_obj_keys))
for i, name in enumerate(channel_obj_keys):
info_list = data.get(cate, {}).get(name, [])
channel_urls = get_total_urls_from_info_list(info_list)
channel_urls = get_total_urls_from_info_list(info_list, ipv6=ipv6)
end_char = ", " if i < names_len - 1 else ""
print(f"{name}:", len(channel_urls), end=end_char)
update_channel_urls_txt(cate, name, channel_urls, callback=callback)
Expand Down
10 changes: 5 additions & 5 deletions utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def get_resolution_value(resolution_str):
return 0


def get_total_urls_from_info_list(infoList):
def get_total_urls_from_info_list(infoList, ipv6=False):
"""
Get the total urls from info list
"""
Expand Down Expand Up @@ -174,7 +174,7 @@ def get_total_urls_from_info_list(infoList):

if (
("ipv6" in ipv_type_prefer)
or "随机" in ipv_type_prefer
or "自动" in ipv_type_prefer
or "random" in ipv_type_prefer
) and "IPv6" in url:
categorized_urls[origin]["ipv6"].append(url)
Expand All @@ -186,8 +186,8 @@ def get_total_urls_from_info_list(infoList):
"ipv4": 0,
"ipv6": 0,
}
if "随机" in ipv_type_prefer or "random" in ipv_type_prefer:
ipv_type_prefer = ["ipv4", "ipv6"]
if "自动" in ipv_type_prefer or "auto" in ipv_type_prefer:
ipv_type_prefer = ["ipv6", "ipv4"] if ipv6 else ["ipv4", "ipv6"]
for origin in origin_type_prefer:
for ipv_type in ipv_type_prefer:
if ipv_num[ipv_type] < ipv_limit[ipv_type]:
Expand Down Expand Up @@ -258,7 +258,7 @@ def check_ipv6_support():
return True
except Exception:
pass
print("Your network does not support IPv6, using proxy instead")
print("Your network does not support IPv6")
return False


Expand Down

0 comments on commit ba5ab3d

Please sign in to comment.