golem.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from .common import InfoExtractor
  2. from ..compat import (
  3. compat_str,
  4. compat_urlparse,
  5. )
  6. from ..utils import (
  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:
  35. url = e.findtext('./url')
  36. if not url:
  37. continue
  38. formats.append({
  39. 'format_id': compat_str(e.tag),
  40. 'url': compat_urlparse.urljoin(self._PREFIX, url),
  41. 'height': self._int(e.get('height'), 'height'),
  42. 'width': self._int(e.get('width'), 'width'),
  43. 'filesize': self._int(e.findtext('filesize'), 'filesize'),
  44. 'ext': determine_ext(e.findtext('./filename')),
  45. })
  46. info['formats'] = formats
  47. thumbnails = []
  48. for e in config.findall('.//teaser'):
  49. url = e.findtext('./url')
  50. if not url:
  51. continue
  52. thumbnails.append({
  53. 'url': compat_urlparse.urljoin(self._PREFIX, url),
  54. 'width': self._int(e.get('width'), 'thumbnail width'),
  55. 'height': self._int(e.get('height'), 'thumbnail height'),
  56. })
  57. info['thumbnails'] = thumbnails
  58. return info