Deleting on successfull and failed conversions now working. Must be tested further

This commit is contained in:
Fabrice Quenneville 2020-11-18 20:58:06 -05:00
parent c549f24774
commit 78efbfe827
3 changed files with 37 additions and 26 deletions

View File

@ -78,29 +78,38 @@ def main():
elif sys.argv[1] == "convert":
counter = 0
nbuseful = len([filepath for filepath in medialibrary.videos if medialibrary.videos[filepath].useful])
for filepath in medialibrary.videos:
if medialibrary.videos[filepath].useful:
counter += 1
# Setting required variables
if "av1" in outputs:
vcodec = "av1"
else:
vcodec = "x265"
keylist = [filepath for filepath in medialibrary.videos if medialibrary.videos[filepath].useful]
for filepath in keylist:
counter += 1
# Setting required variables
if "av1" in outputs:
vcodec = "av1"
else:
vcodec = "x265"
# Verbosing
print(f"{BColors.OKCYAN}****** Starting conversion {counter} of {nbuseful}: '{BColors.OKGREEN}{medialibrary.videos[filepath].filename_origin}{BColors.OKCYAN}' from {BColors.OKGREEN}{medialibrary.videos[filepath].codec}{BColors.OKCYAN} to {BColors.OKGREEN}{vcodec}{BColors.OKCYAN}...{BColors.ENDC}")
print(f"{BColors.OKGREEN}Original file:{BColors.ENDC}")
print(medialibrary.videos[filepath])
print(f"{BColors.OKGREEN}Converting please wait...{BColors.ENDC}")
# Verbosing
print(f"{BColors.OKGREEN}****** Starting conversion {counter} of {len(keylist)}: '{BColors.OKCYAN}{medialibrary.videos[filepath].filename_origin}{BColors.OKGREEN}' from {BColors.OKCYAN}{medialibrary.videos[filepath].codec}{BColors.OKGREEN} to {BColors.OKCYAN}{vcodec}{BColors.OKGREEN}...{BColors.ENDC}")
print(f"{BColors.OKCYAN}Original file:{BColors.ENDC}")
print(medialibrary.videos[filepath])
print(f"{BColors.OKGREEN}Converting please wait...{BColors.ENDC}")
# Converting
if medialibrary.videos[filepath].convert():
# Mark the job as done
medialibrary.videos[filepath].useful = False
# Scan the new video
newfpath = medialibrary.videos[filepath].path + medialibrary.videos[filepath].filename_new
medialibrary.videos[newfpath] = Video(newfpath)
# Vervose
print(f"{BColors.OKGREEN}Successfully converted '{medialibrary.videos[filepath].filename_origin}'{BColors.OKCYAN}({medialibrary.videos[filepath].filesize}mb){BColors.OKGREEN} to '{medialibrary.videos[newfpath].filename_origin}'{BColors.OKCYAN}({medialibrary.videos[newfpath].filesize}mb){BColors.OKGREEN} , {BColors.OKCYAN}new file:{BColors.ENDC}")
print(medialibrary.videos[newfpath])
if "-del" in sys.argv:
medialibrary.unwatch(filepath, delete = True)
# Converting
if medialibrary.videos[filepath].convert():
newvid = Video(medialibrary.videos[filepath].path + medialibrary.videos[filepath].filename_new)
print(f"{BColors.OKGREEN}Converted {medialibrary.videos[filepath].filename_origin}{BColors.OKCYAN}({medialibrary.videos[filepath].filesize}mb){BColors.OKGREEN} to {newvid.filename_origin}{BColors.OKCYAN}({newvid.filesize}mb){BColors.OKGREEN} successfully, new file:{BColors.ENDC}")
print(newvid)
# TODO delete file when -del

View File

@ -31,5 +31,5 @@ def deletefile(filename):
print(f"{BColors.FAIL}Error deleting {filename}{BColors.ENDC}")
return False
print(f"{BColors.OKGREEN}Deleted {filename}{BColors.ENDC}")
print(f"{BColors.OKGREEN}Successfully deleted {filename}{BColors.ENDC}")
return True

View File

@ -2,6 +2,7 @@
'''Its a video!'''
from .bcolors import BColors
from .tools import deletefile
import subprocess
import os
import sys
@ -62,17 +63,18 @@ class Video():
else:
txt = subprocess.check_output(args, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
deletefile(self.path + self.filename_tmp)
self.filename_tmp = ""
print(f"{BColors.FAIL}Conversion failed {e}{BColors.ENDC}")
return False
except KeyboardInterrupt:
print(f"{BColors.WARNING}Conversion cancelled, cleaning up...{BColors.ENDC}")
deletefile(self.path + self.filename_tmp)
self.filename_tmp = ""
exit()
else:
self.filename_new = self.filename_tmp
self.filename_tmp = ""
#newsize = get_size(newfilename)
#oldfilename = str(oldfilename)[str(oldfilename).rindex("/") + 1:]
#newfilename = str(newfilename)[str(newfilename).rindex("/") + 1:]
#print(f"{BColors.OKGREEN}Converted {oldfilename}{BColors.OKCYAN}({oldsize}mb){BColors.OKGREEN} to {newfilename}{BColors.OKCYAN}({newsize}mb){BColors.OKGREEN} successfully{BColors.ENDC}")
return True