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.

137 lines
5.5 KiB

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