Moved arguments loading to its own function
This commit is contained in:
parent
fb5e5cc8ea
commit
09d7d2c537
1
TODO.md
1
TODO.md
@ -12,6 +12,7 @@ Project
|
|||||||
* Add service
|
* Add service
|
||||||
* Make proper raises
|
* Make proper raises
|
||||||
* Document usable modules / imports
|
* Document usable modules / imports
|
||||||
|
* Filelist option
|
||||||
|
|
||||||
Modules
|
Modules
|
||||||
-------
|
-------
|
||||||
|
|||||||
@ -112,6 +112,10 @@ class MediaLibrary():
|
|||||||
# filter for filetypes
|
# filter for filetypes
|
||||||
if len([filtr for filtr in self.filters if filtr in ["old", "mpeg4", "mpeg", "wmv3", "wmv", "h264", "hevc", "x265", "av1"]]) > 0:
|
if len([filtr for filtr in self.filters if filtr in ["old", "mpeg4", "mpeg", "wmv3", "wmv", "h264", "hevc", "x265", "av1"]]) > 0:
|
||||||
useful = False
|
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"]:
|
if "old" in self.filters and self.videos[filepath].codec not in ["hevc", "av1"]:
|
||||||
useful = True
|
useful = True
|
||||||
if ("mpeg4" in self.filters or "mpeg" in self.filters) and self.videos[filepath].codec in ["mpeg4", "msmpeg4v3"]:
|
if ("mpeg4" in self.filters or "mpeg" in self.filters) and self.videos[filepath].codec in ["mpeg4", "msmpeg4v3"]:
|
||||||
|
|||||||
@ -10,6 +10,39 @@ import colorama
|
|||||||
colorama.init()
|
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():
|
def detect_ffmpeg():
|
||||||
'''Returns the version of ffmpeg that is installed or false'''
|
'''Returns the version of ffmpeg that is installed or false'''
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -4,9 +4,9 @@
|
|||||||
* List all the video's and their codecs with or without filters
|
* 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 ...
|
* Batch recode videos to more modern codecs (x265 / AV1) based on filters: extentions, codecs ...
|
||||||
ex:
|
ex:
|
||||||
./converter.py list -in:any -filters:old -dirs:/mnt/media/ >> ../medlist.txt
|
mediacurator 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/"
|
mediacurator convert -del -in:any -filters:mpeg4 -out:x265,mkv -dirs:"/mnt/media/Movies/"
|
||||||
./converter.py convert -del -in:avi,mpg -dirs:/mnt/media/
|
mediacurator convert -del -in:avi,mpg -dirs:/mnt/media/
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@ -15,12 +15,12 @@ import sys
|
|||||||
try:
|
try:
|
||||||
from mediacurator.library.video import Video
|
from mediacurator.library.video import Video
|
||||||
from mediacurator.library.medialibrary import MediaLibrary
|
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
|
# Allow local import for development purposes
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
from library.video import Video
|
from library.video import Video
|
||||||
from library.medialibrary import MediaLibrary
|
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
|
import colorama
|
||||||
@ -45,38 +45,13 @@ def main():
|
|||||||
print(f"{colorama.Fore.BLUE}ffmpeg version detected: {ffmpeg_version}{colorama.Fore.RESET}")
|
print(f"{colorama.Fore.BLUE}ffmpeg version detected: {ffmpeg_version}{colorama.Fore.RESET}")
|
||||||
|
|
||||||
# Get/load command parameters
|
# Get/load command parameters
|
||||||
directories = []
|
arguments = load_arguments()
|
||||||
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(",,")
|
|
||||||
|
|
||||||
# Loading the media library
|
# Loading the media library
|
||||||
if len(files) > 0:
|
if len(arguments["files"]) > 0:
|
||||||
medialibrary = MediaLibrary(files = files, inputs = inputs, filters = filters)
|
medialibrary = MediaLibrary(files = arguments["files"], inputs = arguments["inputs"], filters = arguments["filters"])
|
||||||
elif len(directories) > 0:
|
elif len(arguments["directories"]) > 0:
|
||||||
medialibrary = MediaLibrary(directories = directories, inputs = inputs, filters = filters)
|
medialibrary = MediaLibrary(directories = arguments["directories"], inputs = arguments["inputs"], filters = arguments["filters"])
|
||||||
else:
|
else:
|
||||||
print(f"{colorama.Fore.RED}ERROR: No files or directories selected.{colorama.Fore.RESET}")
|
print(f"{colorama.Fore.RED}ERROR: No files or directories selected.{colorama.Fore.RESET}")
|
||||||
return
|
return
|
||||||
@ -91,7 +66,7 @@ def main():
|
|||||||
|
|
||||||
for filepath in keylist:
|
for filepath in keylist:
|
||||||
if medialibrary.videos[filepath].useful:
|
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:
|
if medialibrary.videos[filepath].error:
|
||||||
print(f"{colorama.Fore.RED}{medialibrary.videos[filepath].fprint()}{colorama.Fore.RESET}")
|
print(f"{colorama.Fore.RED}{medialibrary.videos[filepath].fprint()}{colorama.Fore.RESET}")
|
||||||
else:
|
else:
|
||||||
@ -113,7 +88,7 @@ def main():
|
|||||||
|
|
||||||
for filepath in keylist:
|
for filepath in keylist:
|
||||||
if medialibrary.videos[filepath].useful:
|
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:
|
if medialibrary.videos[filepath].error:
|
||||||
print(f"{colorama.Fore.RED}{medialibrary.videos[filepath].fprint()}{colorama.Fore.RESET}")
|
print(f"{colorama.Fore.RED}{medialibrary.videos[filepath].fprint()}{colorama.Fore.RESET}")
|
||||||
else:
|
else:
|
||||||
@ -138,7 +113,7 @@ def main():
|
|||||||
for filepath in keylist:
|
for filepath in keylist:
|
||||||
counter += 1
|
counter += 1
|
||||||
# Setting required variables
|
# Setting required variables
|
||||||
if "av1" in outputs:
|
if "av1" in arguments["outputs"]:
|
||||||
vcodec = "av1"
|
vcodec = "av1"
|
||||||
else:
|
else:
|
||||||
vcodec = "x265"
|
vcodec = "x265"
|
||||||
@ -146,7 +121,7 @@ def main():
|
|||||||
# Verbosing
|
# 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.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}")
|
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())
|
print(medialibrary.videos[filepath].fprint())
|
||||||
else:
|
else:
|
||||||
print(medialibrary.videos[filepath])
|
print(medialibrary.videos[filepath])
|
||||||
@ -154,20 +129,20 @@ def main():
|
|||||||
print(f"{colorama.Fore.GREEN}Converting please wait...{colorama.Fore.RESET}", end="\r")
|
print(f"{colorama.Fore.GREEN}Converting please wait...{colorama.Fore.RESET}", end="\r")
|
||||||
|
|
||||||
# Converting
|
# 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
|
# Mark the job as done
|
||||||
medialibrary.videos[filepath].useful = False
|
medialibrary.videos[filepath].useful = False
|
||||||
|
|
||||||
# Scan the new video
|
# Scan the new video
|
||||||
newfpath = medialibrary.videos[filepath].path + medialibrary.videos[filepath].filename_new
|
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
|
# 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}")
|
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:
|
if medialibrary.videos[newfpath].error:
|
||||||
print(f"{colorama.Fore.RED}{medialibrary.videos[newfpath].fprint()}{colorama.Fore.RESET}")
|
print(f"{colorama.Fore.RED}{medialibrary.videos[newfpath].fprint()}{colorama.Fore.RESET}")
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user