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