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,9 +78,8 @@ def main():
elif sys.argv[1] == "convert": elif sys.argv[1] == "convert":
counter = 0 counter = 0
nbuseful = len([filepath for filepath in medialibrary.videos if medialibrary.videos[filepath].useful]) keylist = [filepath for filepath in medialibrary.videos if medialibrary.videos[filepath].useful]
for filepath in medialibrary.videos: for filepath in keylist:
if medialibrary.videos[filepath].useful:
counter += 1 counter += 1
# Setting required variables # Setting required variables
if "av1" in outputs: if "av1" in outputs:
@ -89,18 +88,28 @@ def main():
vcodec = "x265" vcodec = "x265"
# Verbosing # 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}****** 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.OKGREEN}Original file:{BColors.ENDC}") print(f"{BColors.OKCYAN}Original file:{BColors.ENDC}")
print(medialibrary.videos[filepath]) print(medialibrary.videos[filepath])
print(f"{BColors.OKGREEN}Converting please wait...{BColors.ENDC}") print(f"{BColors.OKGREEN}Converting please wait...{BColors.ENDC}")
# Converting # Converting
if medialibrary.videos[filepath].convert(): if medialibrary.videos[filepath].convert():
newvid = Video(medialibrary.videos[filepath].path + medialibrary.videos[filepath].filename_new) # Mark the job as done
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}") medialibrary.videos[filepath].useful = False
print(newvid)
# 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)
# TODO delete file when -del

View File

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

View File

@ -2,6 +2,7 @@
'''Its a video!''' '''Its a video!'''
from .bcolors import BColors from .bcolors import BColors
from .tools import deletefile
import subprocess import subprocess
import os import os
import sys import sys
@ -62,17 +63,18 @@ class Video():
else: else:
txt = subprocess.check_output(args, stderr=subprocess.STDOUT) txt = subprocess.check_output(args, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
deletefile(self.path + self.filename_tmp)
self.filename_tmp = "" self.filename_tmp = ""
print(f"{BColors.FAIL}Conversion failed {e}{BColors.ENDC}") print(f"{BColors.FAIL}Conversion failed {e}{BColors.ENDC}")
return False 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: else:
self.filename_new = self.filename_tmp self.filename_new = self.filename_tmp
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 return True