import requests from pathlib import Path class CoverDownloader: def __init__(self, outdir: Path, cache: bool): self.outdir = outdir self.cache = cache def download(self, url: str, filename: str): if (Path(self.outdir) / f"{filename}.jpg").is_file() and self.cache: return Path(self.outdir).mkdir(parents=True, exist_ok=True) with open(Path(self.outdir) / f"{filename}.jpg", "wb") as f: f.write(requests.get(url).content)