1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 18:53:21 +01:00

Merge commit '63e6993716db8d8bedfb7b0d445c7161493046b6'

This commit is contained in:
Mike Fährmann 2019-12-16 17:25:23 +01:00
commit 8c11e81c9f
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
5 changed files with 32 additions and 2 deletions

View File

@ -52,3 +52,4 @@ class Message():
# Cookies = 5 # Cookies = 5
Queue = 6 Queue = 6
Urllist = 7 Urllist = 7
Metadata = 8

View File

@ -33,13 +33,15 @@ class PatreonExtractor(Extractor):
PatreonExtractor._warning = False PatreonExtractor._warning = False
for post in self.posts(): for post in self.posts():
yield Message.Directory, post
ids = set() ids = set()
post["num"] = 0 post["num"] = 0
content = post.get("content") content = post.get("content")
postfile = post.get("post_file") postfile = post.get("post_file")
yield Message.Directory, post
yield Message.Metadata, text.nameext_from_url(
post["creator"].get("image_url", ""), post)
for image in post["images"]: for image in post["images"]:
url = image.get("download_url") url = image.get("download_url")
if not url: if not url:

View File

@ -97,6 +97,10 @@ class Job():
self.update_kwdict(kwds) self.update_kwdict(kwds)
self.handle_urllist(urls, kwds) self.handle_urllist(urls, kwds)
elif msg[0] == Message.Metadata:
self.update_kwdict(msg[1])
self.handle_metadata(msg[1])
elif msg[0] == Message.Version: elif msg[0] == Message.Version:
if msg[1] != 1: if msg[1] != 1:
raise "unsupported message-version ({}, {})".format( raise "unsupported message-version ({}, {})".format(
@ -114,6 +118,9 @@ class Job():
def handle_directory(self, kwdict): def handle_directory(self, kwdict):
"""Handle Message.Directory""" """Handle Message.Directory"""
def handle_metadata(self, kwdict):
"""Handle Message.Metadata"""
def handle_queue(self, url, kwdict): def handle_queue(self, url, kwdict):
"""Handle Message.Queue""" """Handle Message.Queue"""
@ -242,6 +249,16 @@ class DownloadJob(Job):
else: else:
self.pathfmt.set_directory(kwdict) self.pathfmt.set_directory(kwdict)
def handle_metadata(self, kwdict):
"""Run postprocessors with metadata from 'kwdict'"""
postprocessors = self.postprocessors
if postprocessors:
pathfmt = self.pathfmt
pathfmt.set_filename(kwdict)
for pp in postprocessors:
pp.run_metadata(pathfmt)
def handle_queue(self, url, kwdict): def handle_queue(self, url, kwdict):
if "_extractor" in kwdict: if "_extractor" in kwdict:
extr = kwdict["_extractor"].from_url(url) extr = kwdict["_extractor"].from_url(url)
@ -507,6 +524,9 @@ class DataJob(Job):
def handle_directory(self, kwdict): def handle_directory(self, kwdict):
self.data.append((Message.Directory, self.filter(kwdict))) self.data.append((Message.Directory, self.filter(kwdict)))
def handle_metadata(self, kwdict):
self.data.append((Message.Metadata, self.filter(kwdict)))
def handle_queue(self, url, kwdict): def handle_queue(self, url, kwdict):
self.data.append((Message.Queue, url, self.filter(kwdict))) self.data.append((Message.Queue, url, self.filter(kwdict)))

View File

@ -26,6 +26,10 @@ class PostProcessor():
def run(pathfmt): def run(pathfmt):
"""Execute the postprocessor for a file""" """Execute the postprocessor for a file"""
@staticmethod
def run_metadata(pathfmt):
"""Execute the postprocessor for a file"""
@staticmethod @staticmethod
def run_after(pathfmt): def run_after(pathfmt):
"""Execute postprocessor after moving a file to its target location""" """Execute postprocessor after moving a file to its target location"""

View File

@ -40,6 +40,9 @@ class MetadataPP(PostProcessor):
self.path = self._path_append self.path = self._path_append
self.extension = options.get("extension", ext) self.extension = options.get("extension", ext)
if options.get("bypost"):
self.run_metadata, self.run = self.run, self.run_metadata
def run(self, pathfmt): def run(self, pathfmt):
with open(self.path(pathfmt), "w", encoding="utf-8") as file: with open(self.path(pathfmt), "w", encoding="utf-8") as file:
self.write(file, pathfmt.kwdict) self.write(file, pathfmt.kwdict)