chore: applied code formatting across mediacurator modules
Formatted code to improve consistency and readability across the following files: - mediacurator/__init__.py - mediacurator/library/__init__.py - mediacurator/library/medialibrary.py - mediacurator/library/tools.py - mediacurator/library/video.py - mediacurator/mediacurator.py - setup.py No functional changes were made, only cosmetic improvements.
This commit is contained in:
parent
89452e8fa4
commit
448c673385
@ -8,16 +8,23 @@ from .tools import deletefile
|
||||
|
||||
# Import colorama for colored output
|
||||
import colorama
|
||||
|
||||
colorama.init()
|
||||
|
||||
# Define color codes for colored output
|
||||
cgreen = colorama.Fore.GREEN
|
||||
creset = colorama.Fore.RESET
|
||||
|
||||
|
||||
class MediaLibrary():
|
||||
'''This class manages information about the workspace and all videos in it.'''
|
||||
|
||||
def __init__(self, files=False, directories=False, inputs=["any"], filters=[], verbose=False):
|
||||
def __init__(self,
|
||||
files=False,
|
||||
directories=False,
|
||||
inputs=["any"],
|
||||
filters=[],
|
||||
verbose=False):
|
||||
'''
|
||||
Initializes a MediaLibrary instance with provided parameters.
|
||||
|
||||
@ -70,41 +77,58 @@ class MediaLibrary():
|
||||
verbose (bool): A flag to enable verbose output.
|
||||
'''
|
||||
|
||||
print(f"{cgreen}Scanning files in {', '.join(map(str, self.directories))} for videos{creset}")
|
||||
print(
|
||||
f"{cgreen}Scanning files in {', '.join(map(str, self.directories))} for videos{creset}"
|
||||
)
|
||||
videolist = []
|
||||
|
||||
for directory in self.directories:
|
||||
path = Path(directory)
|
||||
# get all video filetypes
|
||||
if "wmv" in self.inputs or "any" in self.inputs or len(self.inputs) < 1:
|
||||
if "wmv" in self.inputs or "any" in self.inputs or len(
|
||||
self.inputs) < 1:
|
||||
videolist += list(path.rglob("*.[wW][mM][vV]"))
|
||||
if "avi" in self.inputs or "any" in self.inputs or len(self.inputs) < 1:
|
||||
if "avi" in self.inputs or "any" in self.inputs or len(
|
||||
self.inputs) < 1:
|
||||
videolist += list(path.rglob("*.[aA][vV][iI]"))
|
||||
if "mkv" in self.inputs or "any" in self.inputs or len(self.inputs) < 1:
|
||||
if "mkv" in self.inputs or "any" in self.inputs or len(
|
||||
self.inputs) < 1:
|
||||
videolist += list(path.rglob("*.[mM][kK][vV]"))
|
||||
if "mp4" in self.inputs or "any" in self.inputs or len(self.inputs) < 1:
|
||||
if "mp4" in self.inputs or "any" in self.inputs or len(
|
||||
self.inputs) < 1:
|
||||
videolist += list(path.rglob("*.[mM][pP]4"))
|
||||
if "m4v" in self.inputs or "any" in self.inputs or len(self.inputs) < 1:
|
||||
if "m4v" in self.inputs or "any" in self.inputs or len(
|
||||
self.inputs) < 1:
|
||||
videolist += list(path.rglob("*.[mM]4[vV]"))
|
||||
if "flv" in self.inputs or "any" in self.inputs or len(self.inputs) < 1:
|
||||
if "flv" in self.inputs or "any" in self.inputs or len(
|
||||
self.inputs) < 1:
|
||||
videolist += list(path.rglob("*.[fF][lL][vV]"))
|
||||
if "mpg" in self.inputs or "any" in self.inputs or len(self.inputs) < 1:
|
||||
if "mpg" in self.inputs or "any" in self.inputs or len(
|
||||
self.inputs) < 1:
|
||||
videolist += list(path.rglob("*.[mM][pP][gG]"))
|
||||
if "mov" in self.inputs or "any" in self.inputs or len(self.inputs) < 1:
|
||||
if "mov" in self.inputs or "any" in self.inputs or len(
|
||||
self.inputs) < 1:
|
||||
videolist += list(path.rglob("*.[mM][oO][vV]"))
|
||||
if "mpeg" in self.inputs or "any" in self.inputs or len(self.inputs) < 1:
|
||||
if "mpeg" in self.inputs or "any" in self.inputs or len(
|
||||
self.inputs) < 1:
|
||||
videolist += list(path.rglob("*.[mM][pP][eE][gG]"))
|
||||
if "vid" in self.inputs or "any" in self.inputs or len(self.inputs) < 1:
|
||||
if "vid" in self.inputs or "any" in self.inputs or len(
|
||||
self.inputs) < 1:
|
||||
videolist += list(path.rglob("*.[vV][iI][dD]"))
|
||||
if "vob" in self.inputs or "any" in self.inputs or len(self.inputs) < 1:
|
||||
if "vob" in self.inputs or "any" in self.inputs or len(
|
||||
self.inputs) < 1:
|
||||
videolist += list(path.rglob("*.[vV][oO][bB]"))
|
||||
if "divx" in self.inputs or "any" in self.inputs or len(self.inputs) < 1:
|
||||
if "divx" in self.inputs or "any" in self.inputs or len(
|
||||
self.inputs) < 1:
|
||||
videolist += list(path.rglob("*.[dD][iI][vV][xX]"))
|
||||
if "ogm" in self.inputs or "any" in self.inputs or len(self.inputs) < 1:
|
||||
if "ogm" in self.inputs or "any" in self.inputs or len(
|
||||
self.inputs) < 1:
|
||||
videolist += list(path.rglob("*.[oO][gG][mM]"))
|
||||
if "ts" in self.inputs or "any" in self.inputs or len(self.inputs) < 1:
|
||||
if "ts" in self.inputs or "any" in self.inputs or len(
|
||||
self.inputs) < 1:
|
||||
videolist += list(path.rglob("*.[tT][sS]"))
|
||||
if "webm" in self.inputs or "any" in self.inputs or len(self.inputs) < 1:
|
||||
if "webm" in self.inputs or "any" in self.inputs or len(
|
||||
self.inputs) < 1:
|
||||
videolist += list(path.rglob("*.[wW][eE][bB][mM]"))
|
||||
|
||||
# Remove folders
|
||||
@ -112,12 +136,15 @@ class MediaLibrary():
|
||||
videolist = [video for video in videolist_tmp if video.is_file()]
|
||||
|
||||
# Map it all to the videos dictionary as initiated Video objects
|
||||
print(f"{cgreen}Analyzing {len(videolist)} videos in {', '.join(map(str, self.directories))}{creset}")
|
||||
print(
|
||||
f"{cgreen}Analyzing {len(videolist)} videos in {', '.join(map(str, self.directories))}{creset}"
|
||||
)
|
||||
iteration = 0
|
||||
for video in videolist:
|
||||
if verbose:
|
||||
iteration += 1
|
||||
print(f'{int((iteration / len(videolist) * 100))}% complete', end='\r')
|
||||
print(f'{int((iteration / len(videolist) * 100))}% complete',
|
||||
end='\r')
|
||||
|
||||
self.videos[video] = Video(video, verbose=verbose)
|
||||
|
||||
@ -129,57 +156,89 @@ class MediaLibrary():
|
||||
verbose (bool): A flag to enable verbose output.
|
||||
'''
|
||||
|
||||
print(f"{cgreen}Filtering {len(self.videos)} videos for the requested parameters{creset}")
|
||||
print(
|
||||
f"{cgreen}Filtering {len(self.videos)} videos for the requested parameters{creset}"
|
||||
)
|
||||
|
||||
for filepath in self.videos:
|
||||
|
||||
# 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:
|
||||
operate = False
|
||||
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"]:
|
||||
operate = 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"
|
||||
]:
|
||||
operate = True
|
||||
if "mpeg" in self.filters and self.videos[filepath].codec in ["mpeg1video"]:
|
||||
if "mpeg" in self.filters and self.videos[filepath].codec in [
|
||||
"mpeg1video"
|
||||
]:
|
||||
operate = True
|
||||
if ("wmv3" in self.filters or "wmv" in self.filters) and self.videos[filepath].codec in ["wmv3"]:
|
||||
if ("wmv3" in self.filters or "wmv" in self.filters
|
||||
) and self.videos[filepath].codec in ["wmv3"]:
|
||||
operate = True
|
||||
if "h264" in self.filters and self.videos[filepath].codec in ["h264"]:
|
||||
if "h264" in self.filters and self.videos[filepath].codec in [
|
||||
"h264"
|
||||
]:
|
||||
operate = True
|
||||
if ("hevc" in self.filters or "x265" in self.filters) and self.videos[filepath].codec in ["hevc"]:
|
||||
if ("hevc" in self.filters or "x265" in self.filters
|
||||
) and self.videos[filepath].codec in ["hevc"]:
|
||||
operate = True
|
||||
if "av1" in self.filters and self.videos[filepath].codec in ["av1"]:
|
||||
if "av1" in self.filters and self.videos[filepath].codec in [
|
||||
"av1"
|
||||
]:
|
||||
operate = True
|
||||
self.videos[filepath].operate = operate
|
||||
|
||||
# Keep video for operation if specified resolution
|
||||
if self.videos[filepath].operate and len([filtr for filtr in self.filters if filtr in ["lowres", "hd", "subsd", "sd", "720p", "1080p", "uhd"]]) > 0:
|
||||
if self.videos[filepath].operate and len([
|
||||
filtr for filtr in self.filters if filtr in
|
||||
["lowres", "hd", "subsd", "sd", "720p", "1080p", "uhd"]
|
||||
]) > 0:
|
||||
operate = False
|
||||
|
||||
if "subsd" in self.filters and self.videos[filepath].definition in ["subsd"]:
|
||||
if "subsd" in self.filters and self.videos[
|
||||
filepath].definition in ["subsd"]:
|
||||
operate = True
|
||||
if "sd" in self.filters and self.videos[filepath].definition in ["sd"]:
|
||||
if "sd" in self.filters and self.videos[
|
||||
filepath].definition in ["sd"]:
|
||||
operate = True
|
||||
if "720p" in self.filters and self.videos[filepath].definition in ["720p"]:
|
||||
if "720p" in self.filters and self.videos[
|
||||
filepath].definition in ["720p"]:
|
||||
operate = True
|
||||
if "1080p" in self.filters and self.videos[filepath].definition in ["1080p"]:
|
||||
if "1080p" in self.filters and self.videos[
|
||||
filepath].definition in ["1080p"]:
|
||||
operate = True
|
||||
if "uhd" in self.filters and self.videos[filepath].definition in ["uhd"]:
|
||||
if "uhd" in self.filters and self.videos[
|
||||
filepath].definition in ["uhd"]:
|
||||
operate = True
|
||||
if "lowres" in self.filters and self.videos[filepath].definition in ["subsd", "sd"]:
|
||||
if "lowres" in self.filters and self.videos[
|
||||
filepath].definition in ["subsd", "sd"]:
|
||||
operate = True
|
||||
if "hd" in self.filters and self.videos[filepath].definition in ["720p", "1080p", "uhd"]:
|
||||
if "hd" in self.filters and self.videos[
|
||||
filepath].definition in ["720p", "1080p", "uhd"]:
|
||||
operate = True
|
||||
self.videos[filepath].operate = operate
|
||||
|
||||
# Keep video for operation if ffmpeg error exists
|
||||
if self.videos[filepath].operate and len([filtr for filtr in self.filters if filtr in ["fferror"]]) > 0:
|
||||
if self.videos[filepath].operate and len(
|
||||
[filtr for filtr in self.filters if filtr in ["fferror"]]) > 0:
|
||||
operate = False
|
||||
if self.videos[filepath].error:
|
||||
operate = True
|
||||
self.videos[filepath].operate = operate
|
||||
|
||||
print(f"{cgreen}Found {len([filepath for filepath in self.videos if self.videos[filepath].operate])} videos for the requested parameters{creset}")
|
||||
print(
|
||||
f"{cgreen}Found {len([filepath for filepath in self.videos if self.videos[filepath].operate])} videos for the requested parameters{creset}"
|
||||
)
|
||||
|
||||
def unwatch(self, filepath, delete=False):
|
||||
'''
|
||||
|
||||
@ -9,6 +9,7 @@ import sys
|
||||
|
||||
# Import colorama for colored output
|
||||
import colorama
|
||||
|
||||
colorama.init()
|
||||
|
||||
# Define color codes for colored output
|
||||
@ -17,6 +18,7 @@ cyellow = colorama.Fore.YELLOW
|
||||
cred = colorama.Fore.RED
|
||||
creset = colorama.Fore.RESET
|
||||
|
||||
|
||||
def load_arguments():
|
||||
'''Get/load command parameters
|
||||
|
||||
@ -35,9 +37,10 @@ def load_arguments():
|
||||
for arg in sys.argv:
|
||||
# Confirm with the user that they selected to delete found files
|
||||
if "-del" in arg:
|
||||
print(
|
||||
f"{cyellow}WARNING: Delete option selected!{creset}")
|
||||
if not user_confirm(f"Are you sure you wish to delete all found results after selected operations are successful? [Y/N] ?", color="yellow"):
|
||||
print(f"{cyellow}WARNING: Delete option selected!{creset}")
|
||||
if not user_confirm(
|
||||
f"Are you sure you wish to delete all found results after selected operations are successful? [Y/N] ?",
|
||||
color="yellow"):
|
||||
print(f"{cgreen}Exiting!{creset}")
|
||||
exit()
|
||||
elif "-in:" in arg:
|
||||
@ -64,8 +67,8 @@ def detect_ffmpeg():
|
||||
False: If version retrieval failed
|
||||
'''
|
||||
try:
|
||||
txt = subprocess.check_output(
|
||||
['ffmpeg', '-version'], stderr=subprocess.STDOUT).decode()
|
||||
txt = subprocess.check_output(['ffmpeg', '-version'],
|
||||
stderr=subprocess.STDOUT).decode()
|
||||
if "ffmpeg version" in txt:
|
||||
# Strip the useless text
|
||||
return txt.split(' ')[2]
|
||||
|
||||
@ -7,6 +7,7 @@ import os
|
||||
|
||||
# Import colorama for colored output
|
||||
import colorama
|
||||
|
||||
colorama.init()
|
||||
|
||||
# Define color codes for colored output
|
||||
@ -14,6 +15,7 @@ cyellow = colorama.Fore.YELLOW
|
||||
cred = colorama.Fore.RED
|
||||
creset = colorama.Fore.RESET
|
||||
|
||||
|
||||
class Video():
|
||||
'''Contains the information and methods of a video file.'''
|
||||
|
||||
@ -42,10 +44,12 @@ class Video():
|
||||
# Break down the full path into its components
|
||||
if os.name == 'nt':
|
||||
self.path = str(filepath)[:str(filepath).rindex("\\") + 1]
|
||||
self.filename_origin = str(filepath)[str(filepath).rindex("\\") + 1:]
|
||||
self.filename_origin = str(filepath)[str(filepath).rindex("\\") +
|
||||
1:]
|
||||
else:
|
||||
self.path = str(filepath)[:str(filepath).rindex("/") + 1]
|
||||
self.filename_origin = str(filepath)[str(filepath).rindex("/") + 1:]
|
||||
self.filename_origin = str(filepath)[str(filepath).rindex("/") +
|
||||
1:]
|
||||
|
||||
if not os.path.exists(filepath):
|
||||
self.error = f"FileNotFoundError: [Errno 2] No such file or directory: '{filepath}'"
|
||||
@ -60,16 +64,16 @@ class Video():
|
||||
self.codec = self.detect_codec(filepath)
|
||||
try:
|
||||
self.width, self.height = self.detect_resolution(filepath)
|
||||
self.definition = self.detect_definition(
|
||||
width=self.width,
|
||||
height=self.height
|
||||
)
|
||||
self.definition = self.detect_definition(width=self.width,
|
||||
height=self.height)
|
||||
except:
|
||||
self.width, self.height = False, False
|
||||
self.definition = False
|
||||
|
||||
if self.error and verbose:
|
||||
print(f"{cred}There seems to be an error with \"{filepath}\"{creset}")
|
||||
print(
|
||||
f"{cred}There seems to be an error with \"{filepath}\"{creset}"
|
||||
)
|
||||
print(f"{cred} {self.error}{creset}")
|
||||
|
||||
def __str__(self):
|
||||
@ -85,7 +89,8 @@ class Video():
|
||||
text = f"{self.codec} - "
|
||||
|
||||
# If the first character of the definition is not a number (e.g., UHD and not 720p), upper it
|
||||
if self.definition and self.definition[0] and not self.definition[0].isnumeric():
|
||||
if self.definition and self.definition[
|
||||
0] and not self.definition[0].isnumeric():
|
||||
text += f"{self.definition.upper()}: ({self.width}x{self.height}) - "
|
||||
else:
|
||||
text += f"{self.definition}: ({self.width}x{self.height}) - "
|
||||
@ -119,7 +124,8 @@ class Video():
|
||||
|
||||
text = f"{self.path + self.filename_origin}\n"
|
||||
|
||||
if self.definition and self.definition[0] and not self.definition[0].isnumeric():
|
||||
if self.definition and self.definition[
|
||||
0] and not self.definition[0].isnumeric():
|
||||
text += f" Definition: {self.definition.upper()}: ({self.width}x{self.height})\n"
|
||||
else:
|
||||
text += f" Definition: {self.definition}: ({self.width}x{self.height})\n"
|
||||
@ -139,7 +145,11 @@ class Video():
|
||||
|
||||
return text
|
||||
|
||||
def convert(self, vcodec="x265", acodec=False, extension="mkv", verbose=False):
|
||||
def convert(self,
|
||||
vcodec="x265",
|
||||
acodec=False,
|
||||
extension="mkv",
|
||||
verbose=False):
|
||||
'''
|
||||
Converts the original file to the requested format / codec.
|
||||
|
||||
@ -159,17 +169,21 @@ class Video():
|
||||
if os.path.exists(self.path + newfilename):
|
||||
newfilename = findfreename(self.path + newfilename)
|
||||
if os.name == 'nt':
|
||||
newfilename = str(newfilename)[str(newfilename).rindex("\\") + 1:]
|
||||
newfilename = str(
|
||||
newfilename)[str(newfilename).rindex("\\") + 1:]
|
||||
else:
|
||||
newfilename = str(newfilename)[str(newfilename).rindex("/") + 1:]
|
||||
newfilename = str(
|
||||
newfilename)[str(newfilename).rindex("/") + 1:]
|
||||
else:
|
||||
newfilename = self.filename_origin[:-4] + ".mkv"
|
||||
if os.path.exists(self.path + newfilename):
|
||||
newfilename = findfreename(self.path + newfilename)
|
||||
if os.name == 'nt':
|
||||
newfilename = str(newfilename)[str(newfilename).rindex("\\") + 1:]
|
||||
newfilename = str(
|
||||
newfilename)[str(newfilename).rindex("\\") + 1:]
|
||||
else:
|
||||
newfilename = str(newfilename)[str(newfilename).rindex("/") + 1:]
|
||||
newfilename = str(
|
||||
newfilename)[str(newfilename).rindex("/") + 1:]
|
||||
|
||||
self.filename_tmp = newfilename
|
||||
|
||||
@ -216,7 +230,9 @@ class Video():
|
||||
try:
|
||||
os.chmod(f"{self.path}{self.filename_tmp}", 0o777)
|
||||
except PermissionError:
|
||||
print(f"{cred}PermissionError on: '{self.path}{self.filename_tmp}'{creset}")
|
||||
print(
|
||||
f"{cred}PermissionError on: '{self.path}{self.filename_tmp}'{creset}"
|
||||
)
|
||||
self.filename_new = self.filename_tmp
|
||||
self.filename_tmp = ""
|
||||
return True
|
||||
@ -255,7 +271,12 @@ class Video():
|
||||
'''
|
||||
output = False
|
||||
try:
|
||||
args = ["ffprobe", "-v", "quiet", "-select_streams", "v:0", "-show_entries", "stream=codec_name", "-of", "default=noprint_wrappers=1:nokey=1", str(filepath)]
|
||||
args = [
|
||||
"ffprobe", "-v", "quiet", "-select_streams", "v:0",
|
||||
"-show_entries", "stream=codec_name", "-of",
|
||||
"default=noprint_wrappers=1:nokey=1",
|
||||
str(filepath)
|
||||
]
|
||||
output = subprocess.check_output(args, stderr=subprocess.STDOUT)
|
||||
# Decoding from binary, stripping whitespace, keep only last line
|
||||
# in case ffprobe added error messages over the requested information
|
||||
@ -276,7 +297,11 @@ class Video():
|
||||
False: An error in the resolution fetching process.
|
||||
'''
|
||||
try:
|
||||
args = ["ffprobe", "-v", "quiet", "-select_streams", "v:0", "-show_entries", "stream=width,height", "-of", "csv=s=x:p=0", str(filepath)]
|
||||
args = [
|
||||
"ffprobe", "-v", "quiet", "-select_streams", "v:0",
|
||||
"-show_entries", "stream=width,height", "-of", "csv=s=x:p=0",
|
||||
str(filepath)
|
||||
]
|
||||
output = subprocess.check_output(args, stderr=subprocess.STDOUT)
|
||||
# Decoding from binary, stripping whitespace, keep only last line
|
||||
# in case ffprobe added error messages over the requested information
|
||||
|
||||
@ -24,6 +24,7 @@ except ModuleNotFoundError:
|
||||
|
||||
# Import colorama for colored output
|
||||
import colorama
|
||||
|
||||
colorama.init()
|
||||
|
||||
# Define color codes for colored output
|
||||
@ -33,6 +34,7 @@ cgreen = colorama.Fore.GREEN
|
||||
cred = colorama.Fore.RED
|
||||
creset = colorama.Fore.RESET
|
||||
|
||||
|
||||
def main():
|
||||
'''
|
||||
mediacurator's main function
|
||||
@ -44,7 +46,9 @@ def main():
|
||||
|
||||
# confirm that the command has enough parameters
|
||||
if len(sys.argv) < 2:
|
||||
print(f"{cred}ERROR: Command not understood, please see documentation.{creset}")
|
||||
print(
|
||||
f"{cred}ERROR: Command not understood, please see documentation.{creset}"
|
||||
)
|
||||
|
||||
# confirm that ffmpeg in indeed installed
|
||||
ffmpeg_version = detect_ffmpeg()
|
||||
@ -58,9 +62,13 @@ def main():
|
||||
|
||||
# Loading the media library
|
||||
if len(arguments["files"]) > 0:
|
||||
medialibrary = MediaLibrary(files = arguments["files"], inputs = arguments["inputs"], filters = arguments["filters"])
|
||||
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"])
|
||||
medialibrary = MediaLibrary(directories=arguments["directories"],
|
||||
inputs=arguments["inputs"],
|
||||
filters=arguments["filters"])
|
||||
else:
|
||||
print(f"{cred}ERROR: No files or directories selected.{creset}")
|
||||
return
|
||||
@ -68,14 +76,20 @@ def main():
|
||||
# Actions
|
||||
if sys.argv[1] == "list":
|
||||
# Pulling list of marked videos / original keys for the medialibrary.videos dictionary
|
||||
keylist = [filepath for filepath in medialibrary.videos if medialibrary.videos[filepath].operate]
|
||||
keylist = [
|
||||
filepath for filepath in medialibrary.videos
|
||||
if medialibrary.videos[filepath].operate
|
||||
]
|
||||
keylist.sort()
|
||||
|
||||
for filepath in keylist:
|
||||
if medialibrary.videos[filepath].operate:
|
||||
if "formated" in arguments["printop"] or "verbose" in arguments["printop"]:
|
||||
if "formated" in arguments[
|
||||
"printop"] or "verbose" in arguments["printop"]:
|
||||
if medialibrary.videos[filepath].error:
|
||||
print(f"{cred}{medialibrary.videos[filepath].fprint()}{creset}")
|
||||
print(
|
||||
f"{cred}{medialibrary.videos[filepath].fprint()}{creset}"
|
||||
)
|
||||
else:
|
||||
print(medialibrary.videos[filepath].fprint())
|
||||
else:
|
||||
@ -86,17 +100,23 @@ def main():
|
||||
|
||||
# if marked for deletion delete and unwatch the video
|
||||
if "-del" in sys.argv:
|
||||
medialibrary.unwatch(filepath, delete = True)
|
||||
medialibrary.unwatch(filepath, delete=True)
|
||||
elif sys.argv[1] == "test":
|
||||
# Pulling list of marked videos / original keys for the medialibrary.videos dictionary
|
||||
keylist = [filepath for filepath in medialibrary.videos if medialibrary.videos[filepath].operate]
|
||||
keylist = [
|
||||
filepath for filepath in medialibrary.videos
|
||||
if medialibrary.videos[filepath].operate
|
||||
]
|
||||
keylist.sort()
|
||||
|
||||
for filepath in keylist:
|
||||
if medialibrary.videos[filepath].operate:
|
||||
if "formated" in arguments["printop"] or "verbose" in arguments["printop"]:
|
||||
if "formated" in arguments[
|
||||
"printop"] or "verbose" in arguments["printop"]:
|
||||
if medialibrary.videos[filepath].error:
|
||||
print(f"{cred}{medialibrary.videos[filepath].fprint()}{creset}")
|
||||
print(
|
||||
f"{cred}{medialibrary.videos[filepath].fprint()}{creset}"
|
||||
)
|
||||
else:
|
||||
print(medialibrary.videos[filepath].fprint())
|
||||
else:
|
||||
@ -107,13 +127,16 @@ def main():
|
||||
|
||||
# if marked for deletion delete and unwatch the video
|
||||
if "-del" in sys.argv:
|
||||
medialibrary.unwatch(filepath, delete = True)
|
||||
medialibrary.unwatch(filepath, delete=True)
|
||||
|
||||
elif sys.argv[1] == "convert":
|
||||
counter = 0
|
||||
|
||||
# Pulling list of marked videos / original keys for the medialibrary.videos dictionary
|
||||
keylist = [filepath for filepath in medialibrary.videos if medialibrary.videos[filepath].operate]
|
||||
keylist = [
|
||||
filepath for filepath in medialibrary.videos
|
||||
if medialibrary.videos[filepath].operate
|
||||
]
|
||||
keylist.sort()
|
||||
|
||||
for filepath in keylist:
|
||||
@ -125,9 +148,12 @@ def main():
|
||||
vcodec = "x265"
|
||||
|
||||
# Verbosing
|
||||
print(f"{cgreen}****** Starting conversion {counter} of {len(keylist)}: '{ccyan}{medialibrary.videos[filepath].filename_origin}{cgreen}' from {ccyan}{medialibrary.videos[filepath].codec}{cgreen} to {ccyan}{vcodec}{cgreen}...{creset}")
|
||||
print(
|
||||
f"{cgreen}****** Starting conversion {counter} of {len(keylist)}: '{ccyan}{medialibrary.videos[filepath].filename_origin}{cgreen}' from {ccyan}{medialibrary.videos[filepath].codec}{cgreen} to {ccyan}{vcodec}{cgreen}...{creset}"
|
||||
)
|
||||
print(f"{ccyan}Original file:{creset}")
|
||||
if "formated" in arguments["printop"] or "verbose" in arguments["printop"]:
|
||||
if "formated" in arguments["printop"] or "verbose" in arguments[
|
||||
"printop"]:
|
||||
print(medialibrary.videos[filepath].fprint())
|
||||
else:
|
||||
print(medialibrary.videos[filepath])
|
||||
@ -135,21 +161,30 @@ def main():
|
||||
print(f"{cgreen}Converting please wait...{creset}", end="\r")
|
||||
|
||||
# Converting
|
||||
if medialibrary.videos[filepath].convert(verbose = "verbose" in arguments["printop"]):
|
||||
if medialibrary.videos[filepath].convert(
|
||||
verbose="verbose" in arguments["printop"]):
|
||||
# Mark the job as done
|
||||
medialibrary.videos[filepath].operate = False
|
||||
|
||||
# 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 arguments["printop"])
|
||||
medialibrary.videos[newfpath] = Video(newfpath,
|
||||
verbose="verbose"
|
||||
in arguments["printop"])
|
||||
|
||||
# Verbose
|
||||
print(f"{cgreen}Successfully converted '{medialibrary.videos[filepath].filename_origin}'{ccyan}({medialibrary.videos[filepath].filesize}mb){cgreen} to '{medialibrary.videos[newfpath].filename_origin}'{ccyan}({medialibrary.videos[newfpath].filesize}mb){cgreen}, {ccyan}new file:{creset}")
|
||||
print(
|
||||
f"{cgreen}Successfully converted '{medialibrary.videos[filepath].filename_origin}'{ccyan}({medialibrary.videos[filepath].filesize}mb){cgreen} to '{medialibrary.videos[newfpath].filename_origin}'{ccyan}({medialibrary.videos[newfpath].filesize}mb){cgreen}, {ccyan}new file:{creset}"
|
||||
)
|
||||
|
||||
if "formated" in arguments["printop"] or "verbose" in arguments["printop"]:
|
||||
if "formated" in arguments[
|
||||
"printop"] or "verbose" in arguments["printop"]:
|
||||
if medialibrary.videos[newfpath].error:
|
||||
print(f"{cred}{medialibrary.videos[newfpath].fprint()}{creset}")
|
||||
print(
|
||||
f"{cred}{medialibrary.videos[newfpath].fprint()}{creset}"
|
||||
)
|
||||
else:
|
||||
print(medialibrary.videos[newfpath].fprint())
|
||||
else:
|
||||
@ -160,7 +195,8 @@ def main():
|
||||
|
||||
# if marked for deletion delete and unwatch the video
|
||||
if "-del" in sys.argv:
|
||||
medialibrary.unwatch(filepath, delete = True)
|
||||
medialibrary.unwatch(filepath, delete=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
12
setup.py
12
setup.py
@ -17,7 +17,8 @@ setuptools.setup(
|
||||
"Documentation": "https://fabquenneville.github.io/mediacurator/",
|
||||
"Source Code": "https://github.com/fabquenneville/mediacurator",
|
||||
},
|
||||
description="mediacurator is a Python command line tool to manage a media database.",
|
||||
description=
|
||||
"mediacurator is a Python command line tool to manage a media database.",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
packages=setuptools.find_packages(),
|
||||
@ -30,15 +31,14 @@ setuptools.setup(
|
||||
"Operating System :: OS Independent",
|
||||
"Environment :: Console",
|
||||
],
|
||||
entry_points = {
|
||||
entry_points={
|
||||
'console_scripts': ['mediacurator=mediacurator.mediacurator:main'],
|
||||
},
|
||||
keywords=[
|
||||
"codecs", "filters", "video", "x265", "av1", "media-database", "python-command", "hevc"
|
||||
],
|
||||
install_requires=[
|
||||
"pathlib","colorama"
|
||||
"codecs", "filters", "video", "x265", "av1", "media-database",
|
||||
"python-command", "hevc"
|
||||
],
|
||||
install_requires=["pathlib", "colorama"],
|
||||
license='GPL-3.0',
|
||||
python_requires='>=3.6',
|
||||
test_suite='nose.collector',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user