Skip to content

Commit

Permalink
[common] remove unwanted query params from unsigned akamai manifest URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
remitamine committed Dec 19, 2020
1 parent 942b8ca commit 22feed0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 8 additions & 1 deletion youtube_dl/extractor/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2605,6 +2605,13 @@ def _media_formats(src, cur_media_type, type_info={}):
return entries

def _extract_akamai_formats(self, manifest_url, video_id, hosts={}):
signed = 'hdnea=' in manifest_url
if not signed:
# https://learn.akamai.com/en-us/webhelp/media-services-on-demand/stream-packaging-user-guide/GUID-BE6C0F73-1E06-483B-B0EA-57984B91B7F9.html
manifest_url = re.sub(
r'(?:b=[\d,-]+|(?:__a__|attributes)=off|__b__=\d+)&?',
'', manifest_url).strip('?')

formats = []

hdcore_sign = 'hdcore=3.7.0'
Expand All @@ -2630,7 +2637,7 @@ def _extract_akamai_formats(self, manifest_url, video_id, hosts={}):
formats.extend(m3u8_formats)

http_host = hosts.get('http')
if http_host and m3u8_formats and 'hdnea=' not in m3u8_url:
if http_host and m3u8_formats and not signed:
REPL_REGEX = r'https?://[^/]+/i/([^,]+),([^/]+),([^/]+)\.csmil/.+'
qualities = re.match(REPL_REGEX, m3u8_url).group(2).split(',')
qualities_length = len(qualities)
Expand Down
3 changes: 1 addition & 2 deletions youtube_dl/extractor/nrk.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class NRKBaseIE(InfoExtractor):

def _extract_nrk_formats(self, asset_url, video_id):
if re.match(r'https?://[^/]+\.akamaihd\.net/i/', asset_url):
return self._extract_akamai_formats(
re.sub(r'(?:b=\d+-\d+|__a__=off)&?', '', asset_url), video_id)
return self._extract_akamai_formats(asset_url, video_id)
asset_url = re.sub(r'(?:bw_(?:low|high)=\d+|no_audio_only)&?', '', asset_url)
formats = self._extract_m3u8_formats(
asset_url, video_id, 'mp4', 'm3u8_native', fatal=False)
Expand Down

0 comments on commit 22feed0

Please sign in to comment.