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.

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