Better handling of FileNotFoundError

This commit is contained in:
Fabrice Quenneville 2020-11-22 15:01:20 -05:00
parent d1ba9c9571
commit e2315c3e7d
2 changed files with 32 additions and 19 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
**/__pycache__ **/__pycache__
test.sh test.sh
renamelist.txt renamelist.txt
.vscode

View File

@ -12,7 +12,7 @@ class Video():
path = str() path = str()
filename_origin = str() filename_origin = str()
filesize = int() filesize = int(0)
filename_new = str() filename_new = str()
filename_tmp = str() filename_tmp = str()
useful = bool() useful = bool()
@ -31,6 +31,11 @@ class Video():
self.path = str(filepath)[:str(filepath).rindex("/") + 1] self.path = str(filepath)[:str(filepath).rindex("/") + 1]
self.filename_origin = str(filepath)[str(filepath).rindex("/") + 1:] self.filename_origin = str(filepath)[str(filepath).rindex("/") + 1:]
if not os.path.exists(filepath):
self.error = f"FileNotFoundError: [Errno 2] No such file or directory: '{filepath}'"
self.useful = useful
else:
# Marking useful is user manually set it. # Marking useful is user manually set it.
self.useful = useful self.useful = useful
@ -54,10 +59,13 @@ class Video():
def __str__(self): def __str__(self):
'''Returns a short formated string about the video''' '''Returns a short formated string about the video'''
if type(self.error) is str and "FileNotFoundError" in self.error:
return self.error
text = f"{self.codec} - " text = f"{self.codec} - "
# If the first character of the definition is not a number (ie UHD and not 720p) upper it # If the first character of the definition is not a number (ie UHD and not 720p) upper it
if self.definition[0] and not self.definition[0].isnumeric(): if self.definition and self.definition[0] and not self.definition[0].isnumeric():
text += f"{self.definition.upper()}: ({self.width}x{self.height}) - " text += f"{self.definition.upper()}: ({self.width}x{self.height}) - "
else: else:
text += f"{self.definition}: ({self.width}x{self.height}) - " text += f"{self.definition}: ({self.width}x{self.height}) - "
@ -85,11 +93,15 @@ class Video():
def fprint(self): def fprint(self):
'''Returns a long formated string about the video ''' '''Returns a long formated string about the video '''
if type(self.error) is str and "FileNotFoundError" in self.error:
return self.error
text = f"{self.path + self.filename_origin}\n" text = f"{self.path + self.filename_origin}\n"
#text += f" Useful: {self.useful}\n" #text += f" Useful: {self.useful}\n"
# If the first character of the definition is not a number (ie UHD and not 720p) upper it # If the first character of the definition is not a number (ie UHD and not 720p) upper it
if self.definition[0] and not self.definition[0].isnumeric(): if self.definition and self.definition[0] and not self.definition[0].isnumeric():
text += f" Definition: {self.definition.upper()}: ({self.width}x{self.height})\n" text += f" Definition: {self.definition.upper()}: ({self.width}x{self.height})\n"
else: else:
text += f" Definition: {self.definition}: ({self.width}x{self.height})\n" text += f" Definition: {self.definition}: ({self.width}x{self.height})\n"