cozytv.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from .common import InfoExtractor
  2. from ..utils import unified_strdate
  3. class CozyTVIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:www\.)?cozy\.tv/(?P<uploader>[^/]+)/replays/(?P<id>[^/$#&?]+)'
  5. _TESTS = [{
  6. 'url': 'https://cozy.tv/beardson/replays/2021-11-19_1',
  7. 'info_dict': {
  8. 'id': 'beardson-2021-11-19_1',
  9. 'ext': 'mp4',
  10. 'title': 'pokemon pt2',
  11. 'uploader': 'beardson',
  12. 'upload_date': '20211119',
  13. 'was_live': True,
  14. 'duration': 7981,
  15. },
  16. 'params': {'skip_download': True},
  17. }]
  18. def _real_extract(self, url):
  19. uploader, date = self._match_valid_url(url).groups()
  20. video_id = f'{uploader}-{date}'
  21. data_json = self._download_json(f'https://api.cozy.tv/cache/{uploader}/replay/{date}', video_id)
  22. formats, subtitles = self._extract_m3u8_formats_and_subtitles(
  23. f'https://cozycdn.foxtrotstream.xyz/replays/{uploader}/{date}/index.m3u8', video_id, ext='mp4')
  24. return {
  25. 'id': video_id,
  26. 'title': data_json.get('title'),
  27. 'uploader': data_json.get('user') or uploader,
  28. 'upload_date': unified_strdate(data_json.get('date')),
  29. 'was_live': True,
  30. 'duration': data_json.get('duration'),
  31. 'formats': formats,
  32. 'subtitles': subtitles,
  33. }