diff --git a/TODO.md b/TODO.md index 39f5bee..3fb662e 100644 --- a/TODO.md +++ b/TODO.md @@ -12,6 +12,7 @@ Project * Add service * Make proper raises * Document usable modules / imports +* Filelist option Modules ------- diff --git a/mediacurator/library/medialibrary.py b/mediacurator/library/medialibrary.py index 015bf13..3595235 100644 --- a/mediacurator/library/medialibrary.py +++ b/mediacurator/library/medialibrary.py @@ -112,6 +112,10 @@ class MediaLibrary(): # filter for filetypes if len([filtr for filtr in self.filters if filtr in ["old", "mpeg4", "mpeg", "wmv3", "wmv", "h264", "hevc", "x265", "av1"]]) > 0: useful = False + if not self.videos[filepath].hasattr("codec"): + print(filepath) + exit() + # ERT1 if "old" in self.filters and self.videos[filepath].codec not in ["hevc", "av1"]: useful = True if ("mpeg4" in self.filters or "mpeg" in self.filters) and self.videos[filepath].codec in ["mpeg4", "msmpeg4v3"]: diff --git a/mediacurator/library/tools.py b/mediacurator/library/tools.py index 4e51daa..4c25705 100644 --- a/mediacurator/library/tools.py +++ b/mediacurator/library/tools.py @@ -10,6 +10,39 @@ import colorama colorama.init() +def load_arguments(): + arguments = { + "directories":list(), + "files":list(), + "inputs":list(), + "filters":list(), + "outputs":list(), + "printop":list(), + } + + for arg in sys.argv: + # Confirm with the user that he selected to delete found files + if "-del" in arg: + print(f"{colorama.Fore.YELLOW}WARNING: Delete option selected!{colorama.Fore.RESET}") + if not user_confirm(f"Are you sure you wish to delete all found results after selected operations are succesfull ? [Y/N] ?", color="yellow"): + print(f"{colorama.Fore.GREEN}Exiting!{colorama.Fore.RESET}") + exit() + elif "-in:" in arg: + arguments["inputs"] += arg[4:].split(",") + elif "-filters:" in arg: + arguments["filters"] += arg[9:].split(",") + elif "-out:" in arg: + arguments["outputs"] += arg[5:].split(",") + elif "-print:" in arg: + arguments["printop"] += arg[7:].split(",") + elif "-files:" in arg: + arguments["files"] += arg[7:].split(",,") + elif "-dirs:" in arg: + arguments["directories"] += arg[6:].split(",,") + + return arguments + + def detect_ffmpeg(): '''Returns the version of ffmpeg that is installed or false''' try: diff --git a/mediacurator/mediacurator.py b/mediacurator/mediacurator.py index a615d9c..7898066 100755 --- a/mediacurator/mediacurator.py +++ b/mediacurator/mediacurator.py @@ -4,9 +4,9 @@ * List all the video's and their codecs with or without filters * Batch recode videos to more modern codecs (x265 / AV1) based on filters: extentions, codecs ... ex: - ./converter.py list -in:any -filters:old -dirs:/mnt/media/ >> ../medlist.txt - ./converter.py convert -del -in:any -filters:mpeg4 -out:x265,mkv -dirs:"/mnt/media/Movies/" - ./converter.py convert -del -in:avi,mpg -dirs:/mnt/media/ + mediacurator list -in:any -filters:old -dirs:/mnt/media/ >> ../medlist.txt + mediacurator convert -del -in:any -filters:mpeg4 -out:x265,mkv -dirs:"/mnt/media/Movies/" + mediacurator convert -del -in:avi,mpg -dirs:/mnt/media/ ''' import sys @@ -15,12 +15,12 @@ import sys try: from mediacurator.library.video import Video from mediacurator.library.medialibrary import MediaLibrary - from mediacurator.library.tools import detect_ffmpeg, user_confirm + from mediacurator.library.tools import detect_ffmpeg, user_confirm, load_arguments # Allow local import for development purposes except ModuleNotFoundError: from library.video import Video from library.medialibrary import MediaLibrary - from library.tools import detect_ffmpeg, user_confirm + from library.tools import detect_ffmpeg, user_confirm, load_arguments import colorama @@ -45,38 +45,13 @@ def main(): print(f"{colorama.Fore.BLUE}ffmpeg version detected: {ffmpeg_version}{colorama.Fore.RESET}") # Get/load command parameters - directories = [] - files = [] - inputs = [] - filters = [] - outputs = [] - printop = [] - - for arg in sys.argv: - # Confirm with the user that he selected to delete found files - if "-del" in arg: - print(f"{colorama.Fore.YELLOW}WARNING: Delete option selected!{colorama.Fore.RESET}") - if not user_confirm(f"Are you sure you wish to delete all found results after selected operations are succesfull ? [Y/N] ?", color="yellow"): - print(f"{colorama.Fore.GREEN}Exiting!{colorama.Fore.RESET}") - exit() - elif "-in:" in arg: - inputs += arg[4:].split(",") - elif "-filters:" in arg: - filters += arg[9:].split(",") - elif "-out:" in arg: - outputs += arg[5:].split(",") - elif "-print:" in arg: - printop += arg[7:].split(",") - elif "-files:" in arg: - files += arg[7:].split(",,") - elif "-dirs:" in arg: - directories += arg[6:].split(",,") + arguments = load_arguments() # Loading the media library - if len(files) > 0: - medialibrary = MediaLibrary(files = files, inputs = inputs, filters = filters) - elif len(directories) > 0: - medialibrary = MediaLibrary(directories = directories, inputs = inputs, filters = filters) + if len(arguments["files"]) > 0: + medialibrary = MediaLibrary(files = arguments["files"], inputs = arguments["inputs"], filters = arguments["filters"]) + elif len(arguments["directories"]) > 0: + medialibrary = MediaLibrary(directories = arguments["directories"], inputs = arguments["inputs"], filters = arguments["filters"]) else: print(f"{colorama.Fore.RED}ERROR: No files or directories selected.{colorama.Fore.RESET}") return @@ -91,7 +66,7 @@ def main(): for filepath in keylist: if medialibrary.videos[filepath].useful: - if "formated" in printop or "verbose" in printop: + if "formated" in arguments["printop"] or "verbose" in arguments["printop"]: if medialibrary.videos[filepath].error: print(f"{colorama.Fore.RED}{medialibrary.videos[filepath].fprint()}{colorama.Fore.RESET}") else: @@ -113,7 +88,7 @@ def main(): for filepath in keylist: if medialibrary.videos[filepath].useful: - if "formated" in printop or "verbose" in printop: + if "formated" in arguments["printop"] or "verbose" in arguments["printop"]: if medialibrary.videos[filepath].error: print(f"{colorama.Fore.RED}{medialibrary.videos[filepath].fprint()}{colorama.Fore.RESET}") else: @@ -138,7 +113,7 @@ def main(): for filepath in keylist: counter += 1 # Setting required variables - if "av1" in outputs: + if "av1" in arguments["outputs"]: vcodec = "av1" else: vcodec = "x265" @@ -146,7 +121,7 @@ def main(): # Verbosing print(f"{colorama.Fore.GREEN}****** Starting conversion {counter} of {len(keylist)}: '{colorama.Fore.CYAN}{medialibrary.videos[filepath].filename_origin}{colorama.Fore.GREEN}' from {colorama.Fore.CYAN}{medialibrary.videos[filepath].codec}{colorama.Fore.GREEN} to {colorama.Fore.CYAN}{vcodec}{colorama.Fore.GREEN}...{colorama.Fore.RESET}") print(f"{colorama.Fore.CYAN}Original file:{colorama.Fore.RESET}") - if "formated" in printop or "verbose" in printop: + if "formated" in arguments["printop"] or "verbose" in arguments["printop"]: print(medialibrary.videos[filepath].fprint()) else: print(medialibrary.videos[filepath]) @@ -154,20 +129,20 @@ def main(): print(f"{colorama.Fore.GREEN}Converting please wait...{colorama.Fore.RESET}", end="\r") # Converting - if medialibrary.videos[filepath].convert(verbose = "verbose" in printop): + if medialibrary.videos[filepath].convert(verbose = "verbose" in arguments["printop"]): # 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, verbose = "verbose" in printop) + medialibrary.videos[newfpath] = Video(newfpath, verbose = "verbose" in arguments["printop"]) # Verbose print(f"{colorama.Fore.GREEN}Successfully converted '{medialibrary.videos[filepath].filename_origin}'{colorama.Fore.CYAN}({medialibrary.videos[filepath].filesize}mb){colorama.Fore.GREEN} to '{medialibrary.videos[newfpath].filename_origin}'{colorama.Fore.CYAN}({medialibrary.videos[newfpath].filesize}mb){colorama.Fore.GREEN}, {colorama.Fore.CYAN}new file:{colorama.Fore.RESET}") - if "formated" in printop or "verbose" in printop: + if "formated" in arguments["printop"] or "verbose" in arguments["printop"]: if medialibrary.videos[newfpath].error: print(f"{colorama.Fore.RED}{medialibrary.videos[newfpath].fprint()}{colorama.Fore.RESET}") else: