mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 02:32:33 +01:00
[twitter] implement 'strategy' option (#2712)
to be able to better control what Tweets get used an returned for twitter.com/USER URLs.
This commit is contained in:
parent
5806a1851e
commit
4b2a0a0eda
@ -2375,6 +2375,22 @@ Description
|
||||
will be taken from the original Tweets, not the Retweets.
|
||||
|
||||
|
||||
extractor.twitter.timeline.strategy
|
||||
-----------------------------------
|
||||
Type
|
||||
``string``
|
||||
Default
|
||||
``"auto"``
|
||||
Description
|
||||
Controls the strategy / tweet source used for user URLs
|
||||
(``https://twitter.com/USER``).
|
||||
|
||||
* ``"tweets"``: `/tweets <https://twitter.com/USER/tweets>`__ timeline + search
|
||||
* ``"media"``: `/media <https://twitter.com/USER/media>`__ timeline + search
|
||||
* ``"with_replies"``: `/with_replies <https://twitter.com/USER/with_replies>`__ timeline + search
|
||||
* ``"auto"``: ``"tweets"`` or ``"media"``, depending on `retweets <extractor.twitter.retweets_>`__ and `text-tweets <extractor.twitter.text-tweets_>`__ settings
|
||||
|
||||
|
||||
extractor.twitter.text-tweets
|
||||
-----------------------------
|
||||
Type
|
||||
|
@ -285,6 +285,7 @@
|
||||
"quoted": false,
|
||||
"replies": true,
|
||||
"retweets": false,
|
||||
"strategy": null,
|
||||
"text-tweets": false,
|
||||
"twitpic": false,
|
||||
"users": "timeline",
|
||||
|
@ -440,12 +440,9 @@ class TwitterTimelineExtractor(TwitterExtractor):
|
||||
self.user = "id:" + user_id
|
||||
|
||||
def tweets(self):
|
||||
tweets = (self.api.user_tweets if self.retweets else
|
||||
self.api.user_media)
|
||||
|
||||
# yield initial batch of (media) tweets
|
||||
tweet = None
|
||||
for tweet in tweets(self.user):
|
||||
for tweet in self._select_tweet_source()(self.user):
|
||||
yield tweet
|
||||
|
||||
if tweet is None:
|
||||
@ -476,6 +473,19 @@ class TwitterTimelineExtractor(TwitterExtractor):
|
||||
# yield search results starting from last tweet id
|
||||
yield from self.api.search_adaptive(query)
|
||||
|
||||
def _select_tweet_source(self):
|
||||
strategy = self.config("strategy")
|
||||
if strategy is None or strategy == "auto":
|
||||
if self.retweets or self.textonly:
|
||||
return self.api.user_tweets
|
||||
else:
|
||||
return self.api.user_media
|
||||
if strategy == "tweets":
|
||||
return self.api.user_tweets
|
||||
if strategy == "with_replies":
|
||||
return self.api.user_tweets_and_replies
|
||||
return self.api.user_media
|
||||
|
||||
|
||||
class TwitterTweetsExtractor(TwitterExtractor):
|
||||
"""Extractor for Tweets from a user's Tweets timeline"""
|
||||
|
Loading…
Reference in New Issue
Block a user