Skip to content

Commit

Permalink
feat:support rtmp(#780)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guovin committed Jan 2, 2025
1 parent 8d8d751 commit 09e04ae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
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 09e04ae

Please sign in to comment.