Skip to content

Commit

Permalink
Merge pull request #782 from Guovin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Guovin authored Jan 2, 2025
2 parents 43c2511 + 4bd8865 commit 1826ef2
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ https://cdn.jsdelivr.net/gh/Guovin/iptv-api@gd/source.json
| ipv6_num | 结果中偏好的 IPv6 接口数量 | 5 |
| ipv6_support | 强制认为当前网络支持IPv6,跳过检测 | False |
| ipv_type | 生成结果中接口的协议类型,可选值:ipv4、ipv6、全部、all | 全部 |
| ipv_type_prefer | 接口协议类型偏好,优先将该类型的接口排在结果前面,可选值:IPv4、IPv6、自动、auto | 自动 |
| ipv_type_prefer | 接口协议类型偏好,优先将该类型的接口排在结果前面,可选值:ipv4、ipv6、自动、auto | 自动 |
| min_resolution | 接口最小分辨率,需要开启 open_filter_resolution 才能生效 | 1920x1080 |
| min_speed | 接口最小速率(单位M/s),需要开启 open_filter_speed 才能生效 | 0.2 |
| multicast_num | 结果中偏好的组播源接口数量 | 10 |
Expand Down
2 changes: 1 addition & 1 deletion README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ https://cdn.jsdelivr.net/gh/Guovin/iptv-api@gd/source.json
| ipv6_num | The preferred number of IPv6 interfaces in the result | 5 |
| ipv6_support | It is forced to consider that the current network supports IPv6 and skip the check | False |
| ipv_type | The protocol type of interface in the generated result, optional values: ipv4, ipv6, all | all |
| ipv_type_prefer | Interface protocol type preference, prioritize interfaces of this type in the results, optional values: IPv4, IPv6, auto | auto |
| ipv_type_prefer | Interface protocol type preference, prioritize interfaces of this type in the results, optional values: ipv4, ipv6, auto | auto |
| min_resolution | Minimum interface resolution, requires enabling open_filter_resolution to take effect | 1920x1080 |
| min_speed | Minimum interface speed (M/s), requires enabling open_filter_speed to take effect | 0.2 |
| multicast_num | The number of preferred multicast source interfaces in the results | 10 |
Expand Down
2 changes: 1 addition & 1 deletion config/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ipv6_num = 5
ipv6_support = False
# 生成结果中接口的协议类型,可选值:ipv4、ipv6、全部、all | Protocol type of the interface in the generated result, optional values: ipv4, ipv6, 全部, all
ipv_type = 全部
# 接口协议类型偏好,优先将该类型的接口排在结果前面,可选值:IPv4、IPv6、自动、auto | Interface protocol type preference, prefer to put this type of interface in front of the result, optional values: IPv4, IPv6, 自动, auto
# 接口协议类型偏好,优先将该类型的接口排在结果前面,可选值:ipv4、ipv6、自动、auto | Interface protocol type preference, prefer to put this type of interface in front of the result, optional values: ipv4, ipv6, 自动, auto
ipv_type_prefer = 自动
# 接口最小分辨率,需要开启 open_filter_resolution 才能生效 | Minimum resolution of the interface, need to enable open_filter_resolution to take effect
min_resolution = 1920x1080
Expand Down
2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
| ipv6_num | 结果中偏好的 IPv6 接口数量 | 5 |
| ipv6_support | 强制认为当前网络支持IPv6,跳过检测 | False |
| ipv_type | 生成结果中接口的协议类型,可选值:ipv4、ipv6、全部、all | 全部 |
| ipv_type_prefer | 接口协议类型偏好,优先将该类型的接口排在结果前面,可选值:IPv4、IPv6、自动、auto | 自动 |
| ipv_type_prefer | 接口协议类型偏好,优先将该类型的接口排在结果前面,可选值:ipv4、ipv6、自动、auto | 自动 |
| min_resolution | 接口最小分辨率,需要开启 open_filter_resolution 才能生效 | 1920x1080 |
| min_speed | 接口最小速率(单位M/s),需要开启 open_filter_speed 才能生效 | 0.2 |
| multicast_num | 结果中偏好的组播源接口数量 | 10 |
Expand Down
2 changes: 1 addition & 1 deletion docs/config_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
| ipv6_num | The preferred number of IPv6 interfaces in the result | 5 |
| ipv6_support | It is forced to consider that the current network supports IPv6 and skip the check | False |
| ipv_type | The protocol type of interface in the generated result, optional values: ipv4, ipv6, all | all |
| ipv_type_prefer | Interface protocol type preference, prioritize interfaces of this type in the results, optional values: IPv4, IPv6, auto | auto |
| ipv_type_prefer | Interface protocol type preference, prioritize interfaces of this type in the results, optional values: ipv4, ipv6, auto | auto |
| min_resolution | Minimum interface resolution, requires enabling open_filter_resolution to take effect | 1920x1080 |
| min_speed | Minimum interface speed (M/s), requires enabling open_filter_speed to take effect | 0.2 |
| multicast_num | The number of preferred multicast source interfaces in the results | 10 |
Expand Down
6 changes: 5 additions & 1 deletion utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@

log_path = os.path.join(output_path, "log.log")

url_pattern = r"((https?):\/\/)?(\[[0-9a-fA-F:]+\]|([\w-]+\.)+[\w-]+)(:[0-9]{1,5})?(\/[^\s]*)?(\$[^\s]+)?"
url_domain_pattern = r"((https?|rtmp)://)?(\[[0-9a-fA-F:]+]|([\w-]+\.)+[\w-]+)(:[0-9]{1,5})?"

url_pattern = url_domain_pattern + r"(/\S*)?(\$\S+)?"

rtmp_url_pattern = r"^rtmp://.*$"

rtp_pattern = r"^([^,,]+)(?:[,,])?(rtp://.*)$"

Expand Down
6 changes: 6 additions & 0 deletions utils/speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from aiohttp import ClientSession, TCPConnector
from multidict import CIMultiDictProxy

import utils.constants as constants
from utils.config import config
from utils.tools import is_ipv6, remove_cache_info, get_resolution_value

Expand Down Expand Up @@ -289,6 +290,11 @@ async def get_speed(url, ipv6_proxy=None, filter_resolution=config.open_filter_r
data['speed'] = float("inf")
data['delay'] = float("-inf")
data['resolution'] = "1920x1080"
elif re.match(constants.rtmp_url_pattern, url) is not None:
start_time = time()
data['resolution'] = await get_resolution_ffprobe(url, timeout)
data['delay'] = int(round((time() - start_time) * 1000))
data['speed'] = float("inf") if data['resolution'] is not None else 0
else:
data.update(await get_speed_m3u8(url, filter_resolution, timeout))
if cache_key and cache_key not in cache:
Expand Down
6 changes: 3 additions & 3 deletions utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,16 +443,16 @@ def process_nested_dict(data, seen, flag=None, force_str=None):
data[key] = remove_duplicates_from_tuple_list(value, seen, flag, force_str)


url_domain_pattern = re.compile(
r"\b((https?):\/\/)?(\[[0-9a-fA-F:]+\]|([\w-]+\.)+[\w-]+)(:[0-9]{1,5})?\b"
url_domain_compile = re.compile(
constants.url_domain_pattern
)


def get_url_domain(url):
"""
Get the url domain
"""
matcher = url_domain_pattern.search(url)
matcher = url_domain_compile.search(url)
if matcher:
return matcher.group()
return None
Expand Down

0 comments on commit 1826ef2

Please sign in to comment.