Skip to content

Commit

Permalink
Merge pull request #327 from Guovin/master
Browse files Browse the repository at this point in the history
release
  • Loading branch information
Guovin authored Sep 19, 2024
2 parents b6412ca + 6936b5b commit b557270
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
build
result_new.log
result_new.log
multicast_region_result.json
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Binary file modified updates/fofa/fofa_hotel_region_result.pkl
Binary file not shown.
Binary file modified updates/fofa/fofa_multicast_region_result.pkl
Binary file not shown.
20 changes: 16 additions & 4 deletions utils/channel.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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": "+",
Expand Down Expand Up @@ -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
Expand All @@ -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 (
Expand All @@ -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.")
Expand All @@ -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,
)
)
Expand Down
20 changes: 16 additions & 4 deletions utils/speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
"""
Expand All @@ -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")
Expand All @@ -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
)
)
Expand Down
16 changes: 16 additions & 0 deletions utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.4.4",
"version": "1.4.5",
"name": "电视直播源更新工具"
}

0 comments on commit b557270

Please sign in to comment.