Skip to content

Commit

Permalink
[tumblr] add option to filter reblogged posts (#61)
Browse files Browse the repository at this point in the history
Reblogs are ignored by default, but can be included by setting
'extractor.tumblr.reblogs' to 'true'.
  • Loading branch information
mikf committed Jan 5, 2018
1 parent a794fff commit d235f68
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,15 @@ Description Search posts for inline images.
=========== =====


extractor.tumblr.reblogs
------------------------
=========== =====
Type ``bool``
Default ``false``
Description Extract images from reblogged posts.
=========== =====


extractor.tumblr.posts
----------------------
=========== =====
Expand Down
1 change: 1 addition & 0 deletions docs/gallery-dl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
{
"posts": "photo",
"inline": false,
"reblogs": false,
"external": false
},
"recursive":
Expand Down
12 changes: 10 additions & 2 deletions gallery_dl/extractor/tumblr.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(self, match):

self.types = self._setup_posttypes()
self.inline = self.config("inline", False)
self.reblogs = self.config("reblogs", False)
self.external = self.config("external", False)

if len(self.types) == 1:
Expand All @@ -65,6 +66,11 @@ def items(self):
if post["type"] not in self.types:
continue

reblog = "reblogged_from_id" in post
if reblog and not self.reblogs:
continue
post["reblogged"] = reblog

post["blog"] = blog
post["offset"] = 0

Expand Down Expand Up @@ -145,7 +151,8 @@ class TumblrUserExtractor(TumblrExtractor):
r"\d+\.media\.tumblr\.com/tumblr_[^/_]+_1280\.jpg|"
r"w+\.tumblr\.com/audio_file/demo/\d+/tumblr_\w+)"),
"count": 3,
"options": (("posts", "all"), ("external", True), ("inline", True))
"options": (("posts", "all"), ("external", True),
("inline", True), ("reblogs", True))
}),
]

Expand All @@ -165,6 +172,7 @@ class TumblrPostExtractor(TumblrExtractor):
def __init__(self, match):
TumblrExtractor.__init__(self, match)
self.post_id = match.group(2)
self.reblogs = True

def posts(self):
return self.api.posts(self.user, {"id": self.post_id})
Expand Down Expand Up @@ -197,7 +205,7 @@ class TumblrAPI():

def __init__(self, extractor):
self.api_key = extractor.config("api-key", TumblrAPI.API_KEY)
self.params = {"offset": 0, "limit": 50}
self.params = {"offset": 0, "limit": 50, "reblog_info": "true"}
self.extractor = extractor

@memcache(keyarg=1)
Expand Down

0 comments on commit d235f68

Please sign in to comment.