Skip to content

Commit

Permalink
[twitter] warn about age-restricted Tweets (#2354)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Mar 3, 2022
1 parent e778be5 commit 64bbc79
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions gallery_dl/extractor/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ def __init__(self, extractor):
"__fs_dont_mention_me_view_api_enabled": False,
}

self._nsfw_warning = True
self._json_dumps = json.JSONEncoder(separators=(",", ":")).encode
self._user = None

Expand Down Expand Up @@ -1147,6 +1148,10 @@ def _pagination_tweets(self, endpoint, variables, path=None):
tweets.extend(entry["content"]["items"])
elif esw("conversationthread-"):
tweets.extend(entry["content"]["items"])
elif esw("tombstone-"):
self._report_tombstone(
entry,
entry["content"]["itemContent"]["tombstoneInfo"])
elif esw("cursor-bottom-"):
cursor = entry["content"]
if not cursor.get("stopOnEmptyResponse", True):
Expand All @@ -1158,6 +1163,9 @@ def _pagination_tweets(self, endpoint, variables, path=None):
try:
tweet = ((entry.get("content") or entry["item"])
["itemContent"]["tweet_results"]["result"])
if "tombstone" in tweet:
self._report_tombstone(entry, tweet["tombstone"])
continue
legacy = tweet["legacy"]
except KeyError:
extr.log.debug(
Expand Down Expand Up @@ -1244,3 +1252,11 @@ def _pagination_users(self, endpoint, variables, path=None):
if stop or not cursor or not entry:
return
variables["cursor"] = cursor

def _report_tombstone(self, entry, tombstone):
text = (tombstone.get("richText") or tombstone["text"])["text"]
if text.startswith("Age-restricted") and self._nsfw_warning:
self.extractor.log.warning(text)
self._nsfw_warning = False
self.extractor.log.debug(
"Skipping %s (%s)", entry["entryId"].rpartition("-")[2], text)

0 comments on commit 64bbc79

Please sign in to comment.