You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gallery-dl/gallery_dl/downloader/common.py

40 lines
1.2 KiB

# -*- coding: utf-8 -*-
# Copyright 2014-2020 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.
"""Common classes and constants used by downloader modules."""
10 years ago
import os
import logging
from .. import config, util
10 years ago
class DownloaderBase():
"""Base class for downloaders"""
scheme = ""
def __init__(self, extractor, output):
self.session = extractor.session
self.out = output
self.part = self.config("part", True)
self.partdir = self.config("part-directory")
self.log = logging.getLogger("downloader." + self.scheme)
self.log.job = extractor.log.job
self.log.extractor = extractor
if self.partdir:
self.partdir = util.expand_path(self.partdir)
os.makedirs(self.partdir, exist_ok=True)
def config(self, key, default=None):
"""Interpolate downloader config value for 'key'"""
return config.interpolate(("downloader", self.scheme), key, default)
def download(self, url, pathfmt):
"""Write data from 'url' into the file specified by 'pathfmt'"""