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.

67 lines
2.4 KiB

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