1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

[twitter] add 'ratelimit' option (#4251)

This commit is contained in:
Mike Fährmann 2023-07-04 18:17:32 +02:00
parent f86fdf64a6
commit 1bf9f52c99
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 16 additions and 0 deletions

View File

@ -3183,6 +3183,19 @@ Description
a quoted (original) Tweet when it sees the Tweet which quotes it.
extractor.twitter.ratelimit
---------------------------
Type
``string``
Default
``"wait"``
Description
Selects how to handle exceeding the API rate limit.
* ``"abort"``: Raise an error and stop extraction
* ``"wait"``: Wait until rate limit reset
extractor.twitter.replies
-------------------------
Type

View File

@ -1439,6 +1439,9 @@ class TwitterAPI():
if response.status_code == 429:
# rate limit exceeded
if self.extractor.config("ratelimit") == "abort":
raise exception.StopExtraction("Rate limit exceeded")
until = response.headers.get("x-rate-limit-reset")
seconds = None if until else 60
self.extractor.wait(until=until, seconds=seconds)