spiegel.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. class SpiegelIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:www\.)?spiegel\.de/video/[^/]*-(?P<videoID>[0-9]+)(?:\.html)?(?:#.*)?$'
  6. _TESTS = [{
  7. 'url': 'http://www.spiegel.de/video/vulkan-tungurahua-in-ecuador-ist-wieder-aktiv-video-1259285.html',
  8. 'file': '1259285.mp4',
  9. 'md5': '2c2754212136f35fb4b19767d242f66e',
  10. 'info_dict': {
  11. 'title': 'Vulkanausbruch in Ecuador: Der "Feuerschlund" ist wieder aktiv',
  12. },
  13. },
  14. {
  15. 'url': 'http://www.spiegel.de/video/schach-wm-videoanalyse-des-fuenften-spiels-video-1309159.html',
  16. 'file': '1309159.mp4',
  17. 'md5': 'f2cdf638d7aa47654e251e1aee360af1',
  18. 'info_dict': {
  19. 'title': 'Schach-WM in der Videoanalyse: Carlsen nutzt die Fehlgriffe des Titelverteidigers',
  20. },
  21. }]
  22. def _real_extract(self, url):
  23. m = re.match(self._VALID_URL, url)
  24. video_id = m.group('videoID')
  25. webpage = self._download_webpage(url, video_id)
  26. video_title = self._html_search_regex(
  27. r'<div class="module-title">(.*?)</div>', webpage, 'title')
  28. base_url = self._search_regex(
  29. r'var\s+server\s+=\s+\"(http://video\d*\.spiegel\.de/flash/\d+/\d+/)\";',
  30. webpage,
  31. 'base_url',
  32. )
  33. xml_url = base_url + video_id + '.xml'
  34. idoc = self._download_xml(
  35. xml_url, video_id,
  36. note='Downloading XML', errnote='Failed to download XML from "{0}"'.format(xml_url))
  37. formats = [
  38. {
  39. 'format_id': n.tag.rpartition('type')[2],
  40. 'url': base_url + n.find('./filename').text,
  41. 'width': int(n.find('./width').text),
  42. 'height': int(n.find('./height').text),
  43. 'abr': int(n.find('./audiobitrate').text),
  44. 'vbr': int(n.find('./videobitrate').text),
  45. 'vcodec': n.find('./codec').text,
  46. 'acodec': 'MP4A',
  47. }
  48. for n in list(idoc)
  49. # Blacklist type 6, it's extremely LQ and not available on the same server
  50. if n.tag.startswith('type') and n.tag != 'type6'
  51. ]
  52. duration = float(idoc[0].findall('./duration')[0].text)
  53. self._sort_formats(formats)
  54. return {
  55. 'id': video_id,
  56. 'title': video_title,
  57. 'duration': duration,
  58. 'formats': formats,
  59. }