internetvideoarchive.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import json
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import parse_qs
  5. class InternetVideoArchiveIE(InfoExtractor):
  6. _VALID_URL = r'https?://video\.internetvideoarchive\.net/(?:player|flash/players)/.*?\?.*?publishedid.*?'
  7. _TEST = {
  8. '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',
  9. 'info_dict': {
  10. 'id': '194487',
  11. 'ext': 'mp4',
  12. 'title': 'Kick-Ass 2',
  13. 'description': 'md5:c189d5b7280400630a1d3dd17eaa8d8a',
  14. },
  15. 'params': {
  16. # m3u8 download
  17. 'skip_download': True,
  18. },
  19. }
  20. @staticmethod
  21. def _build_json_url(query):
  22. return 'http://video.internetvideoarchive.net/player/6/configuration.ashx?' + query
  23. def _real_extract(self, url):
  24. query = parse_qs(url)
  25. video_id = query['publishedid'][0]
  26. data = self._download_json(
  27. 'https://video.internetvideoarchive.net/videojs7/videojs7.ivasettings.ashx',
  28. video_id, data=json.dumps({
  29. 'customerid': query['customerid'][0],
  30. 'publishedid': video_id,
  31. }).encode())
  32. title = data['Title']
  33. formats = self._extract_m3u8_formats(
  34. data['VideoUrl'], video_id, 'mp4',
  35. 'm3u8_native', m3u8_id='hls', fatal=False)
  36. file_url = formats[0]['url']
  37. if '.ism/' in file_url:
  38. replace_url = lambda x: re.sub(r'\.ism/[^?]+', '.ism/' + x, file_url)
  39. formats.extend(self._extract_f4m_formats(
  40. replace_url('.f4m'), video_id, f4m_id='hds', fatal=False))
  41. formats.extend(self._extract_mpd_formats(
  42. replace_url('.mpd'), video_id, mpd_id='dash', fatal=False))
  43. formats.extend(self._extract_ism_formats(
  44. replace_url('Manifest'), video_id, ism_id='mss', fatal=False))
  45. return {
  46. 'id': video_id,
  47. 'title': title,
  48. 'formats': formats,
  49. 'thumbnail': data.get('PosterUrl'),
  50. 'description': data.get('Description'),
  51. }