[postprocessor:metadata] first implementation (#135)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright 2017-2018 Mike Fährmann
|
# Copyright 2017-2019 Mike Fährmann
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License version 2 as
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
@@ -268,6 +268,12 @@ def build_parser():
|
|||||||
dest="postprocessors", const=({"name": "ugoira"},),
|
dest="postprocessors", const=({"name": "ugoira"},),
|
||||||
help="Convert Pixiv Ugoira to WebM (requires FFmpeg)",
|
help="Convert Pixiv Ugoira to WebM (requires FFmpeg)",
|
||||||
)
|
)
|
||||||
|
postprocessor.add_argument(
|
||||||
|
"--write-metadata",
|
||||||
|
action=ConfigConstAction, nargs=0,
|
||||||
|
dest="postprocessors", const=({"name": "metadata"},),
|
||||||
|
help="Write metadata to separate JSON files",
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"urls",
|
"urls",
|
||||||
|
|||||||
33
gallery_dl/postprocessor/metadata.py
Normal file
33
gallery_dl/postprocessor/metadata.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright 2019 Mike Fährmann
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
|
||||||
|
"""Write metadata to JSON files"""
|
||||||
|
|
||||||
|
from .common import PostProcessor
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
class MetadataPP(PostProcessor):
|
||||||
|
|
||||||
|
def __init__(self, pathfmt, options):
|
||||||
|
PostProcessor.__init__(self)
|
||||||
|
self.indent = options.get("indent", 4)
|
||||||
|
self.ascii = options.get("ascii", False)
|
||||||
|
|
||||||
|
def run(self, pathfmt):
|
||||||
|
with open(pathfmt.realpath + ".json", "w") as file:
|
||||||
|
json.dump(
|
||||||
|
pathfmt.keywords,
|
||||||
|
file,
|
||||||
|
sort_keys=True,
|
||||||
|
indent=self.indent,
|
||||||
|
ensure_ascii=self.ascii,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
__postprocessor__ = MetadataPP
|
||||||
Reference in New Issue
Block a user