Repository: yt-dlp/yt-dlp

Issue:
Support for Theater Complex Town
### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I *intentionally* remove or skip any mandatory\* field

### Checklist

- [X] I'm reporting a new site support request
- [X] I've verified that I'm running yt-dlp version **2023.10.13** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [X] I've checked that all provided URLs are playable in a browser with the same IP and same login details
- [X] I've checked that none of provided URLs [violate any copyrights](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-website-primarily-used-for-piracy) or contain any [DRM](https://en.wikipedia.org/wiki/Digital_rights_management) to the best of my knowledge
- [X] I've searched [known issues](https://github.com/yt-dlp/yt-dlp/issues/3766) and the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [X] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and am willing to share it if required

### Region

Global

### Example URLs

https://www.theater-complex.town/en/videos/episodes/tCapUr9VeyBpKbmuJZvvuD
https://www.theater-complex.town/en/ppv/vfxBGDZiog9qP9B9qgA2Je
https://www.theater-complex.town/en/ppv/wytW3X7khrjJBUpKuV3jen

### Provide a description that is worded well enough to be understood

Hi, I would like for support to be added for Theater Complex Town, if possible. It offers videos by membership subscription, VOD pay-per-view, and livestream pay-per-view (link to each example provided.) The videos play even when DRM is disabled in my browser, so I assume they do not use DRM. The site is available globally with an English version, but some of the UI is still in Japanese.

### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [x] If using API, add `'verbose': True` to `YoutubeDL` params instead
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
[debug] Command-line config: ['-vU', '--cookies-from-browser', 'firefox', 'https://www.theater-complex.town/en/videos/episodes/tCapUr9VeyBpKbmuJZvvuD']
Extracting cookies from firefox
[debug] Extracting cookies from: "C:\Users\JJ\AppData\Roaming\Mozilla\Firefox\Profiles\yeplvwe6.default-release\cookies.sqlite"
Extracted 1457 cookies from firefox
[debug] Encodings: locale cp1252, fs utf-8, pref cp1252, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version stable@2023.10.13 [b634ba742] (win_exe)
[debug] Python 3.8.10 (CPython AMD64 64bit) - Windows-10-10.0.19045-SP0 (OpenSSL 1.1.1k  25 Mar 2021)
[debug] exe versions: ffmpeg 2023-03-30-git-4d216654ca-essentials_build-www.gyan.dev (setts), ffprobe 2023-03-30-git-4d216654ca-essentials_build-www.gyan.dev
[debug] Optional libraries: Cryptodome-3.19.0, brotli-1.1.0, certifi-2023.07.22, mutagen-1.47.0, sqlite3-3.35.5, websockets-11.0.3
[debug] Proxy map: {}
[debug] Loaded 1890 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Available version: stable@2023.10.13, Current version: stable@2023.10.13
Current Build Hash: 13d6a04ef6678dc61cb6e2d42eb53e69486bd2f52b8e5d778db029ccd4c600b4
yt-dlp is up to date (stable@2023.10.13)
[generic] Extracting URL: https://www.theater-complex.town/en/videos/episodes/tCapUr9VeyBpKbmuJZvvuD
[generic] tCapUr9VeyBpKbmuJZvvuD: Downloading webpage
WARNING: [generic] Falling back on generic information extractor
[generic] tCapUr9VeyBpKbmuJZvvuD: Extracting information
[debug] Looking for embeds
ERROR: Unsupported URL: https://www.theater-complex.town/en/videos/episodes/tCapUr9VeyBpKbmuJZvvuD
Traceback (most recent call last):
  File "yt_dlp\YoutubeDL.py", line 1567, in wrapper
  File "yt_dlp\YoutubeDL.py", line 1702, in __extract_info
  File "yt_dlp\extractor\common.py", line 715, in extract
  File "yt_dlp\extractor\generic.py", line 2575, in _real_extract
