]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/drtv.py
[extractor/oneplace] Add OnePlacePodcast extractor (#5549)
[yt-dlp.git] / yt_dlp / extractor / drtv.py
index 7bb15f8d4cdba5e6400b8c5093c1f49849545962..128f4391452d27fd614ecfb86966e49d15c54d06 100644 (file)
@@ -1,19 +1,14 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
 import binascii
 import hashlib
 import re
 
 
 from .common import InfoExtractor
-from ..aes import aes_cbc_decrypt
+from ..aes import aes_cbc_decrypt_bytes, unpad_pkcs7
 from ..compat import compat_urllib_parse_unquote
 from ..utils import (
-    bytes_to_intlist,
     ExtractorError,
     int_or_none,
-    intlist_to_bytes,
     float_or_none,
     mimetype2ext,
     str_or_none,
@@ -28,7 +23,7 @@ class DRTVIE(InfoExtractor):
     _VALID_URL = r'''(?x)
                     https?://
                         (?:
-                            (?:www\.)?dr\.dk/(?:tv/se|nyheder|radio(?:/ondemand)?)/(?:[^/]+/)*|
+                            (?:www\.)?dr\.dk/(?:tv/se|nyheder|(?:radio|lyd)(?:/ondemand)?)/(?:[^/]+/)*|
                             (?:www\.)?(?:dr\.dk|dr-massive\.com)/drtv/(?:se|episode|program)/
                         )
                         (?P<id>[\da-z_-]+)
@@ -56,6 +51,7 @@ class DRTVIE(InfoExtractor):
             'release_year': 2016,
         },
         'expected_warnings': ['Unable to download f4m manifest'],
+        'skip': 'this video has been removed',
     }, {
         # embed
         'url': 'https://www.dr.dk/nyheder/indland/live-christianias-rydning-af-pusher-street-er-i-gang',
@@ -76,31 +72,41 @@ class DRTVIE(InfoExtractor):
         # with SignLanguage formats
         'url': 'https://www.dr.dk/tv/se/historien-om-danmark/-/historien-om-danmark-stenalder',
         'info_dict': {
-            'id': 'historien-om-danmark-stenalder',
+            'id': '00831690010',
             'ext': 'mp4',
             'title': 'Historien om Danmark: Stenalder',
             'description': 'md5:8c66dcbc1669bbc6f873879880f37f2a',
             'timestamp': 1546628400,
             'upload_date': '20190104',
-            'duration': 3502.56,
+            'duration': 3504.618,
             'formats': 'mincount:20',
+            'release_year': 2017,
+            'season_id': 'urn:dr:mu:bundle:5afc03ad6187a4065ca5fd35',
+            'season_number': 1,
+            'season': 'Historien om Danmark',
+            'series': 'Historien om Danmark',
         },
         'params': {
             'skip_download': True,
         },
     }, {
-        'url': 'https://www.dr.dk/radio/p4kbh/regionale-nyheder-kh4/p4-nyheder-2019-06-26-17-30-9',
+        'url': 'https://www.dr.dk/lyd/p4kbh/regionale-nyheder-kh4/p4-nyheder-2019-06-26-17-30-9',
         'only_matching': True,
     }, {
         'url': 'https://www.dr.dk/drtv/se/bonderoeven_71769',
         'info_dict': {
             'id': '00951930010',
             'ext': 'mp4',
-            'title': 'Bonderøven (1:8)',
-            'description': 'md5:3cf18fc0d3b205745d4505f896af8121',
-            'timestamp': 1546542000,
-            'upload_date': '20190103',
+            'title': 'Bonderøven 2019 (1:8)',
+            'description': 'md5:b6dcfe9b6f0bea6703e9a0092739a5bd',
+            'timestamp': 1603188600,
+            'upload_date': '20201020',
             'duration': 2576.6,
+            'season': 'Bonderøven 2019',
+            'season_id': 'urn:dr:mu:bundle:5c201667a11fa01ca4528ce5',
+            'release_year': 2019,
+            'season_number': 2019,
+            'series': 'Frank & Kastaniegaarden'
         },
         'params': {
             'skip_download': True,
@@ -114,6 +120,24 @@ class DRTVIE(InfoExtractor):
     }, {
         'url': 'https://www.dr.dk/drtv/program/jagten_220924',
         'only_matching': True,
+    }, {
+        'url': 'https://www.dr.dk/lyd/p4aarhus/regionale-nyheder-ar4/regionale-nyheder-2022-05-05-12-30-3',
+        'info_dict': {
+            'id': 'urn:dr:mu:programcard:6265cb2571401424d0360113',
+            'title': "Regionale nyheder",
+            'ext': 'mp4',
+            'duration': 120.043,
+            'series': 'P4 Østjylland regionale nyheder',
+            'timestamp': 1651746600,
+            'season': 'Regionale nyheder',
+            'release_year': 0,
+            'season_id': 'urn:dr:mu:bundle:61c26889539f0201586b73c5',
+            'description': '',
+            'upload_date': '20220505',
+        },
+        'params': {
+            'skip_download': True,
+        },
     }]
 
     def _real_extract(self, url):
@@ -191,13 +215,11 @@ def hex_to_bytes(hex):
         def decrypt_uri(e):
             n = int(e[2:10], 16)
             a = e[10 + n:]
-            data = bytes_to_intlist(hex_to_bytes(e[10:10 + n]))
-            key = bytes_to_intlist(hashlib.sha256(
-                ('%s:sRBzYNXBzkKgnjj8pGtkACch' % a).encode('utf-8')).digest())
-            iv = bytes_to_intlist(hex_to_bytes(a))
-            decrypted = aes_cbc_decrypt(data, key, iv)
-            return intlist_to_bytes(
-                decrypted[:-decrypted[-1]]).decode('utf-8').split('?')[0]
+            data = hex_to_bytes(e[10:10 + n])
+            key = hashlib.sha256(('%s:sRBzYNXBzkKgnjj8pGtkACch' % a).encode('utf-8')).digest()
+            iv = hex_to_bytes(a)
+            decrypted = unpad_pkcs7(aes_cbc_decrypt_bytes(data, key, iv))
+            return decrypted.decode('utf-8').split('?')[0]
 
         for asset in assets:
             kind = asset.get('Kind')
@@ -278,8 +300,6 @@ def decrypt_uri(e):
                 'Unfortunately, DR is not allowed to show this program outside Denmark.',
                 countries=self._GEO_COUNTRIES)
 
-        self._sort_formats(formats)
-
         return {
             'id': video_id,
             'title': title,
@@ -321,7 +341,7 @@ def _real_extract(self, url):
         channel_data = self._download_json(
             'https://www.dr.dk/mu-online/api/1.0/channel/' + channel_id,
             channel_id)
-        title = self._live_title(channel_data['Title'])
+        title = channel_data['Title']
 
         formats = []
         for streaming_server in channel_data.get('StreamingServers', []):
@@ -344,7 +364,6 @@ def _real_extract(self, url):
                         formats.extend(self._extract_f4m_formats(update_url_query(
                             '%s/%s' % (server, stream_path), {'hdcore': '3.7.0'}),
                             channel_id, f4m_id=link_type, fatal=False))
-        self._sort_formats(formats)
 
         return {
             'id': channel_id,