diff --git a/mediacurator/curator.py b/mediacurator/curator.py index 6fdebb5..6a787a9 100755 --- a/mediacurator/curator.py +++ b/mediacurator/curator.py @@ -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 diff --git a/mediacurator/library/tools.py b/mediacurator/library/tools.py index 087fe6c..1c0b3c0 100644 --- a/mediacurator/library/tools.py +++ b/mediacurator/library/tools.py @@ -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 \ No newline at end of file diff --git a/mediacurator/library/video.py b/mediacurator/library/video.py index b6d0ddb..786c325 100644 --- a/mediacurator/library/video.py +++ b/mediacurator/library/video.py @@ -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