[tiktok] Incorporate --retries and --http-timeout into rehydration data extraction
This commit is contained in:
@@ -144,7 +144,9 @@ class TiktokExtractor(Extractor):
|
|||||||
def _sanitize_url(self, url):
|
def _sanitize_url(self, url):
|
||||||
return text.ensure_http_scheme(url.replace("/photo/", "/video/", 1))
|
return text.ensure_http_scheme(url.replace("/photo/", "/video/", 1))
|
||||||
|
|
||||||
def _extract_rehydration_data(self, url, *, retries=1):
|
def _extract_rehydration_data(self, url, *, retries=None):
|
||||||
|
if retries is None:
|
||||||
|
retries = self._retries
|
||||||
try:
|
try:
|
||||||
html = self.request(url).text
|
html = self.request(url).text
|
||||||
data = text.extr(
|
data = text.extr(
|
||||||
@@ -153,10 +155,12 @@ class TiktokExtractor(Extractor):
|
|||||||
return util.json_loads(data)["__DEFAULT_SCOPE__"]
|
return util.json_loads(data)["__DEFAULT_SCOPE__"]
|
||||||
except JSONDecodeError:
|
except JSONDecodeError:
|
||||||
# We failed to retrieve rehydration data. This happens relatively
|
# We failed to retrieve rehydration data. This happens relatively
|
||||||
# frequently, so retry if we're told to do so.
|
# frequently when making many requests, so retry.
|
||||||
self.log.warning("%s: Failed to retrieve rehydration data, trying "
|
self.log.warning("%s: Failed to retrieve rehydration data, trying "
|
||||||
"%d more time%s", url, retries,
|
"%d more time%s and delaying for %d second(s)",
|
||||||
"" if retries == 1 else "s")
|
url, retries, "" if retries == 1 else "s",
|
||||||
|
self._timeout)
|
||||||
|
self.sleep(self._timeout, "retry")
|
||||||
if retries > 0:
|
if retries > 0:
|
||||||
return self._extract_rehydration_data(url, retries=retries-1)
|
return self._extract_rehydration_data(url, retries=retries-1)
|
||||||
raise
|
raise
|
||||||
|
|||||||
Reference in New Issue
Block a user