]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/openrec.py
1 from .common
import InfoExtractor
11 from ..compat
import compat_str
14 class OpenRecBaseIE(InfoExtractor
):
15 def _extract_pagestore(self
, webpage
, video_id
):
16 return self
._parse
_json
(
17 self
._search
_regex
(r
'(?m)window\.pageStore\s*=\s*(\{.+?\});$', webpage
, 'window.pageStore'), video_id
)
19 def _expand_media(self
, video_id
, media
):
20 for name
, m3u8_url
in (media
or {}).items():
23 yield from self
._extract
_m
3u8_formats
(
24 m3u8_url
, video_id
, ext
='mp4', m3u8_id
=name
)
26 def _extract_movie(self
, webpage
, video_id
, name
, is_live
):
27 window_stores
= self
._extract
_pagestore
(webpage
, video_id
)
29 # extract all three important data (most of data are duplicated each other, but slightly different!)
30 traverse_obj(window_stores
, ('v8', 'state', 'movie'), expected_type
=dict),
31 traverse_obj(window_stores
, ('v8', 'movie'), expected_type
=dict),
32 traverse_obj(window_stores
, 'movieStore', expected_type
=dict),
34 if not any(movie_stores
):
35 raise ExtractorError(f
'Failed to extract {name} info')
37 formats
= list(self
._expand
_media
(video_id
, get_first(movie_stores
, 'media')))
38 if not formats
and is_live
:
39 # archived livestreams
40 cookies
= self
._get
_cookies
('https://www.openrec.tv/')
41 detail
= self
._download
_json
(
42 f
'https://apiv5.openrec.tv/api/v5/movies/{video_id}/detail', video_id
,
44 'Origin': 'https://www.openrec.tv',
45 'Referer': 'https://www.openrec.tv/',
46 'access-token': try_get(cookies
, lambda x
: x
.get('access_token').value
),
47 'uuid': try_get(cookies
, lambda x
: x
.get('uuid').value
),
49 new_media
= traverse_obj(detail
, ('data', 'items', ..., 'media'), get_all
=False)
50 formats
= list(self
._expand
_media
(video_id
, new_media
))
53 self
._sort
_formats
(formats
)
57 'title': get_first(movie_stores
, 'title'),
58 'description': get_first(movie_stores
, 'introduction'),
59 'thumbnail': get_first(movie_stores
, 'thumbnailUrl'),
61 'uploader': get_first(movie_stores
, ('channel', 'user', 'name')),
62 'uploader_id': get_first(movie_stores
, ('channel', 'user', 'id')),
63 'timestamp': int_or_none(get_first(movie_stores
, ['publishedAt', 'time']), scale
=1000) or unified_timestamp(get_first(movie_stores
, 'publishedAt')),
68 class OpenRecIE(OpenRecBaseIE
):
70 _VALID_URL
= r
'https?://(?:www\.)?openrec\.tv/live/(?P<id>[^/]+)'
72 'url': 'https://www.openrec.tv/live/2p8v31qe4zy',
73 'only_matching': True,
75 'url': 'https://www.openrec.tv/live/wez93eqvjzl',
76 'only_matching': True,
79 def _real_extract(self
, url
):
80 video_id
= self
._match
_id
(url
)
81 webpage
= self
._download
_webpage
(f
'https://www.openrec.tv/live/{video_id}', video_id
)
83 return self
._extract
_movie
(webpage
, video_id
, 'live', True)
86 class OpenRecCaptureIE(OpenRecBaseIE
):
87 IE_NAME
= 'openrec:capture'
88 _VALID_URL
= r
'https?://(?:www\.)?openrec\.tv/capture/(?P<id>[^/]+)'
90 'url': 'https://www.openrec.tv/capture/l9nk2x4gn14',
91 'only_matching': True,
93 'url': 'https://www.openrec.tv/capture/mldjr82p7qk',
96 'title': 'たいじの恥ずかしい英語力',
97 'uploader': 'たいちゃんねる',
98 'uploader_id': 'Yaritaiji',
99 'upload_date': '20210803',
103 def _real_extract(self
, url
):
104 video_id
= self
._match
_id
(url
)
105 webpage
= self
._download
_webpage
(f
'https://www.openrec.tv/capture/{video_id}', video_id
)
107 window_stores
= self
._extract
_pagestore
(webpage
, video_id
)
108 movie_store
= window_stores
.get('movie')
110 capture_data
= window_stores
.get('capture')
112 raise ExtractorError('Cannot extract title')
114 formats
= self
._extract
_m
3u8_formats
(
115 capture_data
.get('source'), video_id
, ext
='mp4')
116 self
._sort
_formats
(formats
)
120 'title': capture_data
.get('title'),
121 'thumbnail': capture_data
.get('thumbnailUrl'),
123 'timestamp': unified_timestamp(traverse_obj(movie_store
, 'createdAt', expected_type
=compat_str
)),
124 'uploader': traverse_obj(movie_store
, ('channel', 'name'), expected_type
=compat_str
),
125 'uploader_id': traverse_obj(movie_store
, ('channel', 'id'), expected_type
=compat_str
),
126 'upload_date': unified_strdate(capture_data
.get('createdAt')),
130 class OpenRecMovieIE(OpenRecBaseIE
):
131 IE_NAME
= 'openrec:movie'
132 _VALID_URL
= r
'https?://(?:www\.)?openrec\.tv/movie/(?P<id>[^/]+)'
134 'url': 'https://www.openrec.tv/movie/nqz5xl5km8v',
137 'title': '限定コミュニティ(Discord)参加方法ご説明動画',
138 'description': 'md5:ebd563e5f5b060cda2f02bf26b14d87f',
139 'thumbnail': r
're:https://.+',
140 'uploader': 'タイキとカズヒロ',
141 'uploader_id': 'taiki_to_kazuhiro',
142 'timestamp': 1638856800,
146 def _real_extract(self
, url
):
147 video_id
= self
._match
_id
(url
)
148 webpage
= self
._download
_webpage
(f
'https://www.openrec.tv/movie/{video_id}', video_id
)
150 return self
._extract
_movie
(webpage
, video_id
, 'movie', False)