]> jfr.im git - yt-dlp.git/commitdiff
[extractor/tiktok] Update `_VALID_URL`, add `api_hostname` arg (#5708)
authorbashonly <redacted>
Sun, 4 Dec 2022 22:30:31 +0000 (22:30 +0000)
committerGitHub <redacted>
Sun, 4 Dec 2022 22:30:31 +0000 (22:30 +0000)
Closes #5706
Authored by: bashonly

README.md
yt_dlp/extractor/tiktok.py

index b6a07da9a8ccf5d54c732d8f048dc770ca7fa97a..8fdedacf597f4fcac984a55e6fb43fc26f1ab50c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1765,6 +1765,7 @@ #### hotstar
 * `dr`: dynamic range to ignore - one or more of `sdr`, `hdr10`, `dv`
 
 #### tiktok
+* `api_hostname`: Hostname to use for mobile API requests, e.g. `api-h2.tiktokv.com`
 * `app_version`: App version to call mobile APIs with - should be set along with `manifest_app_version`, e.g. `20.2.1`
 * `manifest_app_version`: Numeric app version to call mobile APIs with, e.g. `221`
 
index 95223f5de950aa2c0662688b494c93206b62db9c..2dd4510cc3893b2e4c5899efbd495e60b460c8e9 100644 (file)
@@ -30,11 +30,15 @@ class TikTokBaseIE(InfoExtractor):
     _WORKING_APP_VERSION = None
     _APP_NAME = 'trill'
     _AID = 1180
-    _API_HOSTNAME = 'api16-normal-c-useast1a.tiktokv.com'
     _UPLOADER_URL_FORMAT = 'https://www.tiktok.com/@%s'
     _WEBPAGE_HOST = 'https://www.tiktok.com/'
     QUALITIES = ('360p', '540p', '720p', '1080p')
 
+    @property
+    def _API_HOSTNAME(self):
+        return self._configuration_arg(
+            'api_hostname', ['api16-normal-c-useast1a.tiktokv.com'], ie_key=TikTokIE)[0]
+
     @staticmethod
     def _create_url(user_id, video_id):
         return f'https://www.tiktok.com/@{user_id or "_"}/video/{video_id}'
@@ -398,7 +402,7 @@ def _parse_aweme_video_web(self, aweme_detail, webpage_url):
 
 
 class TikTokIE(TikTokBaseIE):
-    _VALID_URL = r'https?://www\.tiktok\.com/(?:embed|@(?P<user_id>[\w\.-]+)/video)/(?P<id>\d+)'
+    _VALID_URL = r'https?://www\.tiktok\.com/(?:embed|@(?P<user_id>[\w\.-]+)?/video)/(?P<id>\d+)'
     _EMBED_REGEX = [rf'<(?:script|iframe)[^>]+\bsrc=(["\'])(?P<url>{_VALID_URL})']
 
     _TESTS = [{
@@ -944,8 +948,27 @@ class TikTokVMIE(InfoExtractor):
             'creator': 'SigmaChad',
         },
     }, {
-        'url': 'https://vm.tiktok.com/ZSe4FqkKd',
-        'only_matching': True,
+        'url': 'https://vm.tiktok.com/ZTR45GpSF/',
+        'info_dict': {
+            'id': '7106798200794926362',
+            'ext': 'mp4',
+            'title': 'md5:edc3e7ea587847f8537468f2fe51d074',
+            'uploader_id': '6997695878846268418',
+            'upload_date': '20220608',
+            'view_count': int,
+            'like_count': int,
+            'comment_count': int,
+            'thumbnail': r're:https://.+\.webp.*',
+            'uploader_url': 'https://www.tiktok.com/@MS4wLjABAAAAdZ_NcPPgMneaGrW0hN8O_J_bwLshwNNERRF5DxOw2HKIzk0kdlLrR8RkVl1ksrMO',
+            'duration': 29,
+            'timestamp': 1654680400,
+            'repost_count': int,
+            'artist': 'Akihitoko',
+            'track': 'original sound',
+            'description': 'md5:edc3e7ea587847f8537468f2fe51d074',
+            'uploader': 'akihitoko1',
+            'creator': 'Akihitoko',
+        },
     }, {
         'url': 'https://vt.tiktok.com/ZSe4FqkKd',
         'only_matching': True,