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.2 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_urlparse,
  6. compat_urllib_parse,
  7. xpath_with_ns,
  8. )
  9. class InternetVideoArchiveIE(InfoExtractor):
  10. _VALID_URL = r'https?://video\.internetvideoarchive\.net/flash/players/.*?\?.*?publishedid.*?'
  11. _TEST = {
  12. 'url': 'http://video.internetvideoarchive.net/flash/players/flashconfiguration.aspx?customerid=69249&publishedid=452693&playerid=247',
  13. 'info_dict': {
  14. 'id': '452693',
  15. 'ext': 'mp4',
  16. 'title': 'SKYFALL',
  17. 'description': '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. 'duration': 149,
  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 = self._download_xml(url, video_id,
  39. 'Downloading flash configuration')
  40. file_url = flashconfiguration.find('file').text
  41. file_url = file_url.replace('/playlist.aspx', '/mrssplaylist.aspx')
  42. # Replace some of the parameters in the query to get the best quality
  43. # and http links (no m3u8 manifests)
  44. file_url = re.sub(r'(?<=\?)(.+)$',
  45. lambda m: self._clean_query(m.group()),
  46. file_url)
  47. info = self._download_xml(file_url, video_id,
  48. 'Downloading video info')
  49. item = info.find('channel/item')
  50. def _bp(p):
  51. return xpath_with_ns(p,
  52. {'media': 'http://search.yahoo.com/mrss/',
  53. 'jwplayer': 'http://developer.longtailvideo.com/trac/wiki/FlashFormats'})
  54. formats = []
  55. for content in item.findall(_bp('media:group/media:content')):
  56. attr = content.attrib
  57. f_url = attr['url']
  58. width = int(attr['width'])
  59. bitrate = int(attr['bitrate'])
  60. format_id = '%d-%dk' % (width, bitrate)
  61. formats.append({
  62. 'format_id': format_id,
  63. 'url': f_url,
  64. 'width': width,
  65. 'tbr': bitrate,
  66. })
  67. self._sort_formats(formats)
  68. return {
  69. 'id': video_id,
  70. 'title': item.find('title').text,
  71. 'formats': formats,
  72. 'thumbnail': item.find(_bp('media:thumbnail')).attrib['url'],
  73. 'description': item.find('description').text,
  74. 'duration': int(attr['duration']),
  75. }