use update_url instead of urllib.parse

This commit is contained in:
c0d3d3v 2024-04-18 18:55:00 +02:00
parent 5ca5b56cfc
commit 333eb58c77
No known key found for this signature in database
GPG key ID: 9C0916B73C826BF6

View file

@ -1,13 +1,7 @@
import re import re
from urllib.parse import urlparse, urlunparse
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import determine_ext, float_or_none, traverse_obj, update_url
determine_ext,
float_or_none,
traverse_obj,
)
class Echo360IE(InfoExtractor): class Echo360IE(InfoExtractor):
@ -44,13 +38,8 @@ def _call_api(self, host, video_id, media_id, session_token, **kwargs):
f'https://{host}/api/ui/echoplayer/public-links/{video_id}/media/{media_id}/player-properties', f'https://{host}/api/ui/echoplayer/public-links/{video_id}/media/{media_id}/player-properties',
video_id, headers={'Authorization': f'Bearer {session_token}'}, **kwargs) video_id, headers={'Authorization': f'Bearer {session_token}'}, **kwargs)
def _replace_url_query(self, url, query_string):
if query_string is not None:
return urlunparse(urlparse(url)._replace(query=query_string))
return url
def _get_query_string(self, uri, query_strings): def _get_query_string(self, uri, query_strings):
uri_base = urlparse(uri)._replace(query='', fragment='').geturl() uri_base = update_url(uri, query=None, fragment=None)
for query_string in query_strings: for query_string in query_strings:
try: try:
if re.match(query_string['uriPattern'], uri_base): if re.match(query_string['uriPattern'], uri_base):
@ -68,7 +57,7 @@ def _parse_mediapackage(self, video):
href = track.get('uri') href = track.get('uri')
if href is None: if href is None:
continue continue
href = self._replace_url_query(href, self._get_query_string(href, query_strings)) href = update_url(href, query=self._get_query_string(href, query_strings))
if track.get('isHls') or determine_ext(href, None) == 'm3u8': if track.get('isHls') or determine_ext(href, None) == 'm3u8':
hls_formats = self._extract_m3u8_formats( hls_formats = self._extract_m3u8_formats(
href, video_id, live=track.get('isLive'), m3u8_id='hls', href, video_id, live=track.get('isLive'), m3u8_id='hls',
@ -78,7 +67,7 @@ def _parse_mediapackage(self, video):
for hls_format in hls_formats: for hls_format in hls_formats:
query_string = self._get_query_string(hls_format['url'], query_strings) query_string = self._get_query_string(hls_format['url'], query_strings)
hls_format['extra_param_to_segment_url'] = query_string hls_format['extra_param_to_segment_url'] = query_string
hls_format['url'] = self._replace_url_query(hls_format['url'], query_string) hls_format['url'] = update_url(hls_format['url'], query=query_string)
formats.extend(hls_formats) formats.extend(hls_formats)