2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..utils import compat_urlparse
10 class GolemIE(InfoExtractor):
11 _VALID_URL = r'^https?://video\.golem\.de/.+?/(?P<id>.+?)/'
13 'url': 'http://video.golem.de/handy/14095/iphone-6-und-6-plus-test.html',
14 'md5': 'c1a2c0a3c863319651c7c992c5ee29bf',
19 'title': 'iPhone 6 und 6 Plus - Test',
25 _CONFIG = 'https://video.golem.de/xml/{0}.xml'
26 _PREFIX = 'http://video.golem.de'
28 def _warn(self, fmt, *args):
29 self.report_warning(fmt.format(*args), self._id)
31 def _extract_format(self, elem):
34 url = elem.findtext('./url')
36 self._warn("{0}: url: empty, skipping", format_id)
40 'format_id': format_id,
41 'url': compat_urlparse.urljoin(self._PREFIX, url)
45 _, ext = elem.findtext('./filename', '').rsplit('.', 1)
47 self._warn('{0}: ext: missing extension', format_id)
51 filesize = elem.findtext('./filesize')
52 if filesize is not None:
54 fmt['filesize'] = int(filesize)
55 except ValueError as e:
56 self._warn('{0}: filesize: {1}', format_id, e)
58 width = elem.get('width')
61 fmt['width'] = int(width)
62 except ValueError as e:
63 self._warn('{0}: width: {1}', format_id, e)
65 height = elem.get('height')
66 if height is not None:
68 fmt['height'] = int(height)
69 except ValueError as e:
70 self._warn('{0}: height: {1}', format_id, e)
74 def _extract_thumbnail(self, elem):
75 url = elem.findtext('./url')
79 'url': compat_urlparse.urljoin(self._PREFIX, url)
82 width = elem.get('width')
85 thumb['width'] = int(width)
86 except ValueError as e:
87 self._warn('thumbnail: width: {0}', e)
89 height = elem.get('height')
90 if height is not None:
92 thumb['height'] = int(height)
93 except ValueError as e:
94 self._warn('thumbnail: height: {0}', e)
98 def _real_extract(self, url):
99 mobj = re.match(self._VALID_URL, url)
100 self._id = mobj.group('id')
102 config = self._download_xml(self._CONFIG.format(self._id), self._id)
106 'title': config.findtext('./title', 'golem')
110 for e in config.findall('./*[url]'):
111 fmt = self._extract_format(e)
114 self._sort_formats(formats)
115 info['formats'] = formats
118 for e in config.findall('.//teaser[url]'):
119 thumb = self._extract_thumbnail(e)
120 if thumb is not None:
121 thumbnails.append(thumb)
122 info['thumbnails'] = thumbnails
124 playtime = config.findtext('./playtime')
125 if playtime is not None:
127 info['duration'] = round(float(playtime))
128 except ValueError as e:
129 self._warn('duration: {0}', e)