[cleanup] Make more playlist entries lazy (#11763)
[yt-dlp.git] / yt_dlp / extractor / eitb.py
blob18b802eb1550eee158c51f827328ea4c6adc2b2b
1 from .common import InfoExtractor
2 from ..networking import Request
3 from ..utils import (
4 float_or_none,
5 int_or_none,
6 join_nonempty,
7 parse_iso8601,
11 class EitbIE(InfoExtractor):
12 IE_NAME = 'eitb.tv'
13 _VALID_URL = r'https?://(?:www\.)?eitb\.tv/(?:eu/bideoa|es/video)/[^/]+/\d+/(?P<id>\d+)'
15 _TEST = {
16 'url': 'http://www.eitb.tv/es/video/60-minutos-60-minutos-2013-2014/4104995148001/4090227752001/lasa-y-zabala-30-anos/',
17 'md5': 'edf4436247185adee3ea18ce64c47998',
18 'info_dict': {
19 'id': '4090227752001',
20 'ext': 'mp4',
21 'title': '60 minutos (Lasa y Zabala, 30 aƱos)',
22 'description': 'Programa de reportajes de actualidad.',
23 'duration': 3996.76,
24 'timestamp': 1381789200,
25 'upload_date': '20131014',
26 'tags': list,
30 def _real_extract(self, url):
31 video_id = self._match_id(url)
33 video = self._download_json(
34 f'http://mam.eitb.eus/mam/REST/ServiceMultiweb/Video/MULTIWEBTV/{video_id}/',
35 video_id, 'Downloading video JSON')
37 media = video['web_media'][0]
39 formats = []
40 for rendition in media['RENDITIONS']:
41 video_url = rendition.get('PMD_URL')
42 if not video_url:
43 continue
44 tbr = float_or_none(rendition.get('ENCODING_RATE'), 1000)
45 formats.append({
46 'url': rendition['PMD_URL'],
47 'format_id': join_nonempty('http', int_or_none(tbr)),
48 'width': int_or_none(rendition.get('FRAME_WIDTH')),
49 'height': int_or_none(rendition.get('FRAME_HEIGHT')),
50 'tbr': tbr,
53 hls_url = media.get('HLS_SURL')
54 if hls_url:
55 request = Request(
56 'http://mam.eitb.eus/mam/REST/ServiceMultiweb/DomainRestrictedSecurity/TokenAuth/',
57 headers={'Referer': url})
58 token_data = self._download_json(
59 request, video_id, 'Downloading auth token', fatal=False)
60 if token_data:
61 token = token_data.get('token')
62 if token:
63 formats.extend(self._extract_m3u8_formats(
64 f'{hls_url}?hdnts={token}', video_id, m3u8_id='hls', fatal=False))
66 hds_url = media.get('HDS_SURL')
67 if hds_url:
68 formats.extend(self._extract_f4m_formats(
69 '{}?hdcore=3.7.0'.format(hds_url.replace('euskalsvod', 'euskalvod')),
70 video_id, f4m_id='hds', fatal=False))
72 return {
73 'id': video_id,
74 'title': media.get('NAME_ES') or media.get('name') or media['NAME_EU'],
75 'description': media.get('SHORT_DESC_ES') or video.get('desc_group') or media.get('SHORT_DESC_EU'),
76 'thumbnail': media.get('STILL_URL') or media.get('THUMBNAIL_URL'),
77 'duration': float_or_none(media.get('LENGTH'), 1000),
78 'timestamp': parse_iso8601(media.get('BROADCST_DATE'), ' '),
79 'tags': media.get('TAGS'),
80 'formats': formats,