Working on comments and minor bug fixes in the MediaLibrary object
This commit is contained in:
parent
4e335a3650
commit
ab70af3e21
4
TODO.md
4
TODO.md
@ -17,8 +17,4 @@ Project
|
|||||||
Modules
|
Modules
|
||||||
-------
|
-------
|
||||||
|
|
||||||
* Add notes to every method/function/class
|
|
||||||
* revisit all models for Instance, Class, and Staticness
|
* revisit all models for Instance, Class, and Staticness
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
@ -30,6 +30,7 @@ The source code can be found on `GitHub <https://github.com/fabquenneville/Media
|
|||||||
:maxdepth: 1
|
:maxdepth: 1
|
||||||
:caption: Release Notes:
|
:caption: Release Notes:
|
||||||
|
|
||||||
|
releasenotes/0.0.6-changelog
|
||||||
releasenotes/0.0.5-changelog
|
releasenotes/0.0.5-changelog
|
||||||
releasenotes/0.0.4-changelog
|
releasenotes/0.0.4-changelog
|
||||||
releasenotes/0.0.1-changelog
|
releasenotes/0.0.1-changelog
|
||||||
|
|||||||
@ -1,10 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
'''
|
''' This is the library object who holds the information about the workspace and all the videos in it.'''
|
||||||
This is the container for all the videos found in the folders passed by the user
|
|
||||||
'''
|
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import sys
|
|
||||||
|
|
||||||
from .video import Video
|
from .video import Video
|
||||||
from .tools import deletefile
|
from .tools import deletefile
|
||||||
@ -13,23 +10,24 @@ import colorama
|
|||||||
colorama.init()
|
colorama.init()
|
||||||
|
|
||||||
class MediaLibrary():
|
class MediaLibrary():
|
||||||
'''
|
''' This is the library object who holds the information about the workspace and all the videos in it. '''
|
||||||
Contains the information and methods of a video file.
|
|
||||||
'''
|
|
||||||
|
|
||||||
'''
|
|
||||||
# User options
|
|
||||||
directories = list()
|
|
||||||
inputs = list()
|
|
||||||
filters = list()
|
|
||||||
# The videos variable holds a dictionary of all videos in Video objects
|
|
||||||
videos = dict()
|
|
||||||
'''
|
|
||||||
|
|
||||||
def __init__(self, files = False, directories = False, inputs = ["any"], filters = [], verbose = False):
|
def __init__(self, files = False, directories = False, inputs = ["any"], filters = [], verbose = False):
|
||||||
'''
|
'''
|
||||||
This is the library object who holds the information about the workspace and all the videos in it.
|
This is the library object who holds the information about the workspace and all the videos in it.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
files = False : A list of video files
|
||||||
|
directories = False : A list of directories containing videos directly or in the subdirectories
|
||||||
|
inputs = ["any"] : A list of filters on input FILES, defaults to keep any files
|
||||||
|
filters = [] : A list of filters to apply to the VIDEO
|
||||||
|
verbose = False : A list of print options
|
||||||
|
Returns:
|
||||||
'''
|
'''
|
||||||
|
self.directories = None
|
||||||
|
self.inputs = None
|
||||||
|
self.filters = None
|
||||||
|
self.videos = None
|
||||||
|
|
||||||
if not hasattr(self, "videos"):
|
if not hasattr(self, "videos"):
|
||||||
self.videos = dict()
|
self.videos = dict()
|
||||||
@ -43,13 +41,19 @@ class MediaLibrary():
|
|||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.inputs = inputs
|
self.inputs = inputs
|
||||||
self.filters = filters
|
self.filters = filters
|
||||||
self.load_videos(verbose = verbose)
|
self.load_videos(verbose = verbose)
|
||||||
self.filter_videos(verbose = verbose)
|
self.filter_videos(verbose = verbose)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
''' print '''
|
''' Returns a sting representations about the current instance of the MediaLibrary object
|
||||||
|
|
||||||
|
Args:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
String : Information about what the MediaLibrary is tracking
|
||||||
|
'''
|
||||||
|
|
||||||
if self.directories:
|
if self.directories:
|
||||||
text = f"MediaCurator is watching the following directories: "
|
text = f"MediaCurator is watching the following directories: "
|
||||||
@ -61,6 +65,11 @@ class MediaLibrary():
|
|||||||
'''
|
'''
|
||||||
Scan folders for video files respecting the inputs requested by the user
|
Scan folders for video files respecting the inputs requested by the user
|
||||||
Save them to the videos dictionary
|
Save them to the videos dictionary
|
||||||
|
|
||||||
|
Args:
|
||||||
|
verbose = False : A list of print options
|
||||||
|
|
||||||
|
Returns:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
print(f"{colorama.Fore.GREEN}Scanning files in {', '.join(map(str, self.directories))} for videos{colorama.Fore.RESET}")
|
print(f"{colorama.Fore.GREEN}Scanning files in {', '.join(map(str, self.directories))} for videos{colorama.Fore.RESET}")
|
||||||
@ -103,7 +112,13 @@ class MediaLibrary():
|
|||||||
self.videos[video] = Video(video, verbose = verbose)
|
self.videos[video] = Video(video, verbose = verbose)
|
||||||
|
|
||||||
def filter_videos(self, verbose = False):
|
def filter_videos(self, verbose = False):
|
||||||
''' Mark useless videos in the videos dictionary (default is useful) '''
|
''' Mark useless videos in the videos dictionary (default is useful)
|
||||||
|
|
||||||
|
Args:
|
||||||
|
verbose = False : A list of print options
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
'''
|
||||||
|
|
||||||
print(f"{colorama.Fore.GREEN}Filtering {len(self.videos)} videos for the requested parameters{colorama.Fore.RESET}")
|
print(f"{colorama.Fore.GREEN}Filtering {len(self.videos)} videos for the requested parameters{colorama.Fore.RESET}")
|
||||||
|
|
||||||
@ -112,10 +127,6 @@ 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"]:
|
||||||
@ -163,7 +174,15 @@ class MediaLibrary():
|
|||||||
print(f"{colorama.Fore.GREEN}Found {len([filepath for filepath in self.videos if self.videos[filepath].useful])} videos for the requested parameters{colorama.Fore.RESET}")
|
print(f"{colorama.Fore.GREEN}Found {len([filepath for filepath in self.videos if self.videos[filepath].useful])} videos for the requested parameters{colorama.Fore.RESET}")
|
||||||
|
|
||||||
def unwatch(self, filepath, delete = False):
|
def unwatch(self, filepath, delete = False):
|
||||||
''' remove a video from the index and delete it if requested'''
|
''' remove a video from the index and delete it if requested
|
||||||
|
|
||||||
|
Args:
|
||||||
|
filepath : A string containing the full filepath
|
||||||
|
delete = False : Delete the file as well as removing it from the library
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
boolean : Operation success
|
||||||
|
'''
|
||||||
|
|
||||||
if delete:
|
if delete:
|
||||||
deletefile(filepath)
|
deletefile(filepath)
|
||||||
|
|||||||
@ -14,23 +14,27 @@ colorama.init()
|
|||||||
class Video():
|
class Video():
|
||||||
'''Contains the information and methods of a video file.'''
|
'''Contains the information and methods of a video file.'''
|
||||||
|
|
||||||
'''
|
|
||||||
path = str()
|
|
||||||
filename_origin = str()
|
|
||||||
filesize = int()
|
|
||||||
filename_new = str()
|
|
||||||
filename_tmp = str()
|
|
||||||
useful = bool()
|
|
||||||
codec= str()
|
|
||||||
error = str()
|
|
||||||
definition = str()
|
|
||||||
width = int()
|
|
||||||
height = int()
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, filepath, useful = True, verbose = False):
|
def __init__(self, filepath, useful = True, verbose = False):
|
||||||
''' creates and analyse a video file '''
|
'''Contains the information and methods of a video file.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
filepath : A string containing the full filepath
|
||||||
|
useful :
|
||||||
|
verbose :
|
||||||
|
Returns:
|
||||||
|
:
|
||||||
|
'''
|
||||||
|
self.path = None
|
||||||
|
self.filename_origin = None
|
||||||
|
self.filesize = None
|
||||||
|
self.filename_new = None
|
||||||
|
self.filename_tmp = None
|
||||||
|
self.useful = None
|
||||||
|
self.codec = None
|
||||||
|
self.error = None
|
||||||
|
self.definition = None
|
||||||
|
self.width = None
|
||||||
|
self.height = None
|
||||||
|
|
||||||
#Breaking down the full path in its components
|
#Breaking down the full path in its components
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user