Skip to content

Commit

Permalink
implement 'extension-map' option (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Nov 2, 2020
1 parent 98a4d86 commit e3480bc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
19 changes: 19 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,25 @@ Description
escaped with backslashes, e.g. ``"\\[\\]"``


extractor.*.extension-map
-------------------------
Type
``object``
Default
``null``
Example
.. code:: json
{
"jpeg": "jpg",
"jpe" : "jpg",
"jfif": "jpg",
"jif" : "jpg",
"jfi" : "jpg"
}
Description
A JSON ``object`` mapping filename extensions to alternatives.


extractor.*.skip
----------------
Type
Expand Down
11 changes: 10 additions & 1 deletion gallery_dl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,12 @@ def __init__(self, extractor):
directory_fmt = extractor.config("directory", extractor.directory_fmt)
kwdefault = extractor.config("keywords-default")

extension_map = extractor.config("extension-map")
if extension_map is None:
# TODO: better default value in 1.16.0
extension_map = {}
self.extension_map = extension_map.get

try:
self.filename_formatter = Formatter(
filename_fmt, kwdefault).format_map
Expand Down Expand Up @@ -850,7 +856,9 @@ def set_filename(self, kwdict):
"""Set general filename data"""
self.kwdict = kwdict
self.temppath = self.prefix = ""
self.extension = kwdict["extension"]

ext = kwdict["extension"]
kwdict["extension"] = self.extension = self.extension_map(ext, ext)

if self.extension:
self.build_path()
Expand All @@ -859,6 +867,7 @@ def set_filename(self, kwdict):

def set_extension(self, extension, real=True):
"""Set filename extension"""
extension = self.extension_map(extension, extension)
if real:
self.extension = extension
self.kwdict["extension"] = self.prefix + extension
Expand Down

0 comments on commit e3480bc

Please sign in to comment.