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.

172 lines
6.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from .nexx import NexxEmbedIE
  6. from .spiegeltv import SpiegeltvIE
  7. from ..compat import compat_urlparse
  8. from ..utils import (
  9. extract_attributes,
  10. unified_strdate,
  11. get_element_by_attribute,
  12. )
  13. class SpiegelIE(InfoExtractor):
  14. _VALID_URL = r'https?://(?:www\.)?spiegel\.de/video/[^/]*-(?P<id>[0-9]+)(?:-embed|-iframe)?(?:\.html)?(?:#.*)?$'
  15. _TESTS = [{
  16. 'url': 'http://www.spiegel.de/video/vulkan-tungurahua-in-ecuador-ist-wieder-aktiv-video-1259285.html',
  17. 'md5': '2c2754212136f35fb4b19767d242f66e',
  18. 'info_dict': {
  19. 'id': '1259285',
  20. 'ext': 'mp4',
  21. 'title': 'Vulkanausbruch in Ecuador: Der "Feuerschlund" ist wieder aktiv',
  22. 'description': 'md5:8029d8310232196eb235d27575a8b9f4',
  23. 'duration': 49,
  24. 'upload_date': '20130311',
  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. 'upload_date': '20131115',
  36. },
  37. }, {
  38. 'url': 'http://www.spiegel.de/video/astronaut-alexander-gerst-von-der-iss-station-beantwortet-fragen-video-1519126-embed.html',
  39. 'md5': 'd8eeca6bfc8f1cd6f490eb1f44695d51',
  40. 'info_dict': {
  41. 'id': '1519126',
  42. 'ext': 'mp4',
  43. '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.',
  44. 'title': 'Fragen an Astronaut Alexander Gerst: "Bekommen Sie die Tageszeiten mit?"',
  45. 'upload_date': '20140904',
  46. }
  47. }, {
  48. 'url': 'http://www.spiegel.de/video/astronaut-alexander-gerst-von-der-iss-station-beantwortet-fragen-video-1519126-iframe.html',
  49. 'only_matching': True,
  50. }]
  51. def _real_extract(self, url):
  52. video_id = self._match_id(url)
  53. webpage, handle = self._download_webpage_handle(url, video_id)
  54. # 302 to spiegel.tv, like http://www.spiegel.de/video/der-film-zum-wochenende-die-wahrheit-ueber-maenner-video-99003272.html
  55. if SpiegeltvIE.suitable(handle.geturl()):
  56. return self.url_result(handle.geturl(), 'Spiegeltv')
  57. video_data = extract_attributes(self._search_regex(r'(<div[^>]+id="spVideoElements"[^>]+>)', webpage, 'video element', default=''))
  58. title = video_data.get('data-video-title') or get_element_by_attribute('class', 'module-title', webpage)
  59. description = video_data.get('data-video-teaser') or self._html_search_meta('description', webpage, 'description')
  60. base_url = self._search_regex(
  61. [r'server\s*:\s*(["\'])(?P<url>.+?)\1', r'var\s+server\s*=\s*"(?P<url>[^"]+)\"'],
  62. webpage, 'server URL', group='url')
  63. xml_url = base_url + video_id + '.xml'
  64. idoc = self._download_xml(xml_url, video_id)
  65. formats = []
  66. for n in list(idoc):
  67. if n.tag.startswith('type') and n.tag != 'type6':
  68. format_id = n.tag.rpartition('type')[2]
  69. video_url = base_url + n.find('./filename').text
  70. formats.append({
  71. 'format_id': format_id,
  72. 'url': video_url,
  73. 'width': int(n.find('./width').text),
  74. 'height': int(n.find('./height').text),
  75. 'abr': int(n.find('./audiobitrate').text),
  76. 'vbr': int(n.find('./videobitrate').text),
  77. 'vcodec': n.find('./codec').text,
  78. 'acodec': 'MP4A',
  79. })
  80. duration = float(idoc[0].findall('./duration')[0].text)
  81. self._check_formats(formats, video_id)
  82. self._sort_formats(formats)
  83. return {
  84. 'id': video_id,
  85. 'title': title,
  86. 'description': description.strip() if description else None,
  87. 'duration': duration,
  88. 'upload_date': unified_strdate(video_data.get('data-video-date')),
  89. 'formats': formats,
  90. }
  91. class SpiegelArticleIE(InfoExtractor):
  92. _VALID_URL = r'https?://(?:www\.)?spiegel\.de/(?!video/)[^?#]*?-(?P<id>[0-9]+)\.html'
  93. IE_NAME = 'Spiegel:Article'
  94. IE_DESC = 'Articles on spiegel.de'
  95. _TESTS = [{
  96. 'url': 'http://www.spiegel.de/sport/sonst/badminton-wm-die-randsportart-soll-populaerer-werden-a-987092.html',
  97. 'info_dict': {
  98. 'id': '1516455',
  99. 'ext': 'mp4',
  100. 'title': 'Faszination Badminton: Nennt es bloß nicht Federball',
  101. 'description': 're:^Patrick Kämnitz gehört.{100,}',
  102. 'upload_date': '20140825',
  103. },
  104. }, {
  105. 'url': 'http://www.spiegel.de/wissenschaft/weltall/astronaut-alexander-gerst-antwortet-spiegel-online-lesern-a-989876.html',
  106. 'info_dict': {
  107. },
  108. 'playlist_count': 6,
  109. }, {
  110. # Nexx iFrame embed
  111. 'url': 'http://www.spiegel.de/sptv/spiegeltv/spiegel-tv-ueber-schnellste-katapult-achterbahn-der-welt-taron-a-1137884.html',
  112. 'info_dict': {
  113. 'id': '161464',
  114. 'ext': 'mp4',
  115. 'title': 'Nervenkitzel Achterbahn',
  116. 'alt_title': 'Karussellbauer in Deutschland',
  117. 'description': 'md5:ffe7b1cc59a01f585e0569949aef73cc',
  118. 'release_year': 2005,
  119. 'creator': 'SPIEGEL TV',
  120. 'thumbnail': r're:^https?://.*\.jpg$',
  121. 'duration': 2761,
  122. 'timestamp': 1394021479,
  123. 'upload_date': '20140305',
  124. },
  125. 'params': {
  126. 'format': 'bestvideo',
  127. 'skip_download': True,
  128. },
  129. }]
  130. def _real_extract(self, url):
  131. video_id = self._match_id(url)
  132. webpage = self._download_webpage(url, video_id)
  133. # Single video on top of the page
  134. video_link = self._search_regex(
  135. r'<a href="([^"]+)" onclick="return spOpenVideo\(this,', webpage,
  136. 'video page URL', default=None)
  137. if video_link:
  138. video_url = compat_urlparse.urljoin(
  139. self.http_scheme() + '//spiegel.de/', video_link)
  140. return self.url_result(video_url)
  141. # Multiple embedded videos
  142. embeds = re.findall(
  143. r'<div class="vid_holder[0-9]+.*?</div>\s*.*?url\s*=\s*"([^"]+)"',
  144. webpage)
  145. entries = [
  146. self.url_result(compat_urlparse.urljoin(
  147. self.http_scheme() + '//spiegel.de/', embed_path))
  148. for embed_path in embeds]
  149. if embeds:
  150. return self.playlist_result(entries)
  151. return self.playlist_from_matches(
  152. NexxEmbedIE._extract_urls(webpage), ie=NexxEmbedIE.ie_key())