]>
Commit | Line | Data |
---|---|---|
af1fd12f | 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 | ||
42 | class StacommuVODIE(StacommuBaseIE): | |
43 | _VALID_URL = r'https?://www\.stacommu\.jp/videos/episodes/(?P<id>[\da-zA-Z]+)' | |
44 | _TESTS = [{ | |
45 | # not encrypted | |
46 | 'url': 'https://www.stacommu.jp/videos/episodes/aXcVKjHyAENEjard61soZZ', | |
47 | 'info_dict': { | |
48 | 'id': 'aXcVKjHyAENEjard61soZZ', | |
49 | 'ext': 'mp4', | |
50 | 'title': 'スタコミュAWARDの裏側、ほぼ全部見せます!〜晴れ舞台の直前ドキドキ編〜', | |
51 | 'description': 'md5:6400275c57ae75c06da36b06f96beb1c', | |
52 | 'timestamp': 1679652000, | |
53 | 'upload_date': '20230324', | |
54 | 'thumbnail': 'https://image.stacommu.jp/6eLobQan8PFtBoU4RL4uGg/6eLobQan8PFtBoU4RL4uGg', | |
55 | 'cast': 'count:11', | |
56 | 'duration': 250, | |
57 | }, | |
58 | 'params': { | |
59 | 'skip_download': 'm3u8', | |
60 | }, | |
61 | }, { | |
62 | # encrypted; requires a premium account | |
63 | 'url': 'https://www.stacommu.jp/videos/episodes/3hybMByUvzMEqndSeu5LpD', | |
64 | 'info_dict': { | |
65 | 'id': '3hybMByUvzMEqndSeu5LpD', | |
66 | 'ext': 'mp4', | |
67 | 'title': 'スタプラフェス2023〜裏側ほぼ全部見せます〜#10', | |
68 | 'description': 'md5:85494488ccf1dfa1934accdeadd7b340', | |
69 | 'timestamp': 1682506800, | |
70 | 'upload_date': '20230426', | |
71 | 'thumbnail': 'https://image.stacommu.jp/eMdXtEefR4kEyJJMpAFi7x/eMdXtEefR4kEyJJMpAFi7x', | |
72 | 'cast': 'count:55', | |
73 | 'duration': 312, | |
74 | 'hls_aes': { | |
75 | 'key': '6bbaf241b8e1fd9f59ecf546a70e4ae7', | |
76 | 'iv': '1fc9002a23166c3bb1d240b953d09de9', | |
77 | }, | |
78 | }, | |
79 | 'params': { | |
80 | 'skip_download': 'm3u8', | |
81 | }, | |
82 | }] | |
83 | ||
84 | _API_PATH = 'videoEpisodes' | |
85 | ||
86 | def _real_extract(self, url): | |
87 | video_id = self._match_id(url) | |
88 | video_info = self._download_metadata( | |
89 | url, video_id, 'ja', ('dehydratedState', 'queries', 0, 'state', 'data')) | |
90 | hls_info, decrypt = self._call_encrypted_api( | |
91 | video_id, ':watch', 'stream information', data={'method': 1}) | |
92 | ||
93 | return { | |
94 | 'id': video_id, | |
95 | 'formats': self._get_formats(hls_info, ('protocolHls', 'url', {url_or_none}), video_id), | |
96 | 'hls_aes': self._extract_hls_key(hls_info, 'protocolHls', decrypt), | |
97 | **traverse_obj(video_info, { | |
98 | 'title': ('displayName', {str}), | |
99 | 'description': ('description', {str}), | |
100 | 'timestamp': ('watchStartTime', {int_or_none}), | |
101 | 'thumbnail': ('keyVisualUrl', {url_or_none}), | |
102 | 'cast': ('casts', ..., 'displayName', {str}), | |
103 | 'duration': ('duration', {int}), | |
104 | }), | |
105 | } | |
106 | ||
107 | ||
108 | class StacommuLiveIE(StacommuBaseIE): | |
109 | _VALID_URL = r'https?://www\.stacommu\.jp/live/(?P<id>[\da-zA-Z]+)' | |
110 | _TESTS = [{ | |
111 | 'url': 'https://www.stacommu.jp/live/d2FJ3zLnndegZJCAEzGM3m', | |
112 | 'info_dict': { | |
113 | 'id': 'd2FJ3zLnndegZJCAEzGM3m', | |
114 | 'ext': 'mp4', | |
115 | 'title': '仲村悠菜 2023/05/04', | |
116 | 'timestamp': 1683195647, | |
117 | 'upload_date': '20230504', | |
118 | 'thumbnail': 'https://image.stacommu.jp/pHGF57SPEHE2ke83FS92FN/pHGF57SPEHE2ke83FS92FN', | |
119 | 'duration': 5322, | |
120 | 'hls_aes': { | |
121 | 'key': 'efbb3ec0b8246f61adf1764c5a51213a', | |
122 | 'iv': '80621d19a1f19167b64cedb415b05d1c', | |
123 | }, | |
124 | }, | |
125 | 'params': { | |
126 | 'skip_download': 'm3u8', | |
127 | }, | |
128 | }] | |
129 | ||
130 | _API_PATH = 'events' | |
131 | ||
132 | def _real_extract(self, url): | |
133 | video_id = self._match_id(url) | |
134 | video_info = self._call_api(video_id, msg='video information', query={'al': 'ja'}, auth=False) | |
135 | hls_info, decrypt = self._call_encrypted_api( | |
136 | video_id, ':watchArchive', 'stream information', data={'method': 1}) | |
137 | ||
138 | return { | |
139 | 'id': video_id, | |
140 | 'formats': self._get_formats(hls_info, ('hls', 'urls', ..., {url_or_none}), video_id), | |
141 | 'hls_aes': self._extract_hls_key(hls_info, 'hls', decrypt), | |
142 | **traverse_obj(video_info, { | |
143 | 'title': ('displayName', {str}), | |
144 | 'timestamp': ('startTime', {int_or_none}), | |
145 | 'thumbnail': ('keyVisualUrl', {url_or_none}), | |
146 | 'duration': ('duration', {int_or_none}), | |
147 | }), | |
148 | } |