From d2c023a437f9e47b508b1f0d30171b3fac4f7d1a Mon Sep 17 00:00:00 2001 From: julia-bikova Date: Fri, 29 May 2015 23:40:43 +0500 Subject: [PATCH 1/2] Changes in check of file path Previously, if you had entered a non-existent path load falling on a line 961 with an error "Not such file or directory: 'name_of_file.tmp'". Changed check the file path: added an Exception when entering a non-existent path, plus refactoring - got rid of one variable. --- pafy/pafy.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/pafy/pafy.py b/pafy/pafy.py index ed43153a..d1e8a27a 100644 --- a/pafy/pafy.py +++ b/pafy/pafy.py @@ -926,18 +926,17 @@ def download(self, filepath="", quiet=False, callback=lambda *x: None, """ # pylint: disable=R0912,R0914 # Too many branches, too many local vars - savedir = filename = "" - - if filepath and os.path.isdir(filepath): - savedir, filename = filepath, self.generate_filename() - - elif filepath: - savedir, filename = os.path.split(filepath) - + if filepath: + if os.path.exists(filepath): + if os.path.isdir(filepath): + filepath = os.path.join(filepath, self.generate_filename(meta=meta)) + else: + path_dir = os.path.split(filepath)[0] + if path_dir and not os.path.exists(path_dir): + raise Exception('No such file or directory: ' + filepath) else: - filename = self.generate_filename(meta=meta) - - filepath = os.path.join(savedir, filename) + filepath = self.generate_filename(meta=meta) + temp_filepath = filepath + ".temp" status_string = (' {:,} Bytes [{:.2%}] received. Rate: [{:4.0f} ' From 5a9569462429ea8998741cd603efe53051d30fa7 Mon Sep 17 00:00:00 2001 From: julia-bikova Date: Sun, 31 May 2015 11:51:07 +0500 Subject: [PATCH 2/2] IOError instead of common Exception IOError instead of common Exception --- pafy/pafy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pafy/pafy.py b/pafy/pafy.py index d1e8a27a..2ce59b2d 100644 --- a/pafy/pafy.py +++ b/pafy/pafy.py @@ -933,7 +933,7 @@ def download(self, filepath="", quiet=False, callback=lambda *x: None, else: path_dir = os.path.split(filepath)[0] if path_dir and not os.path.exists(path_dir): - raise Exception('No such file or directory: ' + filepath) + raise IOError('No such file or directory: ' + filepath) else: filepath = self.generate_filename(meta=meta)