[common] remove unwanted query params from unsigned akamai manifest URLs
authorRemita Amine <remitamine@gmail.com>
Sat, 19 Dec 2020 19:08:44 +0000 (20:08 +0100)
committerRemita Amine <remitamine@gmail.com>
Sat, 19 Dec 2020 19:14:44 +0000 (20:14 +0100)
youtube_dl/extractor/common.py
youtube_dl/extractor/nrk.py

index 79138f34636b8a3e70eb533974cfe70eb9644220..d5faa0eb749a6c4e7667ac2661d9169e438d4c49 100644 (file)
@@ -2605,6 +2605,13 @@ class InfoExtractor(object):
         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'
@@ -2630,7 +2637,7 @@ class InfoExtractor(object):
         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)
index fdf2d74079e1b3dfd48783367168e095e8c9b6ce..b545f291b29fe63fc50fff73fb5411acb5ed747a 100644 (file)
@@ -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)