diff --git a/.gitignore b/.gitignore index 9315b48695..c3bdaa2006 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ dist build -result_new.log \ No newline at end of file +result_new.log +multicast_region_result.json \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 58f3e63da2..7fa6cea0e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # 更新日志(Changelog) +## v1.4.5 + +### 2024/9/19 + +- 修复 IPv6 接口测速(#325) + +- Fix IPv6 Interface Speed Test (#325) + ## v1.4.4 ### 2024/9/14 diff --git a/updates/fofa/fofa_hotel_region_result.pkl b/updates/fofa/fofa_hotel_region_result.pkl index 5c70965aab..cb665c5924 100644 Binary files a/updates/fofa/fofa_hotel_region_result.pkl and b/updates/fofa/fofa_hotel_region_result.pkl differ diff --git a/updates/fofa/fofa_multicast_region_result.pkl b/updates/fofa/fofa_multicast_region_result.pkl index 642ee562bb..a94320a32b 100644 Binary files a/updates/fofa/fofa_multicast_region_result.pkl and b/updates/fofa/fofa_multicast_region_result.pkl differ diff --git a/utils/channel.py b/utils/channel.py index 74535cbb81..cf46714164 100644 --- a/utils/channel.py +++ b/utils/channel.py @@ -1,5 +1,9 @@ from utils.config import config, resource_path -from utils.tools import check_url_by_patterns, get_total_urls_from_info_list +from utils.tools import ( + check_url_by_patterns, + get_total_urls_from_info_list, + check_ipv6_support, +) from utils.speed import sort_urls_by_speed_and_resolution, is_ffmpeg_installed import os from collections import defaultdict @@ -105,7 +109,7 @@ def format_channel_name(name): return name cc = OpenCC("t2s") name = cc.convert(name) - sub_pattern = r"-|_|\((.*?)\)|\((.*?)\)|\[(.*?)\]| |频道|普清|标清|高清|HD|hd|超清|超高|超高清|中央|央视|台" + sub_pattern = r"-|_|\((.*?)\)|\((.*?)\)|\[(.*?)\]| |||频道|普清|标清|高清|HD|hd|超清|超高|超高清|中央|央视|台" name = re.sub(sub_pattern, "", name) replace_dict = { "plus": "+", @@ -596,7 +600,7 @@ def append_all_method_data_keep_all( async def sort_channel_list( - cate, name, info_list, semaphore, ffmpeg=False, callback=None + cate, name, info_list, semaphore, ffmpeg=False, ipv6_proxy=None, callback=None ): """ Sort the channel list @@ -606,7 +610,7 @@ async def sort_channel_list( try: if info_list: sorted_data = await sort_urls_by_speed_and_resolution( - info_list, ffmpeg=ffmpeg, callback=callback + info_list, ffmpeg=ffmpeg, ipv6_proxy=ipv6_proxy, callback=callback ) if sorted_data: for ( @@ -632,6 +636,13 @@ async def process_sort_channel_list(data, callback=None): Processs the sort channel list """ open_ffmpeg = config.getboolean("Settings", "open_ffmpeg") + ipv_type = config.get("Settings", "ipv_type").lower() + open_ipv6 = "ipv6" in ipv_type or "all" in ipv_type + ipv6_proxy = None + if open_ipv6: + ipv6_proxy = ( + None if check_ipv6_support() 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.") @@ -645,6 +656,7 @@ async def process_sort_channel_list(data, callback=None): info_list, semaphore, ffmpeg=is_ffmpeg, + ipv6_proxy=ipv6_proxy, callback=callback, ) ) diff --git a/utils/speed.py b/utils/speed.py index 310ec3056e..cc53dc2386 100644 --- a/utils/speed.py +++ b/utils/speed.py @@ -4,6 +4,7 @@ import re from urllib.parse import quote from utils.config import config +from utils.tools import is_ipv6 import subprocess timeout = 15 @@ -115,7 +116,9 @@ async def check_stream_speed(url_info): speed_cache = {} -async def get_speed_by_info(url_info, ffmpeg, semaphore, callback=None): +async def get_speed_by_info( + url_info, ffmpeg, semaphore, ipv6_proxy=None, callback=None +): """ Get the info with speed """ @@ -133,11 +136,16 @@ async def get_speed_by_info(url_info, ffmpeg, semaphore, callback=None): speed = speed_cache[cache_key] return (tuple(url_info), speed) if speed != float("inf") else float("inf") try: - if ".m3u8" not in url and ffmpeg: + url_is_ipv6 = is_ipv6(url) + if ".m3u8" not in url and ffmpeg and not url_is_ipv6: speed = await check_stream_speed(url_info) url_speed = speed[1] if speed != float("inf") else float("inf") else: + if ipv6_proxy and url_is_ipv6: + url = ipv6_proxy + url url_speed = await get_speed(url) + if url_is_ipv6: + url_info[0] = url_info[0] + "$IPv6" speed = ( (tuple(url_info), url_speed) if url_speed != float("inf") @@ -153,14 +161,18 @@ async def get_speed_by_info(url_info, ffmpeg, semaphore, callback=None): callback() -async def sort_urls_by_speed_and_resolution(data, ffmpeg=False, callback=None): +async def sort_urls_by_speed_and_resolution( + data, ffmpeg=False, ipv6_proxy=None, callback=None +): """ Sort by speed and resolution """ semaphore = asyncio.Semaphore(10) response = await asyncio.gather( *( - get_speed_by_info(url_info, ffmpeg, semaphore, callback=callback) + get_speed_by_info( + url_info, ffmpeg, semaphore, ipv6_proxy=ipv6_proxy, callback=callback + ) for url_info in data ) ) diff --git a/utils/tools.py b/utils/tools.py index 0b8795b0dc..071fbfc577 100644 --- a/utils/tools.py +++ b/utils/tools.py @@ -141,6 +141,22 @@ def is_ipv6(url): return False +def check_ipv6_support(): + """ + Check if the system supports ipv6 and if the network can access an IPv6 address + """ + try: + test_socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) + test_socket.settimeout(2) + test_socket.connect(("2001:4860:4860::8888", 80)) + test_socket.close() + print("Your network supports IPv6") + return True + except (socket.timeout, OSError): + print("Your network does not support IPv6, using proxy") + return False + + def check_url_ipv_type(url): """ Check if the url is compatible with the ipv type in the config diff --git a/version.json b/version.json index dd1f77a18a..c83135afa9 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { - "version": "1.4.4", + "version": "1.4.5", "name": "电视直播源更新工具" } \ No newline at end of file