]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/swrmediathek.py
5d9d703673265ca4a53a54f28e34494d570cb206
[youtubedl] / youtube_dl / extractor / swrmediathek.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import parse_duration
8
9
10 class SWRMediathekIE(InfoExtractor):
11 _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})'
12
13 _TESTS = [{
14 'url': 'http://swrmediathek.de/player.htm?show=849790d0-dab8-11e3-a953-0026b975f2e6',
15 'md5': '8c5f6f0172753368547ca8413a7768ac',
16 'info_dict': {
17 'id': '849790d0-dab8-11e3-a953-0026b975f2e6',
18 'ext': 'mp4',
19 'title': 'SWR odysso',
20 'description': 'md5:2012e31baad36162e97ce9eb3f157b8a',
21 'thumbnail': 're:^http:.*\.jpg$',
22 'duration': 2602,
23 'upload_date': '20140515',
24 'uploader': 'SWR Fernsehen',
25 'uploader_id': '990030',
26 },
27 }, {
28 'url': 'http://swrmediathek.de/player.htm?show=0e1a8510-ddf2-11e3-9be3-0026b975f2e6',
29 'md5': 'b10ab854f912eecc5a6b55cd6fc1f545',
30 'info_dict': {
31 'id': '0e1a8510-ddf2-11e3-9be3-0026b975f2e6',
32 'ext': 'mp4',
33 'title': 'Nachtcafé - Alltagsdroge Alkohol - zwischen Sektempfang und Komasaufen',
34 'description': 'md5:e0a3adc17e47db2c23aab9ebc36dbee2',
35 'thumbnail': 're:http://.*\.jpg',
36 'duration': 5305,
37 'upload_date': '20140516',
38 'uploader': 'SWR Fernsehen',
39 'uploader_id': '990030',
40 },
41 }, {
42 'url': 'http://swrmediathek.de/player.htm?show=bba23e10-cb93-11e3-bf7f-0026b975f2e6',
43 'md5': '4382e4ef2c9d7ce6852535fa867a0dd3',
44 'info_dict': {
45 'id': 'bba23e10-cb93-11e3-bf7f-0026b975f2e6',
46 'ext': 'mp3',
47 'title': 'Saša Stanišic: Vor dem Fest',
48 'description': 'md5:5b792387dc3fbb171eb709060654e8c9',
49 'thumbnail': 're:http://.*\.jpg',
50 'duration': 3366,
51 'upload_date': '20140520',
52 'uploader': 'SWR 2',
53 'uploader_id': '284670',
54 }
55 }, {
56 'url': 'http://swrmediathek.de/content/player.htm?show=52dc7e00-15c5-11e4-84bc-0026b975f2e6',
57 'md5': '881531487d0633080a8cc88d31ef896f',
58 'info_dict': {
59 'id': '52dc7e00-15c5-11e4-84bc-0026b975f2e6',
60 'ext': 'mp4',
61 'title': 'Familienspaß am Bodensee',
62 'description': 'md5:0b591225a32cfde7be1629ed49fe4315',
63 'thumbnail': 're:http://.*\.jpg',
64 'duration': 1784,
65 'upload_date': '20140727',
66 'uploader': 'SWR Fernsehen BW',
67 'uploader_id': '281130',
68 }
69 }]
70
71 def _real_extract(self, url):
72 mobj = re.match(self._VALID_URL, url)
73 video_id = mobj.group('id')
74
75 video = self._download_json(
76 'http://swrmediathek.de/AjaxEntry?ekey=%s' % video_id, video_id, 'Downloading video JSON')
77
78 attr = video['attr']
79 media_type = attr['entry_etype']
80
81 formats = []
82 for entry in video['sub']:
83 if entry['name'] != 'entry_media':
84 continue
85
86 entry_attr = entry['attr']
87 codec = entry_attr['val0']
88 quality = int(entry_attr['val1'])
89
90 fmt = {
91 'url': entry_attr['val2'],
92 'quality': quality,
93 }
94
95 if media_type == 'Video':
96 fmt.update({
97 'format_note': ['144p', '288p', '544p'][quality-1],
98 'vcodec': codec,
99 })
100 elif media_type == 'Audio':
101 fmt.update({
102 'acodec': codec,
103 })
104 formats.append(fmt)
105
106 self._sort_formats(formats)
107
108 return {
109 'id': video_id,
110 'title': attr['entry_title'],
111 'description': attr['entry_descl'],
112 'thumbnail': attr['entry_image_16_9'],
113 'duration': parse_duration(attr['entry_durat']),
114 'upload_date': attr['entry_pdatet'][:-4],
115 'uploader': attr['channel_title'],
116 'uploader_id': attr['channel_idkey'],
117 'formats': formats,
118 }