aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/downloader/common.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2025-03-01 19:51:45 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2025-03-01 19:51:45 -0500
commitbc1c79d35e0a75bc8da8f6f010df779c4acca201 (patch)
tree9d8808a5aec770221eb667160a3fbda61f9d5d49 /gallery_dl/downloader/common.py
parent75e3edb22dad2fc506494bb90ee6b331f5169adf (diff)
parent889c7b8caec8fc0b9c7a583ed1d9cfa43518fc42 (diff)
Update upstream source from tag 'upstream/1.29.0'
Update to upstream version '1.29.0' with Debian dir 7b309aa6ccc040a2faaf51d37a63f5233590a8d7
Diffstat (limited to 'gallery_dl/downloader/common.py')
-rw-r--r--gallery_dl/downloader/common.py54
1 files changed, 51 insertions, 3 deletions
diff --git a/gallery_dl/downloader/common.py b/gallery_dl/downloader/common.py
index 1168d83..8430884 100644
--- a/gallery_dl/downloader/common.py
+++ b/gallery_dl/downloader/common.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# Copyright 2014-2022 Mike Fährmann
+# Copyright 2014-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
@@ -10,6 +10,7 @@
import os
from .. import config, util
+_config = config._config
class DownloaderBase():
@@ -17,8 +18,15 @@ class DownloaderBase():
scheme = ""
def __init__(self, job):
+ extractor = job.extractor
+
+ opts = self._extractor_config(extractor)
+ if opts:
+ self.opts = opts
+ self.config = self.config_opts
+
self.out = job.out
- self.session = job.extractor.session
+ self.session = extractor.session
self.part = self.config("part", True)
self.partdir = self.config("part-directory")
self.log = job.get_logger("downloader." + self.scheme)
@@ -29,7 +37,7 @@ class DownloaderBase():
proxies = self.config("proxy", util.SENTINEL)
if proxies is util.SENTINEL:
- self.proxies = job.extractor._proxies
+ self.proxies = extractor._proxies
else:
self.proxies = util.build_proxy_map(proxies, self.log)
@@ -37,5 +45,45 @@ class DownloaderBase():
"""Interpolate downloader config value for 'key'"""
return config.interpolate(("downloader", self.scheme), key, default)
+ def config_opts(self, key, default=None, conf=_config):
+ if key in conf:
+ return conf[key]
+ value = self.opts.get(key, util.SENTINEL)
+ if value is not util.SENTINEL:
+ return value
+ return config.interpolate(("downloader", self.scheme), key, default)
+
+ def _extractor_config(self, extractor):
+ path = extractor._cfgpath
+ if not isinstance(path, list):
+ return self._extractor_opts(path[1], path[2])
+
+ opts = {}
+ for cat, sub in reversed(path):
+ popts = self._extractor_opts(cat, sub)
+ if popts:
+ opts.update(popts)
+ return opts
+
+ def _extractor_opts(self, category, subcategory):
+ cfg = config.get(("extractor",), category)
+ if not cfg:
+ return None
+
+ copts = cfg.get(self.scheme)
+ if copts:
+ if subcategory in cfg:
+ sopts = cfg[subcategory].get(self.scheme)
+ if sopts:
+ opts = copts.copy()
+ opts.update(sopts)
+ return opts
+ return copts
+
+ if subcategory in cfg:
+ return cfg[subcategory].get(self.scheme)
+
+ return None
+
def download(self, url, pathfmt):
"""Write data from 'url' into the file specified by 'pathfmt'"""