diff options
Diffstat (limited to 'gallery_dl/extractor/patreon.py')
| -rw-r--r-- | gallery_dl/extractor/patreon.py | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/gallery_dl/extractor/patreon.py b/gallery_dl/extractor/patreon.py index 547465b..c7df089 100644 --- a/gallery_dl/extractor/patreon.py +++ b/gallery_dl/extractor/patreon.py @@ -32,22 +32,19 @@ class PatreonExtractor(Extractor): if "session_id" not in self.session.cookies: self.log.warning("no 'session_id' cookie set") PatreonExtractor._warning = False + generators = self._build_file_generators(self.config("files")) for post in self.posts(): if not post.get("current_user_can_view", True): self.log.warning("Not allowed to view post %s", post["id"]) continue + yield Message.Directory, post + post["num"] = 0 hashes = set() - - yield Message.Directory, post - for kind, url, name in itertools.chain( - self._images(post), - self._attachments(post), - self._postfile(post), - self._content(post), - ): + for kind, url, name in itertools.chain.from_iterable( + g(post) for g in generators): fhash = self._filehash(url) if fhash not in hashes or not fhash: hashes.add(fhash) @@ -82,15 +79,14 @@ class PatreonExtractor(Extractor): if url: yield "attachment", url, attachment["name"] - @staticmethod - def _content(post): + def _content(self, post): content = post.get("content") if content: for img in text.extract_iter( content, '<img data-media-id="', '>'): url = text.extract(img, 'src="', '"')[0] if url: - yield "content", url, url + yield "content", url, self._filename(url) or url def posts(self): """Return all relevant post objects""" @@ -155,7 +151,7 @@ class PatreonExtractor(Extractor): included[file["type"]][file["id"]] for file in files["data"] ] - return [] + return () @memcache(keyarg=1) def _user(self, url): @@ -212,6 +208,20 @@ class PatreonExtractor(Extractor): "&json-api-version=1.0" ) + def _build_file_generators(self, filetypes): + if filetypes is None: + return (self._images, self._attachments, + self._postfile, self._content) + genmap = { + "images" : self._images, + "attachments": self._attachments, + "postfile" : self._postfile, + "content" : self._content, + } + if isinstance(filetypes, str): + filetypes = filetypes.split(",") + return [genmap[ft] for ft in filetypes] + class PatreonCreatorExtractor(PatreonExtractor): """Extractor for a creator's works""" @@ -305,8 +315,9 @@ class PatreonPostExtractor(PatreonExtractor): "count": 4, }), # postfile + content - ("https://www.patreon.com/posts/19987002", { - "count": 4, + ("https://www.patreon.com/posts/56127163", { + "count": 3, + "keyword": {"filename": r"re:^(?!1).+$"}, }), # tags (#1539) ("https://www.patreon.com/posts/free-post-12497641", { |
