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.

103 lines
3.6 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import compat_urlparse
  6. class SpiegelIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?spiegel\.de/video/[^/]*-(?P<id>[0-9]+)(?:\.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. def _real_extract(self, url):
  30. video_id = self._match_id(url)
  31. webpage = self._download_webpage(url, video_id)
  32. title = self._html_search_regex(
  33. r'<div class="module-title">(.*?)</div>', webpage, 'title')
  34. description = self._html_search_meta('description', webpage, 'description')
  35. base_url = self._search_regex(
  36. r'var\s+server\s*=\s*"([^"]+)\"', webpage, 'server URL')
  37. xml_url = base_url + video_id + '.xml'
  38. idoc = self._download_xml(xml_url, video_id)
  39. formats = [
  40. {
  41. 'format_id': n.tag.rpartition('type')[2],
  42. 'url': base_url + n.find('./filename').text,
  43. 'width': int(n.find('./width').text),
  44. 'height': int(n.find('./height').text),
  45. 'abr': int(n.find('./audiobitrate').text),
  46. 'vbr': int(n.find('./videobitrate').text),
  47. 'vcodec': n.find('./codec').text,
  48. 'acodec': 'MP4A',
  49. }
  50. for n in list(idoc)
  51. # Blacklist type 6, it's extremely LQ and not available on the same server
  52. if n.tag.startswith('type') and n.tag != 'type6'
  53. ]
  54. duration = float(idoc[0].findall('./duration')[0].text)
  55. self._sort_formats(formats)
  56. return {
  57. 'id': video_id,
  58. 'title': title,
  59. 'description': description,
  60. 'duration': duration,
  61. 'formats': formats,
  62. }
  63. class SpiegelArticleIE(InfoExtractor):
  64. _VALID_URL = 'https?://www\.spiegel\.de/(?!video/)[^?#]*?-(?P<id>[0-9]+)\.html'
  65. IE_NAME = 'Spiegel:Article'
  66. IE_DESC = 'Articles on spiegel.de'
  67. _TEST = {
  68. 'url': 'http://www.spiegel.de/sport/sonst/badminton-wm-die-randsportart-soll-populaerer-werden-a-987092.html',
  69. 'info_dict': {
  70. 'id': '1516455',
  71. 'ext': 'mp4',
  72. 'title': 'Faszination Badminton: Nennt es bloß nicht Federball',
  73. 'description': 're:^Patrick Kämnitz gehört.{100,}',
  74. },
  75. }
  76. def _real_extract(self, url):
  77. video_id = self._match_id(url)
  78. webpage = self._download_webpage(url, video_id)
  79. video_link = self._search_regex(
  80. r'<a href="([^"]+)" onclick="return spOpenVideo\(this,', webpage,
  81. 'video page URL')
  82. video_url = compat_urlparse.urljoin(
  83. self.http_scheme() + '//spiegel.de/', video_link)
  84. return {
  85. '_type': 'url',
  86. 'url': video_url,
  87. }