]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
375696b1 | 2 | from __future__ import unicode_literals |
3 | ||
375696b1 | 4 | from .common import InfoExtractor |
a9cd1691 RA |
5 | from ..utils import ( |
6 | parse_duration, | |
7 | int_or_none, | |
8 | determine_protocol, | |
9 | ) | |
375696b1 | 10 | |
11 | ||
12 | class SWRMediathekIE(InfoExtractor): | |
c7b32096 | 13 | _VALID_URL = r'https?://(?:www\.)?swrmediathek\.de/(?:content/)?player\.htm\?show=(?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})' |
375696b1 | 14 | |
15 | _TESTS = [{ | |
16 | 'url': 'http://swrmediathek.de/player.htm?show=849790d0-dab8-11e3-a953-0026b975f2e6', | |
7f739999 | 17 | 'md5': '8c5f6f0172753368547ca8413a7768ac', |
375696b1 | 18 | 'info_dict': { |
19 | 'id': '849790d0-dab8-11e3-a953-0026b975f2e6', | |
7f739999 | 20 | 'ext': 'mp4', |
375696b1 | 21 | 'title': 'SWR odysso', |
22 | 'description': 'md5:2012e31baad36162e97ce9eb3f157b8a', | |
ec85ded8 | 23 | 'thumbnail': r're:^http:.*\.jpg$', |
7f739999 S |
24 | 'duration': 2602, |
25 | 'upload_date': '20140515', | |
26 | 'uploader': 'SWR Fernsehen', | |
27 | 'uploader_id': '990030', | |
375696b1 | 28 | }, |
29 | }, { | |
30 | 'url': 'http://swrmediathek.de/player.htm?show=0e1a8510-ddf2-11e3-9be3-0026b975f2e6', | |
7f739999 | 31 | 'md5': 'b10ab854f912eecc5a6b55cd6fc1f545', |
375696b1 | 32 | 'info_dict': { |
33 | 'id': '0e1a8510-ddf2-11e3-9be3-0026b975f2e6', | |
7f739999 | 34 | 'ext': 'mp4', |
375696b1 | 35 | 'title': 'Nachtcafé - Alltagsdroge Alkohol - zwischen Sektempfang und Komasaufen', |
36 | 'description': 'md5:e0a3adc17e47db2c23aab9ebc36dbee2', | |
ec85ded8 | 37 | 'thumbnail': r're:http://.*\.jpg', |
7f739999 S |
38 | 'duration': 5305, |
39 | 'upload_date': '20140516', | |
40 | 'uploader': 'SWR Fernsehen', | |
41 | 'uploader_id': '990030', | |
375696b1 | 42 | }, |
a5eefc49 | 43 | 'skip': 'redirect to http://swrmediathek.de/index.htm?hinweis=swrlink', |
7f739999 S |
44 | }, { |
45 | 'url': 'http://swrmediathek.de/player.htm?show=bba23e10-cb93-11e3-bf7f-0026b975f2e6', | |
46 | 'md5': '4382e4ef2c9d7ce6852535fa867a0dd3', | |
47 | 'info_dict': { | |
48 | 'id': 'bba23e10-cb93-11e3-bf7f-0026b975f2e6', | |
49 | 'ext': 'mp3', | |
50 | 'title': 'Saša Stanišic: Vor dem Fest', | |
51 | 'description': 'md5:5b792387dc3fbb171eb709060654e8c9', | |
ec85ded8 | 52 | 'thumbnail': r're:http://.*\.jpg', |
7f739999 S |
53 | 'duration': 3366, |
54 | 'upload_date': '20140520', | |
55 | 'uploader': 'SWR 2', | |
56 | 'uploader_id': '284670', | |
a9cd1691 | 57 | }, |
a5eefc49 | 58 | 'skip': 'redirect to http://swrmediathek.de/index.htm?hinweis=swrlink', |
375696b1 | 59 | }] |
60 | ||
61 | def _real_extract(self, url): | |
a9cd1691 | 62 | video_id = self._match_id(url) |
375696b1 | 63 | |
7f739999 | 64 | video = self._download_json( |
a9cd1691 RA |
65 | 'http://swrmediathek.de/AjaxEntry?ekey=%s' % video_id, |
66 | video_id, 'Downloading video JSON') | |
375696b1 | 67 | |
7f739999 | 68 | attr = video['attr'] |
a9cd1691 RA |
69 | title = attr['entry_title'] |
70 | media_type = attr.get('entry_etype') | |
375696b1 | 71 | |
72 | formats = [] | |
a9cd1691 RA |
73 | for entry in video.get('sub', []): |
74 | if entry.get('name') != 'entry_media': | |
7f739999 S |
75 | continue |
76 | ||
a9cd1691 RA |
77 | entry_attr = entry.get('attr', {}) |
78 | f_url = entry_attr.get('val2') | |
79 | if not f_url: | |
80 | continue | |
81 | codec = entry_attr.get('val0') | |
82 | if codec == 'm3u8': | |
83 | formats.extend(self._extract_m3u8_formats( | |
84 | f_url, video_id, 'mp4', 'm3u8_native', | |
85 | m3u8_id='hls', fatal=False)) | |
86 | elif codec == 'f4m': | |
87 | formats.extend(self._extract_f4m_formats( | |
88 | f_url + '?hdcore=3.7.0', video_id, | |
89 | f4m_id='hds', fatal=False)) | |
90 | else: | |
91 | formats.append({ | |
92 | 'format_id': determine_protocol({'url': f_url}), | |
93 | 'url': f_url, | |
94 | 'quality': int_or_none(entry_attr.get('val1')), | |
95 | 'vcodec': codec if media_type == 'Video' else 'none', | |
96 | 'acodec': codec if media_type == 'Audio' else None, | |
7f739999 | 97 | }) |
375696b1 | 98 | self._sort_formats(formats) |
99 | ||
a9cd1691 RA |
100 | upload_date = None |
101 | entry_pdatet = attr.get('entry_pdatet') | |
102 | if entry_pdatet: | |
103 | upload_date = entry_pdatet[:-4] | |
104 | ||
375696b1 | 105 | return { |
106 | 'id': video_id, | |
a9cd1691 RA |
107 | 'title': title, |
108 | 'description': attr.get('entry_descl'), | |
109 | 'thumbnail': attr.get('entry_image_16_9'), | |
110 | 'duration': parse_duration(attr.get('entry_durat')), | |
111 | 'upload_date': upload_date, | |
112 | 'uploader': attr.get('channel_title'), | |
113 | 'uploader_id': attr.get('channel_idkey'), | |
375696b1 | 114 | 'formats': formats, |
d6fdc386 | 115 | } |