yt_dlp.utils.UnsupportedError: Unsupported URL: https://www.theater-complex.town/en/videos/episodes/tCapUr9VeyBpKbmuJZvvuD
```



Discussion:
Note for devs: this site looks to be using the same type of API and HLS AES-128 key protocol as [wrestleuniverse](https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/extractor/wrestleuniverse.py), so the extractor can likely be subclassed from `WrestleUniverseBaseIE`. See also [StacommuBaseIE](https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/extractor/stacommu.py)

Resolving patch:
diff --git a/yt_dlp/extractor/_extractors.py b/yt_dlp/extractor/_extractors.py
--- a/yt_dlp/extractor/_extractors.py
+++ b/yt_dlp/extractor/_extractors.py
@@ -1902,6 +1902,8 @@
 from .stacommu import (
     StacommuLiveIE,
     StacommuVODIE,
+    TheaterComplexTownVODIE,
+    TheaterComplexTownPPVIE,
 )
 from .stanfordoc import StanfordOpenClassroomIE
 from .startv import StarTVIE
diff --git a/yt_dlp/extractor/stacommu.py b/yt_dlp/extractor/stacommu.py
--- a/yt_dlp/extractor/stacommu.py
+++ b/yt_dlp/extractor/stacommu.py
@@ -38,9 +38,48 @@ def _extract_hls_key(self, data, path, decrypt):
             return None
         return traverse_obj(encryption_data, {'key': ('key', {decrypt}), 'iv': ('iv', {decrypt})})
 
+    def _extract_vod(self, url):
+        video_id = self._match_id(url)
+        video_info = self._download_metadata(
+            url, video_id, 'ja', ('dehydratedState', 'queries', 0, 'state', 'data'))
+        hls_info, decrypt = self._call_encrypted_api(
+            video_id, ':watch', 'stream information', data={'method': 1})
+
+        return {
+            'id': video_id,
+            'formats': self._get_formats(hls_info, ('protocolHls', 'url', {url_or_none}), video_id),
+            'hls_aes': self._extract_hls_key(hls_info, 'protocolHls', decrypt),
+            **traverse_obj(video_info, {
+                'title': ('displayName', {str}),
+                'description': ('description', {str}),
+                'timestamp': ('watchStartTime', {int_or_none}),
+                'thumbnail': ('keyVisualUrl', {url_or_none}),
+                'cast': ('casts', ..., 'displayName', {str}),
+                'duration': ('duration', {int}),
+            }),
+        }
+
+    def _extract_ppv(self, url):
+        video_id = self._match_id(url)
+        video_info = self._call_api(video_id, msg='video information', query={'al': 'ja'}, auth=False)
+        hls_info, decrypt = self._call_encrypted_api(
+            video_id, ':watchArchive', 'stream information', data={'method': 1})
+
+        return {
+            'id': video_id,
+            'formats': self._get_formats(hls_info, ('hls', 'urls', ..., {url_or_none}), video_id),
+            'hls_aes': self._extract_hls_key(hls_info, 'hls', decrypt),
+            **traverse_obj(video_info, {
+                'title': ('displayName', {str}),
+                'timestamp': ('startTime', {int_or_none}),
+                'thumbnail': ('keyVisualUrl', {url_or_none}),
+                'duration': ('duration', {int_or_none}),
+            }),
+        }
+
 
 class StacommuVODIE(StacommuBaseIE):
-    _VALID_URL = r'https?://www\.stacommu\.jp/videos/episodes/(?P<id>[\da-zA-Z]+)'
+    _VALID_URL = r'https?://www\.stacommu\.jp/(?:en/)?videos/episodes/(?P<id>[\da-zA-Z]+)'
     _TESTS = [{
         # not encrypted
         'url': 'https://www.stacommu.jp/videos/episodes/aXcVKjHyAENEjard61soZZ',
@@ -79,34 +118,19 @@ class StacommuVODIE(StacommuBaseIE):
         'params': {
             'skip_download': 'm3u8',
         },
+    }, {
+        'url': 'https://www.stacommu.jp/en/videos/episodes/aXcVKjHyAENEjard61soZZ',
+        'only_matching': True,
     }]
 
     _API_PATH = 'videoEpisodes'
 
     def _real_extract(self, url):
-        video_id = self._match_id(url)
-        video_info = self._download_metadata(
-            url, video_id, 'ja', ('dehydratedState', 'queries', 0, 'state', 'data'))
-        hls_info, decrypt = self._call_encrypted_api(
-            video_id, ':watch', 'stream information', data={'method': 1})
-
-        return {
-            'id': video_id,
-            'formats': self._get_formats(hls_info, ('protocolHls', 'url', {url_or_none}), video_id),
-            'hls_aes': self._extract_hls_key(hls_info, 'protocolHls', decrypt),
-            **traverse_obj(video_info, {
-                'title': ('displayName', {str}),
-                'description': ('description', {str}),
-                'timestamp': ('watchStartTime', {int_or_none}),
-                'thumbnail': ('keyVisualUrl', {url_or_none}),
-                'cast': ('casts', ..., 'displayName', {str}),
-                'duration': ('duration', {int}),
-            }),
-        }
+        return self._extract_vod(url)
 
 
 class StacommuLiveIE(StacommuBaseIE):
-    _VALID_URL = r'https?://www\.stacommu\.jp/live/(?P<id>[\da-zA-Z]+)'
+    _VALID_URL = r'https?://www\.stacommu\.jp/(?:en/)?live/(?P<id>[\da-zA-Z]+)'
     _TESTS = [{
         'url': 'https://www.stacommu.jp/live/d2FJ3zLnndegZJCAEzGM3m',
         'info_dict': {
@@ -125,24 +149,83 @@ class StacommuLiveIE(StacommuBaseIE):
         'params': {
             'skip_download': 'm3u8',
         },
+    }, {
+        'url': 'https://www.stacommu.jp/en/live/d2FJ3zLnndegZJCAEzGM3m',
+        'only_matching': True,
     }]
 
     _API_PATH = 'events'
 
     def _real_extract(self, url):
-        video_id = self._match_id(url)
-        video_info = self._call_api(video_id, msg='video information', query={'al': 'ja'}, auth=False)
-        hls_info, decrypt = self._call_encrypted_api(
-            video_id, ':watchArchive', 'stream information', data={'method': 1})
+        return self._extract_ppv(url)
 
-        return {
-            'id': video_id,
-            'formats': self._get_formats(hls_info, ('hls', 'urls', ..., {url_or_none}), video_id),
-            'hls_aes': self._extract_hls_key(hls_info, 'hls', decrypt),
-            **traverse_obj(video_info, {
-                'title': ('displayName', {str}),
-                'timestamp': ('startTime', {int_or_none}),
-                'thumbnail': ('keyVisualUrl', {url_or_none}),
-                'duration': ('duration', {int_or_none}),
-            }),
-        }
+
+class TheaterComplexTownBaseIE(StacommuBaseIE):
+    _NETRC_MACHINE = 'theatercomplextown'
+    _API_HOST = 'api.theater-complex.town'
+    _LOGIN_QUERY = {'key': 'AIzaSyAgNCqToaIz4a062EeIrkhI_xetVfAOrfc'}
+    _LOGIN_HEADERS = {
+        'Accept': '*/*',
+        'Content-Type': 'application/json',
+        'X-Client-Version': 'Chrome/JsCore/9.23.0/FirebaseCore-web',
+        'Referer': 'https://www.theater-complex.town/',
+        'Origin': 'https://www.theater-complex.town',
+    }
+
+
+class TheaterComplexTownVODIE(TheaterComplexTownBaseIE):
+    _VALID_URL = r'https?://(?:www\.)?theater-complex\.town/(?:en/)?videos/episodes/(?P<id>\w+)'
+    IE_NAME = 'theatercomplextown:vod'
+    _TESTS = [{
+        'url': 'https://www.theater-complex.town/videos/episodes/hoxqidYNoAn7bP92DN6p78',
+        'info_dict': {
+            'id': 'hoxqidYNoAn7bP92DN6p78',
+            'ext': 'mp4',
+            'title': '演劇ドラフトグランプリ2023　劇団『恋のぼり』〜劇団名決定秘話ラジオ',
+            'description': 'md5:a7e2e9cf570379ea67fb630f345ff65d',
+            'cast': ['玉城 裕規', '石川 凌雅'],
+            'thumbnail': 'https://image.theater-complex.town/5URnXX6KCeDysuFrPkP38o/5URnXX6KCeDysuFrPkP38o',
+            'upload_date': '20231103',
+            'timestamp': 1699016400,
+            'duration': 868,
+        },
+        'params': {
+            'skip_download': 'm3u8',
+        },
+    }, {
+        'url': 'https://www.theater-complex.town/en/videos/episodes/6QT7XYwM9dJz5Gf9VB6K5y',
+        'only_matching': True,
+    }]
+
+    _API_PATH = 'videoEpisodes'
+
+    def _real_extract(self, url):
+        return self._extract_vod(url)
+
+
+class TheaterComplexTownPPVIE(TheaterComplexTownBaseIE):
+    _VALID_URL = r'https?://(?:www\.)?theater-complex\.town/(?:en/)?ppv/(?P<id>\w+)'
+    IE_NAME = 'theatercomplextown:ppv'
+    _TESTS = [{
+        'url': 'https://www.theater-complex.town/ppv/wytW3X7khrjJBUpKuV3jen',
+        'info_dict': {
+            'id': 'wytW3X7khrjJBUpKuV3jen',
+            'ext': 'mp4',
+            'title': 'BREAK FREE STARS　11月5日（日）12:30千秋楽公演',
+            'thumbnail': 'https://image.theater-complex.town/5GWEB31JcTUfjtgdeV5t6o/5GWEB31JcTUfjtgdeV5t6o',
+            'upload_date': '20231105',
+            'timestamp': 1699155000,
+            'duration': 8378,
+        },
+        'params': {
+            'skip_download': 'm3u8',
+        },
+    }, {
+        'url': 'https://www.theater-complex.town/en/ppv/wytW3X7khrjJBUpKuV3jen',
+        'only_matching': True,
+    }]
+
+    _API_PATH = 'events'
+
+    def _real_extract(self, url):
+        return self._extract_ppv(url)


Test patch: