- self._set_cookie(self._API_HOSTNAME, 'odin_tt', ''.join(random.choice('0123456789abcdef') for _ in range(160)))
- return self._download_json(
- 'https://%s/aweme/v1/%s/' % (self._API_HOSTNAME, ep), video_id=video_id,
- fatal=fatal, note=note, errnote=errnote, headers={
- 'User-Agent': f'com.ss.android.ugc.trill/{self._MANIFEST_APP_VERSION} (Linux; U; Android 10; en_US; Pixel 4; Build/QQ3A.200805.001; Cronet/58.0.2991.0)',
- 'Accept': 'application/json',
- }, query=real_query)
+
+ def _call_api(self, ep, query, video_id, fatal=True,
+ note='Downloading API JSON', errnote='Unable to download API page'):
+ if not self._WORKING_APP_VERSION:
+ app_version = self._configuration_arg('app_version', [''], ie_key=TikTokIE.ie_key())[0]
+ manifest_app_version = self._configuration_arg('manifest_app_version', [''], ie_key=TikTokIE.ie_key())[0]
+ if app_version and manifest_app_version:
+ self._WORKING_APP_VERSION = (app_version, manifest_app_version)
+ self.write_debug('Imported app version combo from extractor arguments')
+ elif app_version or manifest_app_version:
+ self.report_warning('Only one of the two required version params are passed as extractor arguments', only_once=True)
+
+ if self._WORKING_APP_VERSION:
+ app_version, manifest_app_version = self._WORKING_APP_VERSION
+ real_query = self._build_api_query(query, app_version, manifest_app_version)
+ return self._call_api_impl(ep, real_query, manifest_app_version, video_id, fatal, note, errnote)
+
+ for count, (app_version, manifest_app_version) in enumerate(self._APP_VERSIONS, start=1):
+ real_query = self._build_api_query(query, app_version, manifest_app_version)
+ try:
+ res = self._call_api_impl(ep, real_query, manifest_app_version, video_id, fatal, note, errnote)
+ self._WORKING_APP_VERSION = (app_version, manifest_app_version)
+ return res
+ except ExtractorError as e:
+ if isinstance(e.cause, json.JSONDecodeError) and e.cause.pos == 0:
+ if count == len(self._APP_VERSIONS):
+ if fatal:
+ raise e
+ else:
+ self.report_warning(str(e.cause or e.msg))
+ return
+ self.report_warning('%s. Retrying... (attempt %s of %s)' % (str(e.cause or e.msg), count, len(self._APP_VERSIONS)))
+ continue
+ raise e
+
+ def _get_subtitles(self, aweme_detail, aweme_id):
+ # TODO: Extract text positioning info
+ subtitles = {}
+ captions_info = traverse_obj(
+ aweme_detail, ('interaction_stickers', ..., 'auto_video_caption_info', 'auto_captions', ...), expected_type=dict, default=[])
+ for caption in captions_info:
+ caption_url = traverse_obj(caption, ('url', 'url_list', ...), expected_type=url_or_none, get_all=False)
+ if not caption_url:
+ continue
+ caption_json = self._download_json(
+ caption_url, aweme_id, note='Downloading captions', errnote='Unable to download captions', fatal=False)
+ if not caption_json:
+ continue
+ subtitles.setdefault(caption.get('language', 'en'), []).append({
+ 'ext': 'srt',
+ 'data': '\n\n'.join(
+ f'{i + 1}\n{srt_subtitles_timecode(line["start_time"] / 1000)} --> {srt_subtitles_timecode(line["end_time"] / 1000)}\n{line["text"]}'
+ for i, line in enumerate(caption_json['utterances']) if line.get('text'))
+ })
+ return subtitles