daystar.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from .common import InfoExtractor
  2. from ..utils import js_to_json, urljoin
  3. class DaystarClipIE(InfoExtractor):
  4. IE_NAME = 'daystar:clip'
  5. _VALID_URL = r'https?://player\.daystar\.tv/(?P<id>\w+)'
  6. _TESTS = [{
  7. 'url': 'https://player.daystar.tv/0MTO2ITM',
  8. 'info_dict': {
  9. 'id': '0MTO2ITM',
  10. 'ext': 'mp4',
  11. 'title': 'The Dark World of COVID Pt. 1 | Aaron Siri',
  12. 'description': 'a420d320dda734e5f29458df3606c5f4',
  13. 'thumbnail': r're:^https?://.+\.jpg',
  14. },
  15. }]
  16. def _real_extract(self, url):
  17. video_id = self._match_id(url)
  18. webpage = self._download_webpage(url, video_id)
  19. src_iframe = self._search_regex(r'\<iframe[^>]+src="([^"]+)"', webpage, 'src iframe')
  20. webpage_iframe = self._download_webpage(
  21. src_iframe.replace('player.php', 'config2.php'), video_id, headers={'Referer': src_iframe})
  22. sources = self._parse_json(self._search_regex(
  23. r'sources\:\s*(\[.*?\])', webpage_iframe, 'm3u8 source'), video_id, transform_source=js_to_json)
  24. formats, subtitles = [], {}
  25. for source in sources:
  26. file = source.get('file')
  27. if file and source.get('type') == 'm3u8':
  28. fmts, subs = self._extract_m3u8_formats_and_subtitles(
  29. urljoin('https://www.lightcast.com/embed/', file),
  30. video_id, 'mp4', fatal=False, headers={'Referer': src_iframe})
  31. formats.extend(fmts)
  32. subtitles = self._merge_subtitles(subtitles, subs)
  33. return {
  34. 'id': video_id,
  35. 'title': self._html_search_meta(['og:title', 'twitter:title'], webpage),
  36. 'description': self._html_search_meta(['og:description', 'twitter:description'], webpage),
  37. 'thumbnail': self._search_regex(r'image:\s*"([^"]+)', webpage_iframe, 'thumbnail'),
  38. 'formats': formats,
  39. 'subtitles': subtitles,
  40. }