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.

150 lines
5.9 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urlparse,
  7. compat_HTTPError,
  8. )
  9. from ..utils import (
  10. HEADRequest,
  11. ExtractorError,
  12. )
  13. from .spiegeltv import SpiegeltvIE
  14. class SpiegelIE(InfoExtractor):
  15. _VALID_URL = r'https?://(?:www\.)?spiegel\.de/video/[^/]*-(?P<id>[0-9]+)(?:-embed)?(?:\.html)?(?:#.*)?$'
  16. _TESTS = [{
  17. 'url': 'http://www.spiegel.de/video/vulkan-tungurahua-in-ecuador-ist-wieder-aktiv-video-1259285.html',
  18. 'md5': '2c2754212136f35fb4b19767d242f66e',
  19. 'info_dict': {
  20. 'id': '1259285',
  21. 'ext': 'mp4',
  22. 'title': 'Vulkanausbruch in Ecuador: Der "Feuerschlund" ist wieder aktiv',
  23. 'description': 'md5:8029d8310232196eb235d27575a8b9f4',
  24. 'duration': 49,
  25. },
  26. }, {
  27. 'url': 'http://www.spiegel.de/video/schach-wm-videoanalyse-des-fuenften-spiels-video-1309159.html',
  28. 'md5': 'f2cdf638d7aa47654e251e1aee360af1',
  29. 'info_dict': {
  30. 'id': '1309159',
  31. 'ext': 'mp4',
  32. 'title': 'Schach-WM in der Videoanalyse: Carlsen nutzt die Fehlgriffe des Titelverteidigers',
  33. 'description': 'md5:c2322b65e58f385a820c10fa03b2d088',
  34. 'duration': 983,
  35. },
  36. }, {
  37. 'url': 'http://www.spiegel.de/video/astronaut-alexander-gerst-von-der-iss-station-beantwortet-fragen-video-1519126-embed.html',
  38. 'md5': 'd8eeca6bfc8f1cd6f490eb1f44695d51',
  39. 'info_dict': {
  40. 'id': '1519126',
  41. 'ext': 'mp4',
  42. 'description': 'SPIEGEL ONLINE-Nutzer durften den deutschen Astronauten Alexander Gerst über sein Leben auf der ISS-Station befragen. Hier kommen seine Antworten auf die besten sechs Fragen.',
  43. 'title': 'Fragen an Astronaut Alexander Gerst: "Bekommen Sie die Tageszeiten mit?"',
  44. }
  45. }]
  46. def _real_extract(self, url):
  47. video_id = self._match_id(url)
  48. webpage, handle = self._download_webpage_handle(url, video_id)
  49. # 302 to spiegel.tv, like http://www.spiegel.de/video/der-film-zum-wochenende-die-wahrheit-ueber-maenner-video-99003272.html
  50. if SpiegeltvIE.suitable(handle.geturl()):
  51. return self.url_result(handle.geturl(), 'Spiegeltv')
  52. title = re.sub(r'\s+', ' ', self._html_search_regex(
  53. r'(?s)<(?:h1|div) class="module-title"[^>]*>(.*?)</(?:h1|div)>',
  54. webpage, 'title'))
  55. description = self._html_search_meta('description', webpage, 'description')
  56. base_url = self._search_regex(
  57. r'var\s+server\s*=\s*"([^"]+)\"', webpage, 'server URL')
  58. xml_url = base_url + video_id + '.xml'
  59. idoc = self._download_xml(xml_url, video_id)
  60. formats = []
  61. for n in list(idoc):
  62. if n.tag.startswith('type') and n.tag != 'type6':
  63. format_id = n.tag.rpartition('type')[2]
  64. video_url = base_url + n.find('./filename').text
  65. # Test video URLs beforehand as some of them are invalid
  66. try:
  67. self._request_webpage(
  68. HEADRequest(video_url), video_id,
  69. 'Checking %s video URL' % format_id)
  70. except ExtractorError as e:
  71. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
  72. self.report_warning(
  73. '%s video URL is invalid, skipping' % format_id, video_id)
  74. continue
  75. formats.append({
  76. 'format_id': format_id,
  77. 'url': video_url,
  78. 'width': int(n.find('./width').text),
  79. 'height': int(n.find('./height').text),
  80. 'abr': int(n.find('./audiobitrate').text),
  81. 'vbr': int(n.find('./videobitrate').text),
  82. 'vcodec': n.find('./codec').text,
  83. 'acodec': 'MP4A',
  84. })
  85. duration = float(idoc[0].findall('./duration')[0].text)
  86. self._sort_formats(formats)
  87. return {
  88. 'id': video_id,
  89. 'title': title,
  90. 'description': description,
  91. 'duration': duration,
  92. 'formats': formats,
  93. }
  94. class SpiegelArticleIE(InfoExtractor):
  95. _VALID_URL = 'https?://www\.spiegel\.de/(?!video/)[^?#]*?-(?P<id>[0-9]+)\.html'
  96. IE_NAME = 'Spiegel:Article'
  97. IE_DESC = 'Articles on spiegel.de'
  98. _TESTS = [{
  99. 'url': 'http://www.spiegel.de/sport/sonst/badminton-wm-die-randsportart-soll-populaerer-werden-a-987092.html',
  100. 'info_dict': {
  101. 'id': '1516455',
  102. 'ext': 'mp4',
  103. 'title': 'Faszination Badminton: Nennt es bloß nicht Federball',
  104. 'description': 're:^Patrick Kämnitz gehört.{100,}',
  105. },
  106. }, {
  107. 'url': 'http://www.spiegel.de/wissenschaft/weltall/astronaut-alexander-gerst-antwortet-spiegel-online-lesern-a-989876.html',
  108. 'info_dict': {
  109. },
  110. 'playlist_count': 6,
  111. }]
  112. def _real_extract(self, url):
  113. video_id = self._match_id(url)
  114. webpage = self._download_webpage(url, video_id)
  115. # Single video on top of the page
  116. video_link = self._search_regex(
  117. r'<a href="([^"]+)" onclick="return spOpenVideo\(this,', webpage,
  118. 'video page URL', default=None)
  119. if video_link:
  120. video_url = compat_urlparse.urljoin(
  121. self.http_scheme() + '//spiegel.de/', video_link)
  122. return self.url_result(video_url)
  123. # Multiple embedded videos
  124. embeds = re.findall(
  125. r'<div class="vid_holder[0-9]+.*?</div>\s*.*?url\s*=\s*"([^"]+)"',
  126. webpage)
  127. entries = [
  128. self.url_result(compat_urlparse.urljoin(
  129. self.http_scheme() + '//spiegel.de/', embed_path))
  130. for embed_path in embeds
  131. ]
  132. return self.playlist_result(entries)