Skip to content

Commit

Permalink
[twitter] implement 'users' option (#1337)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Mar 15, 2021
1 parent 847e9b0 commit 3378b39
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
14 changes: 14 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,20 @@ Description
Extract `TwitPic <https://twitpic.com/>`__ embeds.


extractor.twitter.users
-----------------------
Type
``string``
Default
``"timeline"``
Description
Output format for user results from
``following`` and ``list-members`` queries.

* ``"timeline"``: ``https://twitter.com/i/user/USERID``
* ``"media"``: ``https://twitter.com/id:USERID/media``


extractor.twitter.videos
------------------------
Type
Expand Down
1 change: 1 addition & 0 deletions docs/gallery-dl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@
"replies": true,
"retweets": true,
"twitpic": false,
"users": "timeline",
"videos": true
},
"unsplash":
Expand Down
22 changes: 14 additions & 8 deletions gallery_dl/extractor/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ def _transform_user(self, user):
}
return cache[uid]

def _users_result(self, users):
if self.config("users") == "media":
cls = TwitterMediaExtractor
fmt = "{}/id:{}/media".format
else:
cls = TwitterTimelineExtractor
fmt = "{}/i/user/{}".format

for user in users:
user["_extractor"] = cls
yield Message.Queue, fmt(self.root, user["rest_id"]), user

def metadata(self):
"""Return general metadata"""
return {}
Expand Down Expand Up @@ -356,10 +368,7 @@ class TwitterListMembersExtractor(TwitterExtractor):

def items(self):
self.login()
for user in TwitterAPI(self).list_members(self.user):
user["_extractor"] = TwitterTimelineExtractor
url = "{}/i/user/{}".format(self.root, user["rest_id"])
yield Message.Queue, url, user
return self._users_result(TwitterAPI(self).list_members(self.user))


class TwitterFollowingExtractor(TwitterExtractor):
Expand All @@ -373,10 +382,7 @@ class TwitterFollowingExtractor(TwitterExtractor):

def items(self):
self.login()
for user in TwitterAPI(self).user_following(self.user):
user["_extractor"] = TwitterTimelineExtractor
url = "{}/i/user/{}".format(self.root, user["rest_id"])
yield Message.Queue, url, user
return self._users_result(TwitterAPI(self).user_following(self.user))


class TwitterSearchExtractor(TwitterExtractor):
Expand Down

0 comments on commit 3378b39

Please sign in to comment.