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