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.

81 lines
3.1 KiB

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