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.

100 lines
3.7 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..compat import (
  4. compat_parse_qs,
  5. compat_urlparse,
  6. )
  7. from ..utils import (
  8. determine_ext,
  9. int_or_none,
  10. xpath_text,
  11. )
  12. class InternetVideoArchiveIE(InfoExtractor):
  13. _VALID_URL = r'https?://video\.internetvideoarchive\.net/(?:player|flash/players)/.*?\?.*?publishedid.*?'
  14. _TEST = {
  15. 'url': 'http://video.internetvideoarchive.net/player/6/configuration.ashx?customerid=69249&publishedid=194487&reporttag=vdbetatitle&playerid=641&autolist=0&domain=www.videodetective.com&maxrate=high&minrate=low&socialplayer=false',
  16. 'info_dict': {
  17. 'id': '194487',
  18. 'ext': 'mp4',
  19. 'title': 'KICK-ASS 2',
  20. 'description': 'md5:c189d5b7280400630a1d3dd17eaa8d8a',
  21. },
  22. 'params': {
  23. # m3u8 download
  24. 'skip_download': True,
  25. },
  26. }
  27. @staticmethod
  28. def _build_json_url(query):
  29. return 'http://video.internetvideoarchive.net/player/6/configuration.ashx?' + query
  30. @staticmethod
  31. def _build_xml_url(query):
  32. return 'http://video.internetvideoarchive.net/flash/players/flashconfiguration.aspx?' + query
  33. def _real_extract(self, url):
  34. query = compat_urlparse.urlparse(url).query
  35. query_dic = compat_parse_qs(query)
  36. video_id = query_dic['publishedid'][0]
  37. if '/player/' in url:
  38. configuration = self._download_json(url, video_id)
  39. # There are multiple videos in the playlist whlie only the first one
  40. # matches the video played in browsers
  41. video_info = configuration['playlist'][0]
  42. title = video_info['title']
  43. formats = []
  44. for source in video_info['sources']:
  45. file_url = source['file']
  46. if determine_ext(file_url) == 'm3u8':
  47. m3u8_formats = self._extract_m3u8_formats(
  48. file_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False)
  49. if m3u8_formats:
  50. formats.extend(m3u8_formats)
  51. file_url = m3u8_formats[0]['url']
  52. formats.extend(self._extract_f4m_formats(
  53. file_url.replace('.m3u8', '.f4m'),
  54. video_id, f4m_id='hds', fatal=False))
  55. formats.extend(self._extract_mpd_formats(
  56. file_url.replace('.m3u8', '.mpd'),
  57. video_id, mpd_id='dash', fatal=False))
  58. else:
  59. a_format = {
  60. 'url': file_url,
  61. }
  62. if source.get('label') and source['label'][-4:] == ' kbs':
  63. tbr = int_or_none(source['label'][:-4])
  64. a_format.update({
  65. 'tbr': tbr,
  66. 'format_id': 'http-%d' % tbr,
  67. })
  68. formats.append(a_format)
  69. self._sort_formats(formats)
  70. description = video_info.get('description')
  71. thumbnail = video_info.get('image')
  72. else:
  73. configuration = self._download_xml(url, video_id)
  74. formats = [{
  75. 'url': xpath_text(configuration, './file', 'file URL', fatal=True),
  76. }]
  77. thumbnail = xpath_text(configuration, './image', 'thumbnail')
  78. title = 'InternetVideoArchive video %s' % video_id
  79. description = None
  80. return {
  81. 'id': video_id,
  82. 'title': title,
  83. 'formats': formats,
  84. 'thumbnail': thumbnail,
  85. 'description': description,
  86. }