minoto.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. int_or_none,
  4. parse_codecs,
  5. )
  6. class MinotoIE(InfoExtractor):
  7. _VALID_URL = r'(?:minoto:|https?://(?:play|iframe|embed)\.minoto-video\.com/(?P<player_id>[0-9]+)/)(?P<id>[a-zA-Z0-9]+)'
  8. def _real_extract(self, url):
  9. mobj = self._match_valid_url(url)
  10. player_id = mobj.group('player_id') or '1'
  11. video_id = mobj.group('id')
  12. video_data = self._download_json(f'http://play.minoto-video.com/{player_id}/{video_id}.js', video_id)
  13. video_metadata = video_data['video-metadata']
  14. formats = []
  15. for fmt in video_data['video-files']:
  16. fmt_url = fmt.get('url')
  17. if not fmt_url:
  18. continue
  19. container = fmt.get('container')
  20. if container == 'hls':
  21. formats.extend(self._extract_m3u8_formats(fmt_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  22. else:
  23. fmt_profile = fmt.get('profile') or {}
  24. formats.append({
  25. 'format_id': fmt_profile.get('name-short'),
  26. 'format_note': fmt_profile.get('name'),
  27. 'url': fmt_url,
  28. 'container': container,
  29. 'tbr': int_or_none(fmt.get('bitrate')),
  30. 'filesize': int_or_none(fmt.get('filesize')),
  31. 'width': int_or_none(fmt.get('width')),
  32. 'height': int_or_none(fmt.get('height')),
  33. **parse_codecs(fmt.get('codecs')),
  34. })
  35. return {
  36. 'id': video_id,
  37. 'title': video_metadata['title'],
  38. 'description': video_metadata.get('description'),
  39. 'thumbnail': video_metadata.get('video-poster', {}).get('url'),
  40. 'formats': formats,
  41. }