Skip to content

Commit

Permalink
[twitter] update 'search' pagination (#544)
Browse files Browse the repository at this point in the history
Only stop when list of all returned Tweets is empty
instead of when no valid Tweet was found.
  • Loading branch information
mikf committed Dec 14, 2022
1 parent 1cbc234 commit 90a9c07
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions gallery_dl/extractor/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,15 +1216,16 @@ def _pagination_legacy(self, endpoint, params):
original_retweets = (self.extractor.retweets == "original")

while True:
cursor = tweet = None
data = self._call(endpoint, params)

instr = data["timeline"]["instructions"]
if not instr:
return
tweet_ids = []

tweets = data["globalObjects"]["tweets"]
users = data["globalObjects"]["users"]
tweet_id = cursor = None
tweet_ids = []

# collect tweet IDs and cursor value
for entry in instr[0]["addEntries"]["entries"]:
Expand All @@ -1243,7 +1244,7 @@ def _pagination_legacy(self, endpoint, params):
cursor = entry["content"]["operation"]["cursor"]
if not cursor.get("stopOnEmptyResponse", True):
# keep going even if there are no tweets
tweet = True
tweet_id = True
cursor = cursor["value"]

elif entry_startswith("conversationThread-"):
Expand Down Expand Up @@ -1292,7 +1293,7 @@ def _pagination_legacy(self, endpoint, params):
cursor = (instr[-1]["replaceEntry"]["entry"]
["content"]["operation"]["cursor"]["value"])

if not cursor or not tweet:
if not cursor or (not tweets and not tweet_id):
return
params["cursor"] = cursor

Expand Down

0 comments on commit 90a9c07

Please sign in to comment.