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.

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