Merge remote-tracking branch 'r4mos/played'
[youtube-dl] / youtube_dl / extractor / golem.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     compat_urlparse,
7     determine_ext,
8 )
9
10
11 class GolemIE(InfoExtractor):
12     _VALID_URL = r'^https?://video\.golem\.de/.+?/(?P<id>.+?)/'
13     _TEST = {
14         'url': 'http://video.golem.de/handy/14095/iphone-6-und-6-plus-test.html',
15         'md5': 'c1a2c0a3c863319651c7c992c5ee29bf',
16         'info_dict': {
17             'id': '14095',
18             'format_id': 'high',
19             'ext': 'mp4',
20             'title': 'iPhone 6 und 6 Plus - Test',
21             'duration': 300.44,
22             'filesize': 65309548,
23         }
24     }
25
26     _PREFIX = 'http://video.golem.de'
27
28     def _real_extract(self, url):
29         video_id = self._match_id(url)
30
31         config = self._download_xml(
32             'https://video.golem.de/xml/{0}.xml'.format(video_id), video_id)
33
34         info = {
35             'id': video_id,
36             'title': config.findtext('./title', 'golem'),
37             'duration': self._float(config.findtext('./playtime'), 'duration'),
38         }
39
40         formats = []
41         for e in config.findall('./*[url]'):
42             url = e.findtext('./url')
43             if not url:
44                 self._downloader.report_warning(
45                     "{0}: url: empty, skipping".format(e.tag))
46                 continue
47
48             formats.append({
49                 'format_id': e.tag,
50                 'url': compat_urlparse.urljoin(self._PREFIX, url),
51                 'height': self._int(e.get('height'), 'height'),
52                 'width': self._int(e.get('width'), 'width'),
53                 'filesize': self._int(e.findtext('filesize'), 'filesize'),
54                 'ext': determine_ext(e.findtext('./filename')),
55             })
56         self._sort_formats(formats)
57         info['formats'] = formats
58
59         thumbnails = []
60         for e in config.findall('.//teaser[url]'):
61             url = e.findtext('./url')
62             if not url:
63                 continue
64             thumbnails.append({
65                 'url': compat_urlparse.urljoin(self._PREFIX, url),
66                 'width': self._int(e.get('width'), 'thumbnail width'),
67                 'height': self._int(e.get('height'), 'thumbnail height'),
68             })
69         info['thumbnails'] = thumbnails
70
71         return info