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.

148 lines
6.0 KiB

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