From 7b77ecc35acfca02073c907051c92e60beae6b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 15 Jul 2019 16:39:03 +0200 Subject: [PATCH] fix paths for files without extension (#220) --- gallery_dl/job.py | 2 +- gallery_dl/util.py | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/gallery_dl/job.py b/gallery_dl/job.py index 7d790f54..20823a69 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -310,7 +310,7 @@ class DownloadJob(Job): self.sleep = self.extractor.config("sleep") if not self.extractor.config("download", True): - self.download = lambda x: True + self.download = self.pathfmt.fix_extension skip = self.extractor.config("skip", True) if skip: diff --git a/gallery_dl/util.py b/gallery_dl/util.py index a448a8a5..14ae3d21 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -532,7 +532,7 @@ class PathFormat(): self.basedirectory = expand_path( extractor.config("base-directory", (".", "gallery-dl"))) - if os.altsep: + if os.altsep and os.altsep in self.basedirectory: self.basedirectory = self.basedirectory.replace(os.altsep, os.sep) def open(self, mode="wb"): @@ -541,13 +541,9 @@ class PathFormat(): def exists(self, archive=None): """Return True if the file exists on disk or in 'archive'""" - if (archive and archive.check(self.keywords) or - self.has_extension and os.path.exists(self.realpath)): - if not self.has_extension: - # adjust display name - self.set_extension("") - if self.path[-1] == ".": - self.path = self.path[:-1] + if archive and archive.check(self.keywords): + return self.fix_extension() + if self.has_extension and os.path.exists(self.realpath): return True return False @@ -590,6 +586,14 @@ class PathFormat(): self.keywords["extension"] = extension self.build_path() + def fix_extension(self, _=None): + if not self.has_extension: + self.set_extension("") + if self.path[-1] == ".": + self.path = self.path[:-1] + self.temppath = self.realpath = self.realpath[:-1] + return True + def build_path(self): """Use filename-keywords and directory to build a full path""" try: