You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import compat_urlparse
  6. class GolemIE(InfoExtractor):
  7. _VALID_URL = r'^https?://video\.golem\.de/.+?/(?P<id>.+?)/'
  8. _TEST = {
  9. 'url': 'http://video.golem.de/handy/14095/iphone-6-und-6-plus-test.html',
  10. 'md5': 'c1a2c0a3c863319651c7c992c5ee29bf',
  11. 'info_dict': {
  12. 'id': '14095',
  13. 'format_id': 'high',
  14. 'ext': 'mp4',
  15. 'title': 'iPhone 6 und 6 Plus - Test',
  16. 'duration': 300,
  17. 'filesize': 65309548,
  18. }
  19. }
  20. _CONFIG = 'https://video.golem.de/xml/{}.xml'
  21. _PREFIX = 'http://video.golem.de'
  22. def _warn(self, fmt, *args):
  23. self.report_warning(fmt.format(*args), self._id)
  24. def _extract_format(self, elem):
  25. format_id = elem.tag
  26. url = elem.findtext('./url')
  27. if url == '':
  28. self._warn("{}: url: empty, skipping", format_id)
  29. return None
  30. fmt = {
  31. 'format_id': format_id,
  32. 'url': compat_urlparse.urljoin(self._PREFIX, url)
  33. }
  34. try:
  35. _, ext = elem.findtext('./filename', '').rsplit('.', 1)
  36. except ValueError:
  37. self._warn('{}: ext: missing extension', format_id)
  38. else:
  39. fmt['ext'] = ext
  40. filesize = elem.findtext('./filesize')
  41. if filesize is not None:
  42. try:
  43. fmt['filesize'] = int(filesize)
  44. except ValueError as e:
  45. self._warn('{}: filesize: {}', format_id, e)
  46. width = elem.get('width')
  47. if width is not None:
  48. try:
  49. fmt['width'] = int(width)
  50. except ValueError as e:
  51. self._warn('{}: width: {}', format_id, e)
  52. height = elem.get('height')
  53. if height is not None:
  54. try:
  55. fmt['height'] = int(height)
  56. except ValueError as e:
  57. self._warn('{}: height: {}', format_id, e)
  58. return fmt
  59. def _extract_thumbnail(self, elem):
  60. url = elem.findtext('./url')
  61. if url == '':
  62. return None
  63. thumb = {
  64. 'url': compat_urlparse.urljoin(self._PREFIX, url)
  65. }
  66. width = elem.get('width')
  67. if width is not None:
  68. try:
  69. thumb['width'] = int(width)
  70. except ValueError as e:
  71. self._warn('thumbnail: width: {}', e)
  72. height = elem.get('height')
  73. if height is not None:
  74. try:
  75. thumb['height'] = int(height)
  76. except ValueError as e:
  77. self._warn('thumbnail: height: {}', e)
  78. return thumb
  79. def _real_extract(self, url):
  80. mobj = re.match(self._VALID_URL, url)
  81. self._id = mobj.group('id')
  82. config = self._download_xml(self._CONFIG.format(self._id), self._id)
  83. info = {
  84. 'id': self._id,
  85. 'title': config.findtext('./title', 'golem')
  86. }
  87. formats = []
  88. for e in config.findall('./*[url]'):
  89. fmt = self._extract_format(e)
  90. if fmt is not None:
  91. formats.append(fmt)
  92. self._sort_formats(formats)
  93. info['formats'] = formats
  94. thumbnails = []
  95. for e in config.findall('.//teaser[url]'):
  96. thumb = self._extract_thumbnail(e)
  97. if thumb is not None:
  98. thumbnails.append(thumb)
  99. info['thumbnails'] = thumbnails
  100. playtime = config.findtext('./playtime')
  101. if playtime is not None:
  102. try:
  103. info['duration'] = round(float(playtime))
  104. except ValueError as e:
  105. self._warn('duration: {}', e)
  106. return info