[extractor/tiktok] Update `_VALID_URL`, add `api_hostname` arg (#5708)

Closes #5706
Authored by: bashonly
This commit is contained in:
bashonly 2022-12-04 22:30:31 +00:00 committed by GitHub
parent c53a18f016
commit c4cbd3bebd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 4 deletions

View File

@ -1765,6 +1765,7 @@ The following extractors use this feature:
* `dr`: dynamic range to ignore - one or more of `sdr`, `hdr10`, `dv` * `dr`: dynamic range to ignore - one or more of `sdr`, `hdr10`, `dv`
#### tiktok #### 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` * `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` * `manifest_app_version`: Numeric app version to call mobile APIs with, e.g. `221`

View File

@ -30,11 +30,15 @@ class TikTokBaseIE(InfoExtractor):
_WORKING_APP_VERSION = None _WORKING_APP_VERSION = None
_APP_NAME = 'trill' _APP_NAME = 'trill'
_AID = 1180 _AID = 1180
_API_HOSTNAME = 'api16-normal-c-useast1a.tiktokv.com'
_UPLOADER_URL_FORMAT = 'https://www.tiktok.com/@%s' _UPLOADER_URL_FORMAT = 'https://www.tiktok.com/@%s'
_WEBPAGE_HOST = 'https://www.tiktok.com/' _WEBPAGE_HOST = 'https://www.tiktok.com/'
QUALITIES = ('360p', '540p', '720p', '1080p') 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 @staticmethod
def _create_url(user_id, video_id): def _create_url(user_id, video_id):
return f'https://www.tiktok.com/@{user_id or "_"}/video/{video_id}' return f'https://www.tiktok.com/@{user_id or "_"}/video/{video_id}'
@ -398,7 +402,7 @@ class TikTokBaseIE(InfoExtractor):
class TikTokIE(TikTokBaseIE): 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})'] _EMBED_REGEX = [rf'<(?:script|iframe)[^>]+\bsrc=(["\'])(?P<url>{_VALID_URL})']
_TESTS = [{ _TESTS = [{
@ -944,8 +948,27 @@ class TikTokVMIE(InfoExtractor):
'creator': 'SigmaChad', 'creator': 'SigmaChad',
}, },
}, { }, {
'url': 'https://vm.tiktok.com/ZSe4FqkKd', 'url': 'https://vm.tiktok.com/ZTR45GpSF/',
'only_matching': True, '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', 'url': 'https://vt.tiktok.com/ZSe4FqkKd',
'only_matching': True, 'only_matching': True,