]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/dreisat.py
Merge branch 'ustream-embed-recorded2' of https://github.com/anovicecodemonkey/youtub...
[youtube-dl] / youtube_dl / extractor / dreisat.py
1 # coding: utf-8
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7     unified_strdate,
8 )
9
10
11 class DreiSatIE(InfoExtractor):
12     IE_NAME = '3sat'
13     _VALID_URL = r'(?:http://)?(?:www\.)?3sat\.de/mediathek/(?:index\.php)?\?(?:(?:mode|display)=[^&]+&)*obj=(?P<id>[0-9]+)$'
14     _TEST = {
15         u"url": u"http://www.3sat.de/mediathek/index.php?obj=36983",
16         u'file': u'36983.mp4',
17         u'md5': u'9dcfe344732808dbfcc901537973c922',
18         u'info_dict': {
19             u"title": u"Kaffeeland Schweiz",
20             u"description": u"Über 80 Kaffeeröstereien liefern in der Schweiz das Getränk, in das das Land so vernarrt ist: Mehr als 1000 Tassen trinkt ein Schweizer pro Jahr. SCHWEIZWEIT nimmt die Kaffeekultur unter die...", 
21             u"uploader": u"3sat",
22             u"upload_date": u"20130622"
23         }
24     }
25
26
27     def _real_extract(self, url):
28         mobj = re.match(self._VALID_URL, url)
29         video_id = mobj.group('id')
30         details_url = 'http://www.3sat.de/mediathek/xmlservice/web/beitragsDetails?ak=web&id=%s' % video_id
31         details_doc = self._download_xml(details_url, video_id, note=u'Downloading video details')
32
33         thumbnail_els = details_doc.findall('.//teaserimage')
34         thumbnails = [{
35             'width': te.attrib['key'].partition('x')[0],
36             'height': te.attrib['key'].partition('x')[2],
37             'url': te.text,
38         } for te in thumbnail_els]
39
40         information_el = details_doc.find('.//information')
41         video_title = information_el.find('./title').text
42         video_description = information_el.find('./detail').text
43
44         details_el = details_doc.find('.//details')
45         video_uploader = details_el.find('./channel').text
46         upload_date = unified_strdate(details_el.find('./airtime').text)
47
48         format_els = details_doc.findall('.//formitaet')
49         formats = [{
50             'format_id': fe.attrib['basetype'],
51             'width': int(fe.find('./width').text),
52             'height': int(fe.find('./height').text),
53             'url': fe.find('./url').text,
54             'filesize': int(fe.find('./filesize').text),
55             'video_bitrate': int(fe.find('./videoBitrate').text),
56         } for fe in format_els
57             if not fe.find('./url').text.startswith('http://www.metafilegenerator.de/')]
58
59         self._sort_formats(formats)
60
61         return {
62             '_type': 'video',
63             'id': video_id,
64             'title': video_title,
65             'formats': formats,
66             'description': video_description,
67             'thumbnails': thumbnails,
68             'thumbnail': thumbnails[-1]['url'],
69             'uploader': video_uploader,
70             'upload_date': upload_date,
71         }