stacommu.py 8.8 KB

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