diff --git a/gallery_dl/downloader/common.py b/gallery_dl/downloader/common.py index c55975b7..b82cd80f 100644 --- a/gallery_dl/downloader/common.py +++ b/gallery_dl/downloader/common.py @@ -19,16 +19,14 @@ class BasicDownloader(): def download(self, url, pathfmt): """Download the resource at 'url' and write it to a file-like object""" try: - return self.download_impl(url, pathfmt) - except: - # remove file if download failed - try: - if self.downloading: - os.unlink(pathfmt.realpath) - except (AttributeError, FileNotFoundError): - pass - raise + self.download_impl(url, pathfmt) + finally: + # remove file from incomplete downloads + if self.downloading: + try: + os.remove(pathfmt.realpath) + except (OSError, AttributeError): + pass def download_impl(self, url, file_handle): """Actual implementaion of the download process""" - pass diff --git a/gallery_dl/downloader/http.py b/gallery_dl/downloader/http.py index b14acb63..6ba2ac9d 100644 --- a/gallery_dl/downloader/http.py +++ b/gallery_dl/downloader/http.py @@ -72,14 +72,14 @@ class Downloader(BasicDownloader): # everything ok -- proceed to download self.out.start(pathfmt.path) self.downloading = True - with pathfmt.open() as file: - try: - for data in response.iter_content(None): + try: + with pathfmt.open() as file: + for data in response.iter_content(16384): file.write(data) - except rexcepts.RequestException as exception: - msg = exception - response.close() - continue + except rexcepts.RequestException as exception: + msg = exception + response.close() + continue self.downloading = False self.out.success(pathfmt.path, tries) return