diff --git a/docs/configuration.rst b/docs/configuration.rst index 4389c8dc..9aed9675 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -112,7 +112,11 @@ downloader.part-directory =========== ===== Type ``string`` Default ``null`` -Description Path to an existing directory to store ``.part`` files in. +Description Alternate location for ``.part`` files. + + Missing directories will be created as needed. + If this value is ``null``, ``.part`` files are going to be stored + alongside the actual output files. =========== ===== diff --git a/gallery_dl/downloader/common.py b/gallery_dl/downloader/common.py index bb3ec732..f94ab273 100644 --- a/gallery_dl/downloader/common.py +++ b/gallery_dl/downloader/common.py @@ -11,19 +11,29 @@ import os import time import logging +from .. import config, util class DownloaderBase(): """Base class for downloaders""" + scheme = "" retries = 1 - part = True - partdir = None def __init__(self, session, output): self.session = session self.out = output self.log = logging.getLogger("download") self.downloading = False + self.part = self.config("part", True) + self.partdir = self.config("part-directory") + + if self.partdir: + self.partdir = util.expand_path(self.partdir) + os.makedirs(self.partdir, exist_ok=True) + + def config(self, key, default=None): + """Interpolate config value for 'key'""" + return config.interpolate(("downloader", self.scheme, key), default) def download(self, url, pathfmt): """Download the resource at 'url' and write it to a file-like object""" diff --git a/gallery_dl/downloader/http.py b/gallery_dl/downloader/http.py index bd1648e3..a303e220 100644 --- a/gallery_dl/downloader/http.py +++ b/gallery_dl/downloader/http.py @@ -10,23 +10,18 @@ import mimetypes from .common import DownloaderBase -from .. import config, util - - -def _conf(key, default=None): - return config.interpolate(("downloader", "http", key), default) +from .. import util class Downloader(DownloaderBase): - retries = _conf("retries", 5) - timeout = _conf("timeout", 30) - verify = _conf("verify", True) - part = _conf("part", True) - partdir = util.expand_path(_conf("part-directory")) + scheme = "http" def __init__(self, session, output): DownloaderBase.__init__(self, session, output) self.response = None + self.retries = self.config("retries", 5) + self.timeout = self.config("timeout", 30) + self.verify = self.config("verify", True) def connect(self, url, offset): headers = {} diff --git a/gallery_dl/downloader/text.py b/gallery_dl/downloader/text.py index 64e1bdcc..ddd6f453 100644 --- a/gallery_dl/downloader/text.py +++ b/gallery_dl/downloader/text.py @@ -9,16 +9,10 @@ """Downloader module for text: URLs""" from .common import DownloaderBase -from .. import config, util - - -def _conf(key, default=None): - return config.interpolate(("downloader", "text", key), default) class Downloader(DownloaderBase): - part = _conf("part", True) - partdir = util.expand_path(_conf("part-directory")) + scheme = "text" def __init__(self, session, output): DownloaderBase.__init__(self, session, output)