mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 18:53:21 +01:00
[twitter] add option to log out when blocked (#1719)
This commit is contained in:
parent
ed4b3c48cb
commit
52984f7e22
@ -596,8 +596,8 @@ class TwitterAPI():
|
|||||||
"ext": "mediaStats,highlightedLabel",
|
"ext": "mediaStats,highlightedLabel",
|
||||||
}
|
}
|
||||||
|
|
||||||
cookies = self.extractor.session.cookies
|
cookies = extractor.session.cookies
|
||||||
cookiedomain = ".twitter.com"
|
cookiedomain = extractor.cookiedomain
|
||||||
|
|
||||||
# CSRF
|
# CSRF
|
||||||
csrf_token = cookies.get("ct0", domain=cookiedomain)
|
csrf_token = cookies.get("ct0", domain=cookiedomain)
|
||||||
@ -751,14 +751,35 @@ class TwitterAPI():
|
|||||||
msg = data["errors"]
|
msg = data["errors"]
|
||||||
if response.status_code < 400:
|
if response.status_code < 400:
|
||||||
self.extractor.log.warning(msg)
|
self.extractor.log.warning(msg)
|
||||||
|
else:
|
||||||
|
msg = ""
|
||||||
|
|
||||||
if response.status_code < 400:
|
if response.status_code < 400:
|
||||||
|
# success
|
||||||
return data
|
return data
|
||||||
|
|
||||||
if response.status_code == 429:
|
if response.status_code == 429:
|
||||||
|
# rate limit exceeded
|
||||||
until = response.headers.get("x-rate-limit-reset")
|
until = response.headers.get("x-rate-limit-reset")
|
||||||
seconds = None if until else 60
|
seconds = None if until else 60
|
||||||
self.extractor.wait(until=until, seconds=seconds)
|
self.extractor.wait(until=until, seconds=seconds)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if response.status_code == 401 and \
|
||||||
|
"have been blocked from viewing" in msg:
|
||||||
|
# account blocked
|
||||||
|
extr = extr = self.extractor
|
||||||
|
if self.headers["x-twitter-auth-type"] and \
|
||||||
|
extr.config("logout"):
|
||||||
|
guest_token = self._guest_token()
|
||||||
|
extr.session.cookies.set(
|
||||||
|
"gt", guest_token, domain=extr.cookiedomain)
|
||||||
|
self.headers["x-guest-token"] = guest_token
|
||||||
|
self.headers["x-twitter-auth-type"] = None
|
||||||
|
extr.log.info("Retrying API request as guest")
|
||||||
|
continue
|
||||||
|
|
||||||
|
# error
|
||||||
raise exception.StopExtraction(
|
raise exception.StopExtraction(
|
||||||
"%s %s (%s)", response.status_code, response.reason, msg)
|
"%s %s (%s)", response.status_code, response.reason, msg)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user