diff --git a/gallery_dl/downloader/common.py b/gallery_dl/downloader/common.py index 6c3012a3..6e08b9ad 100644 --- a/gallery_dl/downloader/common.py +++ b/gallery_dl/downloader/common.py @@ -15,6 +15,9 @@ class BasicDownloader(): max_tries = 5 + def __init__(self): + self.downloading = False + def download(self, url, pathfmt): """Download the resource at 'url' and write it to a file-like object""" try: @@ -22,7 +25,8 @@ class BasicDownloader(): except: # remove file if download failed try: - os.unlink(pathfmt.realpath) + if self.downloading: + os.unlink(pathfmt.realpath) except (AttributeError, FileNotFoundError): pass raise diff --git a/gallery_dl/downloader/http.py b/gallery_dl/downloader/http.py index 488d186f..b472ebd9 100644 --- a/gallery_dl/downloader/http.py +++ b/gallery_dl/downloader/http.py @@ -61,9 +61,11 @@ class Downloader(BasicDownloader): return self.out.start(pathfmt.path) + self.downloading = True with pathfmt.open() as file: for data in response.iter_content(16384): file.write(data) + self.downloading = False self.out.success(pathfmt.path, tries) def set_headers(self, headers): diff --git a/gallery_dl/downloader/text.py b/gallery_dl/downloader/text.py index fdfd685f..f326334c 100644 --- a/gallery_dl/downloader/text.py +++ b/gallery_dl/downloader/text.py @@ -24,6 +24,8 @@ class Downloader(BasicDownloader): return self.out.start(pathfmt.path) + self.downloading = True with pathfmt.open() as file: file.write(bytes(url[7:], "utf-8")) + self.downloading = False self.out.success(pathfmt.path, 0)