]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/stacommu.py
[ie/theatercomplextown] Add extractors (#8560)
[yt-dlp.git] / yt_dlp / extractor / stacommu.py
1 import time
2
3 from .wrestleuniverse import WrestleUniverseBaseIE
4 from ..utils import (
5 int_or_none,
6 traverse_obj,
7 url_or_none,
8 )
9
10
11 class StacommuBaseIE(WrestleUniverseBaseIE):
12 _NETRC_MACHINE = 'stacommu'
13 _API_HOST = 'api.stacommu.jp'
14 _LOGIN_QUERY = {'key': 'AIzaSyCR9czxhH2eWuijEhTNWBZ5MCcOYEUTAhg'}
15 _LOGIN_HEADERS = {
16 'Accept': '*/*',
17 'Content-Type': 'application/json',
18 'X-Client-Version': 'Chrome/JsCore/9.9.4/FirebaseCore-web',
19 'Referer': 'https://www.stacommu.jp/',
20 'Origin': 'https://www.stacommu.jp',
21 }
22
23 @WrestleUniverseBaseIE._TOKEN.getter
24 def _TOKEN(self):
25 if self._REAL_TOKEN and self._TOKEN_EXPIRY <= int(time.time()):
26 self._refresh_token()
27
28 return self._REAL_TOKEN
29
30 def _get_formats(self, data, path, video_id=None):
31 if not traverse_obj(data, path) and not data.get('canWatch') and not self._TOKEN:
32 self.raise_login_required(method='password')
33 return super()._get_formats(data, path, video_id)
34
35 def _extract_hls_key(self, data, path, decrypt):
36 encryption_data = traverse_obj(data, path)
37 if traverse_obj(encryption_data, ('encryptType', {int})) == 0:
38 return None
39 return traverse_obj(encryption_data, {'key': ('key', {decrypt}), 'iv': ('iv', {decrypt})})
40
41 def _extract_vod(self, url):
42 video_id = self._match_id(url)
43 video_info = self._download_metadata(
44 url, video_id, 'ja', ('dehydratedState', 'queries', 0, 'state', 'data'))
45 hls_info, decrypt = self._call_encrypted_api(
46 video_id, ':watch', 'stream information', data={'method': 1})
47
48 return {
49 'id': video_id,
50 'formats': self._get_formats(hls_info, ('protocolHls', 'url', {url_or_none}), video_id),
51 'hls_aes': self._extract_hls_key(hls_info, 'protocolHls', decrypt),
52 **traverse_obj(video_info, {
53 'title': ('displayName', {str}),
54 'description': ('description', {str}),
55 'timestamp': ('watchStartTime', {int_or_none}),
56 'thumbnail': ('keyVisualUrl', {url_or_none}),
57 'cast': ('casts', ..., 'displayName', {str}),
58 'duration': ('duration', {int}),
59 }),
60 }
61
62 def _extract_ppv(self, url):
63 video_id = self._match_id(url)
64 video_info = self._call_api(video_id, msg='video information', query={'al': 'ja'}, auth=False)
65 hls_info, decrypt = self._call_encrypted_api(
66 video_id, ':watchArchive', 'stream information', data={'method': 1})
67
68 return {
69 'id': video_id,
70 'formats': self._get_formats(hls_info, ('hls', 'urls', ..., {url_or_none}), video_id),
71 'hls_aes': self._extract_hls_key(hls_info, 'hls', decrypt),
72 **traverse_obj(video_info, {
73 'title': ('displayName', {str}),
74 'timestamp': ('startTime', {int_or_none}),
75 'thumbnail': ('keyVisualUrl', {url_or_none}),
76 'duration': ('duration', {int_or_none}),
77 }),
78 }
79
80
81 class StacommuVODIE(StacommuBaseIE):
82 _VALID_URL = r'https?://www\.stacommu\.jp/(?:en/)?videos/episodes/(?P<id>[\da-zA-Z]+)'
83 _TESTS = [{
84 # not encrypted
85 'url': 'https://www.stacommu.jp/videos/episodes/aXcVKjHyAENEjard61soZZ',
86 'info_dict': {
87 'id': 'aXcVKjHyAENEjard61soZZ',
88 'ext': 'mp4',
89 'title': 'スタコミュAWARDの裏側、ほぼ全部見せます!〜晴れ舞台の直前ドキドキ編〜',
90 'description': 'md5:6400275c57ae75c06da36b06f96beb1c',
91 'timestamp': 1679652000,
92 'upload_date': '20230324',
93 'thumbnail': 'https://image.stacommu.jp/6eLobQan8PFtBoU4RL4uGg/6eLobQan8PFtBoU4RL4uGg',
94 'cast': 'count:11',
95 'duration': 250,
96 },
97 'params': {
98 'skip_download': 'm3u8',
99 },
100 }, {
101 # encrypted; requires a premium account
102 'url': 'https://www.stacommu.jp/videos/episodes/3hybMByUvzMEqndSeu5LpD',
103 'info_dict': {
104 'id': '3hybMByUvzMEqndSeu5LpD',
105 'ext': 'mp4',
106 'title': 'スタプラフェス2023〜裏側ほぼ全部見せます〜#10',
107 'description': 'md5:85494488ccf1dfa1934accdeadd7b340',
108 'timestamp': 1682506800,
109 'upload_date': '20230426',
110 'thumbnail': 'https://image.stacommu.jp/eMdXtEefR4kEyJJMpAFi7x/eMdXtEefR4kEyJJMpAFi7x',
111 'cast': 'count:55',
112 'duration': 312,
113 'hls_aes': {
114 'key': '6bbaf241b8e1fd9f59ecf546a70e4ae7',
115 'iv': '1fc9002a23166c3bb1d240b953d09de9',
116 },
117 },
118 'params': {
119 'skip_download': 'm3u8',
120 },
121 }, {
122 'url': 'https://www.stacommu.jp/en/videos/episodes/aXcVKjHyAENEjard61soZZ',
123 'only_matching': True,
124 }]
125
126 _API_PATH = 'videoEpisodes'
127
128 def _real_extract(self, url):
129 return self._extract_vod(url)
130
131
132 class StacommuLiveIE(StacommuBaseIE):
133 _VALID_URL = r'https?://www\.stacommu\.jp/(?:en/)?live/(?P<id>[\da-zA-Z]+)'
134 _TESTS = [{
135 'url': 'https://www.stacommu.jp/live/d2FJ3zLnndegZJCAEzGM3m',
136 'info_dict': {
137 'id': 'd2FJ3zLnndegZJCAEzGM3m',
138 'ext': 'mp4',
139 'title': '仲村悠菜 2023/05/04',
140 'timestamp': 1683195647,
141 'upload_date': '20230504',
142 'thumbnail': 'https://image.stacommu.jp/pHGF57SPEHE2ke83FS92FN/pHGF57SPEHE2ke83FS92FN',
143 'duration': 5322,
144 'hls_aes': {
145 'key': 'efbb3ec0b8246f61adf1764c5a51213a',
146 'iv': '80621d19a1f19167b64cedb415b05d1c',
147 },
148 },
149 'params': {
150 'skip_download': 'm3u8',
151 },
152 }, {
153 'url': 'https://www.stacommu.jp/en/live/d2FJ3zLnndegZJCAEzGM3m',
154 'only_matching': True,
155 }]
156
157 _API_PATH = 'events'
158
159 def _real_extract(self, url):
160 return self._extract_ppv(url)
161
162
163 class TheaterComplexTownBaseIE(StacommuBaseIE):
164 _NETRC_MACHINE = 'theatercomplextown'
165 _API_HOST = 'api.theater-complex.town'
166 _LOGIN_QUERY = {'key': 'AIzaSyAgNCqToaIz4a062EeIrkhI_xetVfAOrfc'}
167 _LOGIN_HEADERS = {
168 'Accept': '*/*',
169 'Content-Type': 'application/json',
170 'X-Client-Version': 'Chrome/JsCore/9.23.0/FirebaseCore-web',
171 'Referer': 'https://www.theater-complex.town/',
172 'Origin': 'https://www.theater-complex.town',
173 }
174
175
176 class TheaterComplexTownVODIE(TheaterComplexTownBaseIE):
177 _VALID_URL = r'https?://(?:www\.)?theater-complex\.town/(?:en/)?videos/episodes/(?P<id>\w+)'
178 IE_NAME = 'theatercomplextown:vod'
179 _TESTS = [{
180 'url': 'https://www.theater-complex.town/videos/episodes/hoxqidYNoAn7bP92DN6p78',
181 'info_dict': {
182 'id': 'hoxqidYNoAn7bP92DN6p78',
183 'ext': 'mp4',
184 'title': '演劇ドラフトグランプリ2023 劇団『恋のぼり』〜劇団名決定秘話ラジオ',
185 'description': 'md5:a7e2e9cf570379ea67fb630f345ff65d',
186 'cast': ['玉城 裕規', '石川 凌雅'],
187 'thumbnail': 'https://image.theater-complex.town/5URnXX6KCeDysuFrPkP38o/5URnXX6KCeDysuFrPkP38o',
188 'upload_date': '20231103',
189 'timestamp': 1699016400,
190 'duration': 868,
191 },
192 'params': {
193 'skip_download': 'm3u8',
194 },
195 }, {
196 'url': 'https://www.theater-complex.town/en/videos/episodes/6QT7XYwM9dJz5Gf9VB6K5y',
197 'only_matching': True,
198 }]
199
200 _API_PATH = 'videoEpisodes'
201
202 def _real_extract(self, url):
203 return self._extract_vod(url)
204
205
206 class TheaterComplexTownPPVIE(TheaterComplexTownBaseIE):
207 _VALID_URL = r'https?://(?:www\.)?theater-complex\.town/(?:en/)?ppv/(?P<id>\w+)'
208 IE_NAME = 'theatercomplextown:ppv'
209 _TESTS = [{
210 'url': 'https://www.theater-complex.town/ppv/wytW3X7khrjJBUpKuV3jen',
211 'info_dict': {
212 'id': 'wytW3X7khrjJBUpKuV3jen',
213 'ext': 'mp4',
214 'title': 'BREAK FREE STARS 11月5日(日)12:30千秋楽公演',
215 'thumbnail': 'https://image.theater-complex.town/5GWEB31JcTUfjtgdeV5t6o/5GWEB31JcTUfjtgdeV5t6o',
216 'upload_date': '20231105',
217 'timestamp': 1699155000,
218 'duration': 8378,
219 },
220 'params': {
221 'skip_download': 'm3u8',
222 },
223 }, {
224 'url': 'https://www.theater-complex.town/en/ppv/wytW3X7khrjJBUpKuV3jen',
225 'only_matching': True,
226 }]
227
228 _API_PATH = 'events'
229
230 def _real_extract(self, url):
231 return self._extract_ppv(url)