[cleanup] Make more playlist entries lazy (#11763)
[yt-dlp.git] / yt_dlp / extractor / beacon.py
blobae47687cc8850029d004fc64002d9110fe290a4d
1 import json
3 from .common import InfoExtractor
4 from ..utils import (
5 ExtractorError,
6 parse_iso8601,
7 traverse_obj,
11 class BeaconTvIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?beacon\.tv/content/(?P<id>[\w-]+)'
14 _TESTS = [{
15 'url': 'https://beacon.tv/content/welcome-to-beacon',
16 'md5': 'b3f5932d437f288e662f10f3bfc5bd04',
17 'info_dict': {
18 'id': 'welcome-to-beacon',
19 'ext': 'mp4',
20 'upload_date': '20240509',
21 'description': 'md5:ea2bd32e71acf3f9fca6937412cc3563',
22 'thumbnail': 'https://cdn.jwplayer.com/v2/media/I4CkkEvN/poster.jpg?width=720',
23 'title': 'Your home for Critical Role!',
24 'timestamp': 1715227200,
25 'duration': 105.494,
27 }, {
28 'url': 'https://beacon.tv/content/re-slayers-take-trailer',
29 'md5': 'd879b091485dbed2245094c8152afd89',
30 'info_dict': {
31 'id': 're-slayers-take-trailer',
32 'ext': 'mp4',
33 'title': 'The Re-Slayer’s Take | Official Trailer',
34 'timestamp': 1715189040,
35 'upload_date': '20240508',
36 'duration': 53.249,
37 'thumbnail': 'https://cdn.jwplayer.com/v2/media/PW5ApIw3/poster.jpg?width=720',
41 def _real_extract(self, url):
42 video_id = self._match_id(url)
43 webpage = self._download_webpage(url, video_id)
45 content_data = traverse_obj(self._search_nextjs_data(webpage, video_id), (
46 'props', 'pageProps', '__APOLLO_STATE__',
47 lambda k, v: k.startswith('Content:') and v['slug'] == video_id, any))
48 if not content_data:
49 raise ExtractorError('Failed to extract content data')
51 jwplayer_data = traverse_obj(content_data, (
52 (('contentVideo', 'video', 'videoData'),
53 ('contentPodcast', 'podcast', 'audioData')), {json.loads}, {dict}, any))
54 if not jwplayer_data:
55 if content_data.get('contentType') not in ('videoPodcast', 'video', 'podcast'):
56 raise ExtractorError('Content is not a video/podcast', expected=True)
57 if traverse_obj(content_data, ('contentTier', '__ref')) != 'MemberTier:65b258d178f89be87b4dc0a4':
58 self.raise_login_required('This video/podcast is for members only')
59 raise ExtractorError('Failed to extract content')
61 return {
62 **self._parse_jwplayer_data(jwplayer_data, video_id),
63 **traverse_obj(content_data, {
64 'title': ('title', {str}),
65 'description': ('description', {str}),
66 'timestamp': ('publishedAt', {parse_iso8601}),
67 }),