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.

66 lines
2.4 KiB

  1. import re
  2. import xml.etree.ElementTree
  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. u'url': u'http://www.spiegel.de/video/vulkan-tungurahua-in-ecuador-ist-wieder-aktiv-video-1259285.html',
  8. u'file': u'1259285.mp4',
  9. u'md5': u'2c2754212136f35fb4b19767d242f66e',
  10. u'info_dict': {
  11. u"title": u"Vulkanausbruch in Ecuador: Der \"Feuerschlund\" ist wieder aktiv"
  12. }
  13. },
  14. {
  15. u'url': u'http://www.spiegel.de/video/schach-wm-videoanalyse-des-fuenften-spiels-video-1309159.html',
  16. u'file': u'1309159.mp4',
  17. u'md5': u'f2cdf638d7aa47654e251e1aee360af1',
  18. u'info_dict': {
  19. u'title': u'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, u'title')
  28. xml_url = u'http://video2.spiegel.de/flash/' + video_id + u'.xml'
  29. xml_code = self._download_webpage(
  30. xml_url, video_id,
  31. note=u'Downloading XML', errnote=u'Failed to download XML')
  32. idoc = xml.etree.ElementTree.fromstring(xml_code)
  33. formats = [
  34. {
  35. 'format_id': n.tag.rpartition('type')[2],
  36. 'url': u'http://video2.spiegel.de/flash/' + n.find('./filename').text,
  37. 'width': int(n.find('./width').text),
  38. 'height': int(n.find('./height').text),
  39. 'abr': int(n.find('./audiobitrate').text),
  40. 'vbr': int(n.find('./videobitrate').text),
  41. 'vcodec': n.find('./codec').text,
  42. 'acodec': 'MP4A',
  43. }
  44. for n in list(idoc)
  45. # Blacklist type 6, it's extremely LQ and not available on the same server
  46. if n.tag.startswith('type') and n.tag != 'type6'
  47. ]
  48. formats.sort(key=lambda f: f['vbr'])
  49. duration = float(idoc[0].findall('./duration')[0].text)
  50. info = {
  51. 'id': video_id,
  52. 'title': video_title,
  53. 'duration': duration,
  54. 'formats': formats,
  55. }
  56. return info