summaryrefslogtreecommitdiffstats
path: root/gallery_dl/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'gallery_dl/config.py')
-rw-r--r--gallery_dl/config.py46
1 files changed, 33 insertions, 13 deletions
diff --git a/gallery_dl/config.py b/gallery_dl/config.py
index 92e55d3..1873634 100644
--- a/gallery_dl/config.py
+++ b/gallery_dl/config.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# Copyright 2015-2023 Mike Fährmann
+# Copyright 2015-2025 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
@@ -103,14 +103,12 @@ def open_extern():
openers = ("explorer", "notepad")
else:
openers = ("xdg-open", "open")
- editor = os.environ.get("EDITOR")
- if editor:
+ if editor := os.environ.get("EDITOR"):
openers = (editor,) + openers
import shutil
for opener in openers:
- opener = shutil.which(opener)
- if opener:
+ if opener := shutil.which(opener):
break
else:
log.warning("Unable to find a program to open '%s' with", path)
@@ -155,13 +153,38 @@ def status():
paths.append((path, status))
- fmt = "{{:<{}}} : {{}}\n".format(
- max(len(p[0]) for p in paths)).format
+ fmt = f"{{:<{max(len(p[0]) for p in paths)}}} : {{}}\n".format
for path, status in paths:
stdout_write(fmt(path, status))
+def remap_categories():
+ opts = _config.get("extractor")
+ if not opts:
+ return
+
+ cmap = opts.get("config-map")
+ if cmap is None:
+ cmap = (
+ ("coomerparty" , "coomer"),
+ ("kemonoparty" , "kemono"),
+ ("koharu" , "schalenetwork"),
+ ("naver" , "naver-blog"),
+ ("chzzk" , "naver-chzzk"),
+ ("naverwebtoon", "naver-webtoon"),
+ ("pixiv" , "pixiv-novel"),
+ )
+ elif not cmap:
+ return
+ elif isinstance(cmap, dict):
+ cmap = cmap.items()
+
+ for old, new in cmap:
+ if old in opts and new not in opts:
+ opts[new] = opts[old]
+
+
def load(files=None, strict=False, loads=util.json_loads):
"""Load JSON configuration files"""
for pathfmt in files or _default_configs:
@@ -186,8 +209,7 @@ def load(files=None, strict=False, loads=util.json_loads):
_files.append(pathfmt)
if "subconfigs" in conf:
- subconfigs = conf["subconfigs"]
- if subconfigs:
+ if subconfigs := conf["subconfigs"]:
if isinstance(subconfigs, str):
subconfigs = (subconfigs,)
load(subconfigs, strict, loads)
@@ -259,8 +281,7 @@ def accumulate(path, key, conf=_config):
result = []
try:
if key in conf:
- value = conf[key]
- if value:
+ if value := conf[key]:
if isinstance(value, list):
result.extend(value)
else:
@@ -268,8 +289,7 @@ def accumulate(path, key, conf=_config):
for p in path:
conf = conf[p]
if key in conf:
- value = conf[key]
- if value:
+ if value := conf[key]:
if isinstance(value, list):
result[:0] = value
else: