aboutsummaryrefslogtreecommitdiffstats
path: root/hypervideo_dl/extractor/drtv.py
diff options
context:
space:
mode:
Diffstat (limited to 'hypervideo_dl/extractor/drtv.py')
-rw-r--r--hypervideo_dl/extractor/drtv.py166
1 files changed, 141 insertions, 25 deletions
diff --git a/hypervideo_dl/extractor/drtv.py b/hypervideo_dl/extractor/drtv.py
index 128f439..6c381aa 100644
--- a/hypervideo_dl/extractor/drtv.py
+++ b/hypervideo_dl/extractor/drtv.py
@@ -2,28 +2,29 @@ import binascii
import hashlib
import re
-
from .common import InfoExtractor
from ..aes import aes_cbc_decrypt_bytes, unpad_pkcs7
from ..compat import compat_urllib_parse_unquote
from ..utils import (
ExtractorError,
- int_or_none,
float_or_none,
+ int_or_none,
mimetype2ext,
str_or_none,
- try_get,
+ traverse_obj,
unified_timestamp,
update_url_query,
url_or_none,
)
+SERIES_API = 'https://production-cdn.dr-massive.com/api/page?device=web_browser&item_detail_expand=all&lang=da&max_list_prefetch=3&path=%s'
+
class DRTVIE(InfoExtractor):
_VALID_URL = r'''(?x)
https?://
(?:
- (?:www\.)?dr\.dk/(?:tv/se|nyheder|(?:radio|lyd)(?:/ondemand)?)/(?:[^/]+/)*|
+ (?:www\.)?dr\.dk/(?:tv/se|nyheder|(?P<radio>radio|lyd)(?:/ondemand)?)/(?:[^/]+/)*|
(?:www\.)?(?:dr\.dk|dr-massive\.com)/drtv/(?:se|episode|program)/
)
(?P<id>[\da-z_-]+)
@@ -78,7 +79,7 @@ class DRTVIE(InfoExtractor):
'description': 'md5:8c66dcbc1669bbc6f873879880f37f2a',
'timestamp': 1546628400,
'upload_date': '20190104',
- 'duration': 3504.618,
+ 'duration': 3504.619,
'formats': 'mincount:20',
'release_year': 2017,
'season_id': 'urn:dr:mu:bundle:5afc03ad6187a4065ca5fd35',
@@ -99,14 +100,16 @@ class DRTVIE(InfoExtractor):
'ext': 'mp4',
'title': 'Bonderøven 2019 (1:8)',
'description': 'md5:b6dcfe9b6f0bea6703e9a0092739a5bd',
- 'timestamp': 1603188600,
- 'upload_date': '20201020',
+ 'timestamp': 1654856100,
+ 'upload_date': '20220610',
'duration': 2576.6,
'season': 'Bonderøven 2019',
'season_id': 'urn:dr:mu:bundle:5c201667a11fa01ca4528ce5',
'release_year': 2019,
'season_number': 2019,
- 'series': 'Frank & Kastaniegaarden'
+ 'series': 'Frank & Kastaniegaarden',
+ 'episode_number': 1,
+ 'episode': 'Episode 1',
},
'params': {
'skip_download': True,
@@ -138,16 +141,32 @@ class DRTVIE(InfoExtractor):
'params': {
'skip_download': True,
},
+ 'skip': 'this video has been removed',
+ }, {
+ 'url': 'https://www.dr.dk/lyd/p4kbh/regionale-nyheder-kh4/regionale-nyheder-2023-03-14-10-30-9',
+ 'info_dict': {
+ 'ext': 'mp4',
+ 'id': '14802310112',
+ 'timestamp': 1678786200,
+ 'duration': 120.043,
+ 'season_id': 'urn:dr:mu:bundle:63a4f7c87140143504b6710f',
+ 'series': 'P4 København regionale nyheder',
+ 'upload_date': '20230314',
+ 'release_year': 0,
+ 'description': 'Hør seneste regionale nyheder fra P4 København.',
+ 'season': 'Regionale nyheder',
+ 'title': 'Regionale nyheder',
+ },
}]
def _real_extract(self, url):
- video_id = self._match_id(url)
+ raw_video_id, is_radio_url = self._match_valid_url(url).group('id', 'radio')
- webpage = self._download_webpage(url, video_id)
+ webpage = self._download_webpage(url, raw_video_id)
if '>Programmet er ikke længere tilgængeligt' in webpage:
raise ExtractorError(
- 'Video %s is not available' % video_id, expected=True)
+ 'Video %s is not available' % raw_video_id, expected=True)
video_id = self._search_regex(
(r'data-(?:material-identifier|episode-slug)="([^"]+)"',
@@ -168,20 +187,27 @@ class DRTVIE(InfoExtractor):
programcard_url = '%s/%s' % (_PROGRAMCARD_BASE, video_id)
else:
programcard_url = _PROGRAMCARD_BASE
- page = self._parse_json(
- self._search_regex(
- r'data\s*=\s*({.+?})\s*(?:;|</script)', webpage,
- 'data'), '1')['cache']['page']
- page = page[list(page.keys())[0]]
- item = try_get(
- page, (lambda x: x['item'], lambda x: x['entries'][0]['item']),
- dict)
- video_id = item['customId'].split(':')[-1]
+ if is_radio_url:
+ video_id = self._search_nextjs_data(
+ webpage, raw_video_id)['props']['pageProps']['episode']['productionNumber']
+ else:
+ json_data = self._search_json(
+ r'window\.__data\s*=', webpage, 'data', raw_video_id)
+ video_id = traverse_obj(json_data, (
+ 'cache', 'page', ..., (None, ('entries', 0)), 'item', 'customId',
+ {lambda x: x.split(':')[-1]}), get_all=False)
+ if not video_id:
+ raise ExtractorError('Unable to extract video id')
query['productionnumber'] = video_id
data = self._download_json(
programcard_url, video_id, 'Downloading video JSON', query=query)
+ supplementary_data = {}
+ if re.search(r'_\d+$', raw_video_id):
+ supplementary_data = self._download_json(
+ SERIES_API % f'/episode/{raw_video_id}', raw_video_id, fatal=False) or {}
+
title = str_or_none(data.get('Title')) or re.sub(
r'\s*\|\s*(?:TV\s*\|\s*DR|DRTV)$', '',
self._og_search_title(webpage))
@@ -262,10 +288,11 @@ class DRTVIE(InfoExtractor):
f['vcodec'] = 'none'
formats.extend(f4m_formats)
elif target == 'HLS':
- formats.extend(self._extract_m3u8_formats(
+ fmts, subs = self._extract_m3u8_formats_and_subtitles(
uri, video_id, 'mp4', entry_protocol='m3u8_native',
- quality=preference, m3u8_id=format_id,
- fatal=False))
+ quality=preference, m3u8_id=format_id, fatal=False)
+ formats.extend(fmts)
+ self._merge_subtitles(subs, target=subtitles)
else:
bitrate = link.get('Bitrate')
if bitrate:
@@ -313,8 +340,8 @@ class DRTVIE(InfoExtractor):
'season': str_or_none(data.get('SeasonTitle')),
'season_number': int_or_none(data.get('SeasonNumber')),
'season_id': str_or_none(data.get('SeasonUrn')),
- 'episode': str_or_none(data.get('EpisodeTitle')),
- 'episode_number': int_or_none(data.get('EpisodeNumber')),
+ 'episode': traverse_obj(supplementary_data, ('entries', 0, 'item', 'contextualTitle')) or str_or_none(data.get('EpisodeTitle')),
+ 'episode_number': traverse_obj(supplementary_data, ('entries', 0, 'item', 'episodeNumber')) or int_or_none(data.get('EpisodeNumber')),
'release_year': int_or_none(data.get('ProductionYear')),
}
@@ -372,3 +399,92 @@ class DRTVLiveIE(InfoExtractor):
'formats': formats,
'is_live': True,
}
+
+
+class DRTVSeasonIE(InfoExtractor):
+ IE_NAME = 'drtv:season'
+ _VALID_URL = r'https?://(?:www\.)?(?:dr\.dk|dr-massive\.com)/drtv/saeson/(?P<display_id>[\w-]+)_(?P<id>\d+)'
+ _GEO_COUNTRIES = ['DK']
+ _TESTS = [{
+ 'url': 'https://www.dr.dk/drtv/saeson/frank-and-kastaniegaarden_9008',
+ 'info_dict': {
+ 'id': '9008',
+ 'display_id': 'frank-and-kastaniegaarden',
+ 'title': 'Frank & Kastaniegaarden',
+ 'series': 'Frank & Kastaniegaarden',
+ },
+ 'playlist_mincount': 8
+ }, {
+ 'url': 'https://www.dr.dk/drtv/saeson/frank-and-kastaniegaarden_8761',
+ 'info_dict': {
+ 'id': '8761',
+ 'display_id': 'frank-and-kastaniegaarden',
+ 'title': 'Frank & Kastaniegaarden',
+ 'series': 'Frank & Kastaniegaarden',
+ },
+ 'playlist_mincount': 19
+ }]
+
+ def _real_extract(self, url):
+ display_id, season_id = self._match_valid_url(url).group('display_id', 'id')
+ data = self._download_json(SERIES_API % f'/saeson/{display_id}_{season_id}', display_id)
+
+ entries = [{
+ '_type': 'url',
+ 'url': f'https://www.dr.dk/drtv{episode["path"]}',
+ 'ie_key': DRTVIE.ie_key(),
+ 'title': episode.get('title'),
+ 'episode': episode.get('episodeName'),
+ 'description': episode.get('shortDescription'),
+ 'series': traverse_obj(data, ('entries', 0, 'item', 'title')),
+ 'season_number': traverse_obj(data, ('entries', 0, 'item', 'seasonNumber')),
+ 'episode_number': episode.get('episodeNumber'),
+ } for episode in traverse_obj(data, ('entries', 0, 'item', 'episodes', 'items'))]
+
+ return {
+ '_type': 'playlist',
+ 'id': season_id,
+ 'display_id': display_id,
+ 'title': traverse_obj(data, ('entries', 0, 'item', 'title')),
+ 'series': traverse_obj(data, ('entries', 0, 'item', 'title')),
+ 'entries': entries,
+ 'season_number': traverse_obj(data, ('entries', 0, 'item', 'seasonNumber'))
+ }
+
+
+class DRTVSeriesIE(InfoExtractor):
+ IE_NAME = 'drtv:series'
+ _VALID_URL = r'https?://(?:www\.)?(?:dr\.dk|dr-massive\.com)/drtv/serie/(?P<display_id>[\w-]+)_(?P<id>\d+)'
+ _GEO_COUNTRIES = ['DK']
+ _TESTS = [{
+ 'url': 'https://www.dr.dk/drtv/serie/frank-and-kastaniegaarden_6954',
+ 'info_dict': {
+ 'id': '6954',
+ 'display_id': 'frank-and-kastaniegaarden',
+ 'title': 'Frank & Kastaniegaarden',
+ 'series': 'Frank & Kastaniegaarden',
+ },
+ 'playlist_mincount': 15
+ }]
+
+ def _real_extract(self, url):
+ display_id, series_id = self._match_valid_url(url).group('display_id', 'id')
+ data = self._download_json(SERIES_API % f'/serie/{display_id}_{series_id}', display_id)
+
+ entries = [{
+ '_type': 'url',
+ 'url': f'https://www.dr.dk/drtv{season.get("path")}',
+ 'ie_key': DRTVSeasonIE.ie_key(),
+ 'title': season.get('title'),
+ 'series': traverse_obj(data, ('entries', 0, 'item', 'title')),
+ 'season_number': traverse_obj(data, ('entries', 0, 'item', 'seasonNumber'))
+ } for season in traverse_obj(data, ('entries', 0, 'item', 'show', 'seasons', 'items'))]
+
+ return {
+ '_type': 'playlist',
+ 'id': series_id,
+ 'display_id': display_id,
+ 'title': traverse_obj(data, ('entries', 0, 'item', 'title')),
+ 'series': traverse_obj(data, ('entries', 0, 'item', 'title')),
+ 'entries': entries
+ }