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.

116 lines
4.2 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import compat_urlparse
  6. class SpiegelIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?spiegel\.de/video/[^/]*-(?P<videoID>[0-9]+)(?:\.html)?(?:#.*)?$'
  8. _TESTS = [{
  9. 'url': 'http://www.spiegel.de/video/vulkan-tungurahua-in-ecuador-ist-wieder-aktiv-video-1259285.html',
  10. 'md5': '2c2754212136f35fb4b19767d242f66e',
  11. 'info_dict': {
  12. 'id': '1259285',
  13. 'ext': 'mp4',
  14. 'title': 'Vulkanausbruch in Ecuador: Der "Feuerschlund" ist wieder aktiv',
  15. 'description': 'md5:8029d8310232196eb235d27575a8b9f4',
  16. 'duration': 49,
  17. },
  18. }, {
  19. 'url': 'http://www.spiegel.de/video/schach-wm-videoanalyse-des-fuenften-spiels-video-1309159.html',
  20. 'md5': 'f2cdf638d7aa47654e251e1aee360af1',
  21. 'info_dict': {
  22. 'id': '1309159',
  23. 'ext': 'mp4',
  24. 'title': 'Schach-WM in der Videoanalyse: Carlsen nutzt die Fehlgriffe des Titelverteidigers',
  25. 'description': 'md5:c2322b65e58f385a820c10fa03b2d088',
  26. 'duration': 983,
  27. },
  28. }, {
  29. 'url': 'http://www.spiegel.de/video/johann-westhauser-videobotschaft-des-hoehlenforschers-video-1502367.html',
  30. 'md5': '54f58ba0e752e3c07bc2a26222dd0acf',
  31. 'info_dict': {
  32. 'id': '1502367',
  33. 'ext': 'mp4',
  34. 'title': 'Videobotschaft: Höhlenforscher Westhauser dankt seinen Rettern',
  35. 'description': 'md5:c6f1ec11413ebd1088b6813943e5fc91',
  36. 'duration': 42,
  37. },
  38. }]
  39. def _real_extract(self, url):
  40. m = re.match(self._VALID_URL, url)
  41. video_id = m.group('videoID')
  42. webpage = self._download_webpage(url, video_id)
  43. title = self._html_search_regex(
  44. r'<div class="module-title">(.*?)</div>', webpage, 'title')
  45. description = self._html_search_meta('description', webpage, 'description')
  46. base_url = self._search_regex(
  47. r'var\s+server\s*=\s*"([^"]+)\"', webpage, 'server URL')
  48. xml_url = base_url + video_id + '.xml'
  49. idoc = self._download_xml(xml_url, video_id)
  50. formats = [
  51. {
  52. 'format_id': n.tag.rpartition('type')[2],
  53. 'url': base_url + n.find('./filename').text,
  54. 'width': int(n.find('./width').text),
  55. 'height': int(n.find('./height').text),
  56. 'abr': int(n.find('./audiobitrate').text),
  57. 'vbr': int(n.find('./videobitrate').text),
  58. 'vcodec': n.find('./codec').text,
  59. 'acodec': 'MP4A',
  60. }
  61. for n in list(idoc)
  62. # Blacklist type 6, it's extremely LQ and not available on the same server
  63. if n.tag.startswith('type') and n.tag != 'type6'
  64. ]
  65. duration = float(idoc[0].findall('./duration')[0].text)
  66. self._sort_formats(formats)
  67. return {
  68. 'id': video_id,
  69. 'title': title,
  70. 'description': description,
  71. 'duration': duration,
  72. 'formats': formats,
  73. }
  74. class SpiegelArticleIE(InfoExtractor):
  75. _VALID_URL = 'https?://www\.spiegel\.de/(?!video/)[^?#]*?-(?P<id>[0-9]+)\.html'
  76. IE_NAME = 'Spiegel:Article'
  77. IE_DESC = 'Articles on spiegel.de'
  78. _TEST = {
  79. 'url': 'http://www.spiegel.de/sport/sonst/badminton-wm-die-randsportart-soll-populaerer-werden-a-987092.html',
  80. 'info_dict': {
  81. 'id': '1516455',
  82. 'ext': 'mp4',
  83. 'title': 'Faszination Badminton: Nennt es bloß nicht Federball',
  84. 'description': 're:^Patrick Kämnitz gehört.{100,}',
  85. },
  86. }
  87. def _real_extract(self, url):
  88. m = re.match(self._VALID_URL, url)
  89. video_id = m.group('id')
  90. webpage = self._download_webpage(url, video_id)
  91. video_link = self._search_regex(
  92. r'<a href="([^"]+)" onclick="return spOpenVideo\(this,', webpage,
  93. 'video page URL')
  94. video_url = compat_urlparse.urljoin(
  95. self.http_scheme() + '//spiegel.de/', video_link)
  96. return {
  97. '_type': 'url',
  98. 'url': video_url,
  99. }