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.

138 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'server\s*:\s*(["\'])(?P<url>.+?)\1', r'var\s+server\s*=\s*"(?P<url>[^"]+)\"'],
  54. webpage, 'server URL', group='url')
  55. xml_url = base_url + video_id + '.xml'
  56. idoc = self._download_xml(xml_url, video_id)
  57. formats = []
  58. for n in list(idoc):
  59. if n.tag.startswith('type') and n.tag != 'type6':
  60. format_id = n.tag.rpartition('type')[2]
  61. video_url = base_url + n.find('./filename').text
  62. formats.append({
  63. 'format_id': format_id,
  64. 'url': video_url,
  65. 'width': int(n.find('./width').text),
  66. 'height': int(n.find('./height').text),
  67. 'abr': int(n.find('./audiobitrate').text),
  68. 'vbr': int(n.find('./videobitrate').text),
  69. 'vcodec': n.find('./codec').text,
  70. 'acodec': 'MP4A',
  71. })
  72. duration = float(idoc[0].findall('./duration')[0].text)
  73. self._check_formats(formats, video_id)
  74. self._sort_formats(formats)
  75. return {
  76. 'id': video_id,
  77. 'title': title,
  78. 'description': description,
  79. 'duration': duration,
  80. 'formats': formats,
  81. }
  82. class SpiegelArticleIE(InfoExtractor):
  83. _VALID_URL = 'https?://www\.spiegel\.de/(?!video/)[^?#]*?-(?P<id>[0-9]+)\.html'
  84. IE_NAME = 'Spiegel:Article'
  85. IE_DESC = 'Articles on spiegel.de'
  86. _TESTS = [{
  87. 'url': 'http://www.spiegel.de/sport/sonst/badminton-wm-die-randsportart-soll-populaerer-werden-a-987092.html',
  88. 'info_dict': {
  89. 'id': '1516455',
  90. 'ext': 'mp4',
  91. 'title': 'Faszination Badminton: Nennt es bloß nicht Federball',
  92. 'description': 're:^Patrick Kämnitz gehört.{100,}',
  93. },
  94. }, {
  95. 'url': 'http://www.spiegel.de/wissenschaft/weltall/astronaut-alexander-gerst-antwortet-spiegel-online-lesern-a-989876.html',
  96. 'info_dict': {
  97. },
  98. 'playlist_count': 6,
  99. }]
  100. def _real_extract(self, url):
  101. video_id = self._match_id(url)
  102. webpage = self._download_webpage(url, video_id)
  103. # Single video on top of the page
  104. video_link = self._search_regex(
  105. r'<a href="([^"]+)" onclick="return spOpenVideo\(this,', webpage,
  106. 'video page URL', default=None)
  107. if video_link:
  108. video_url = compat_urlparse.urljoin(
  109. self.http_scheme() + '//spiegel.de/', video_link)
  110. return self.url_result(video_url)
  111. # Multiple embedded videos
  112. embeds = re.findall(
  113. r'<div class="vid_holder[0-9]+.*?</div>\s*.*?url\s*=\s*"([^"]+)"',
  114. webpage)
  115. entries = [
  116. self.url_result(compat_urlparse.urljoin(
  117. self.http_scheme() + '//spiegel.de/', embed_path))
  118. for embed_path in embeds
  119. ]
  120. return self.playlist_result(entries)