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.

91 lines
3.1 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. formats = []
  43. for source in video_info['sources']:
  44. file_url = source['file']
  45. if determine_ext(file_url) == 'm3u8':
  46. formats.extend(self._extract_m3u8_formats(
  47. file_url, video_id, ext='mp4', m3u8_id='hls'))
  48. else:
  49. a_format = {
  50. 'url': file_url,
  51. }
  52. if source.get('label') and source['label'][-4:] == ' kbs':
  53. tbr = int_or_none(source['label'][:-4])
  54. a_format.update({
  55. 'tbr': tbr,
  56. 'format_id': 'http-%d' % tbr,
  57. })
  58. formats.append(a_format)
  59. self._sort_formats(formats)
  60. title = video_info['title']
  61. description = video_info.get('description')
  62. thumbnail = video_info.get('image')
  63. else:
  64. configuration = self._download_xml(url, video_id)
  65. formats = [{
  66. 'url': xpath_text(configuration, './file', 'file URL', fatal=True),
  67. }]
  68. thumbnail = xpath_text(configuration, './image', 'thumbnail')
  69. title = 'InternetVideoArchive video %s' % video_id
  70. description = None
  71. return {
  72. 'id': video_id,
  73. 'title': title,
  74. 'formats': formats,
  75. 'thumbnail': thumbnail,
  76. 'description': description,
  77. }