golem.py 2.2 KB

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