fix paths for files without extension (#220)

This commit is contained in:
Mike Fährmann
2019-07-15 16:39:03 +02:00
parent c41ff9441e
commit 7b77ecc35a
2 changed files with 13 additions and 9 deletions

View File

@@ -310,7 +310,7 @@ class DownloadJob(Job):
self.sleep = self.extractor.config("sleep") self.sleep = self.extractor.config("sleep")
if not self.extractor.config("download", True): if not self.extractor.config("download", True):
self.download = lambda x: True self.download = self.pathfmt.fix_extension
skip = self.extractor.config("skip", True) skip = self.extractor.config("skip", True)
if skip: if skip:

View File

@@ -532,7 +532,7 @@ class PathFormat():
self.basedirectory = expand_path( self.basedirectory = expand_path(
extractor.config("base-directory", (".", "gallery-dl"))) 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) self.basedirectory = self.basedirectory.replace(os.altsep, os.sep)
def open(self, mode="wb"): def open(self, mode="wb"):
@@ -541,13 +541,9 @@ class PathFormat():
def exists(self, archive=None): def exists(self, archive=None):
"""Return True if the file exists on disk or in 'archive'""" """Return True if the file exists on disk or in 'archive'"""
if (archive and archive.check(self.keywords) or if archive and archive.check(self.keywords):
self.has_extension and os.path.exists(self.realpath)): return self.fix_extension()
if not self.has_extension: if self.has_extension and os.path.exists(self.realpath):
# adjust display name
self.set_extension("")
if self.path[-1] == ".":
self.path = self.path[:-1]
return True return True
return False return False
@@ -590,6 +586,14 @@ class PathFormat():
self.keywords["extension"] = extension self.keywords["extension"] = extension
self.build_path() 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): def build_path(self):
"""Use filename-keywords and directory to build a full path""" """Use filename-keywords and directory to build a full path"""
try: try: