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.

87 lines
3.4 KiB

  1. import re
  2. import xml.etree.ElementTree
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_urlparse,
  6. compat_urllib_parse,
  7. xpath_with_ns,
  8. determine_ext,
  9. )
  10. class InternetVideoArchiveIE(InfoExtractor):
  11. _VALID_URL = r'https?://video\.internetvideoarchive\.net/flash/players/.*?\?.*?publishedid.*?'
  12. _TEST = {
  13. u'url': u'http://video.internetvideoarchive.net/flash/players/flashconfiguration.aspx?customerid=69249&publishedid=452693&playerid=247',
  14. u'file': u'452693.mp4',
  15. u'info_dict': {
  16. u'title': u'SKYFALL',
  17. 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.',
  18. u'duration': 156,
  19. },
  20. }
  21. @staticmethod
  22. def _build_url(query):
  23. return 'http://video.internetvideoarchive.net/flash/players/flashconfiguration.aspx?' + query
  24. @staticmethod
  25. def _clean_query(query):
  26. NEEDED_ARGS = ['publishedid', 'customerid']
  27. query_dic = compat_urlparse.parse_qs(query)
  28. cleaned_dic = dict((k,v[0]) for (k,v) in query_dic.items() if k in NEEDED_ARGS)
  29. # Other player ids return m3u8 urls
  30. cleaned_dic['playerid'] = '247'
  31. cleaned_dic['videokbrate'] = '100000'
  32. return compat_urllib_parse.urlencode(cleaned_dic)
  33. def _real_extract(self, url):
  34. query = compat_urlparse.urlparse(url).query
  35. query_dic = compat_urlparse.parse_qs(query)
  36. video_id = query_dic['publishedid'][0]
  37. url = self._build_url(query)
  38. flashconfiguration_xml = self._download_webpage(url, video_id,
  39. u'Downloading flash configuration')
  40. flashconfiguration = xml.etree.ElementTree.fromstring(flashconfiguration_xml.encode('utf-8'))
  41. file_url = flashconfiguration.find('file').text
  42. file_url = file_url.replace('/playlist.aspx', '/mrssplaylist.aspx')
  43. # Replace some of the parameters in the query to get the best quality
  44. # and http links (no m3u8 manifests)
  45. file_url = re.sub(r'(?<=\?)(.+)$',
  46. lambda m: self._clean_query(m.group()),
  47. file_url)
  48. info_xml = self._download_webpage(file_url, video_id,
  49. u'Downloading video info')
  50. info = xml.etree.ElementTree.fromstring(info_xml.encode('utf-8'))
  51. item = info.find('channel/item')
  52. def _bp(p):
  53. return xpath_with_ns(p,
  54. {'media': 'http://search.yahoo.com/mrss/',
  55. 'jwplayer': 'http://developer.longtailvideo.com/trac/wiki/FlashFormats'})
  56. formats = []
  57. for content in item.findall(_bp('media:group/media:content')):
  58. attr = content.attrib
  59. f_url = attr['url']
  60. formats.append({
  61. 'url': f_url,
  62. 'ext': determine_ext(f_url),
  63. 'width': int(attr['width']),
  64. 'bitrate': int(attr['bitrate']),
  65. })
  66. formats = sorted(formats, key=lambda f: f['bitrate'])
  67. info = {
  68. 'id': video_id,
  69. 'title': item.find('title').text,
  70. 'formats': formats,
  71. 'thumbnail': item.find(_bp('media:thumbnail')).attrib['url'],
  72. 'description': item.find('description').text,
  73. 'duration': int(attr['duration']),
  74. }
  75. # TODO: Remove when #980 has been merged
  76. info.update(formats[-1])
  77. return info