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.

71 lines
2.7 KiB

  1. import re
  2. import xml.etree.ElementTree
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_urlparse,
  6. xpath_with_ns,
  7. determine_ext,
  8. )
  9. class InternetVideoArchiveIE(InfoExtractor):
  10. _VALID_URL = r'https?://video\.internetvideoarchive\.net/flash/players/.*?\?.*?publishedid.*?'
  11. _TEST = {
  12. u'url': u'http://video.internetvideoarchive.net/flash/players/flashconfiguration.aspx?customerid=69249&publishedid=452693&playerid=247',
  13. u'file': u'452693.mp4',
  14. u'info_dict': {
  15. u'title': u'SKYFALL',
  16. u'description': u'In SKYFALL, Bond\'s loyalty to M is tested as her past comes back to haunt her. As MI6 comes under attack, 007 must track down and destroy the threat, no matter how personal the cost.',
  17. u'duration': 156,
  18. },
  19. }
  20. @staticmethod
  21. def _build_url(query):
  22. return 'http://video.internetvideoarchive.net/flash/players/flashconfiguration.aspx?' + query
  23. def _real_extract(self, url):
  24. query = compat_urlparse.urlparse(url).query
  25. query_dic = compat_urlparse.parse_qs(query)
  26. video_id = query_dic['publishedid'][0]
  27. url = self._build_url(query)
  28. flashconfiguration_xml = self._download_webpage(url, video_id,
  29. u'Downloading flash configuration')
  30. flashconfiguration = xml.etree.ElementTree.fromstring(flashconfiguration_xml.encode('utf-8'))
  31. file_url = flashconfiguration.find('file').text
  32. file_url = file_url.replace('/playlist.aspx', '/mrssplaylist.aspx')
  33. info_xml = self._download_webpage(file_url, video_id,
  34. u'Downloading video info')
  35. info = xml.etree.ElementTree.fromstring(info_xml.encode('utf-8'))
  36. item = info.find('channel/item')
  37. def _bp(p):
  38. return xpath_with_ns(p,
  39. {'media': 'http://search.yahoo.com/mrss/',
  40. 'jwplayer': 'http://developer.longtailvideo.com/trac/wiki/FlashFormats'})
  41. formats = []
  42. for content in item.findall(_bp('media:group/media:content')):
  43. attr = content.attrib
  44. f_url = attr['url']
  45. formats.append({
  46. 'url': f_url,
  47. 'ext': determine_ext(f_url),
  48. 'width': int(attr['width']),
  49. 'bitrate': int(attr['bitrate']),
  50. })
  51. formats = sorted(formats, key=lambda f: f['bitrate'])
  52. info = {
  53. 'id': video_id,
  54. 'title': item.find('title').text,
  55. 'formats': formats,
  56. 'thumbnail': item.find(_bp('media:thumbnail')).attrib['url'],
  57. 'description': item.find('description').text,
  58. 'duration': int(attr['duration']),
  59. }
  60. # TODO: Remove when #980 has been merged
  61. info.update(formats[-1])
  62. return info