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.

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