diff --git a/model/__init__.py b/model/__init__.py index 0c26d45..3e76344 100644 --- a/model/__init__.py +++ b/model/__init__.py @@ -1,2 +1,2 @@ from .recent_project import RecentProject -from .project import Project \ No newline at end of file +from .project import Project, ProjectItem, ItemType \ No newline at end of file diff --git a/model/composition.py b/model/composition.py index 2211249..213f5fb 100644 --- a/model/composition.py +++ b/model/composition.py @@ -1,2 +1,2 @@ class CompositionClip(object): - \ No newline at end of file + pass \ No newline at end of file diff --git a/model/project.py b/model/project.py index bf65c76..3e693ca 100644 --- a/model/project.py +++ b/model/project.py @@ -1,7 +1,74 @@ +import os +from enum import Enum +from typing import List + +class ItemType(Enum): + MISSING = 0 + DIRECTORY = 1 + IMAGE = 2 + AUDIO = 3 + VIDEO = 4 + SUBTITLES = 5 + PROJECT = 6 + COMPOSITION = 7 + SEQUENCE = 8 + UNKNOWN = 1000 + +class ProjectItem(object): + def __init__(self, name : str, project : "Project", storage : "ProjectStorage", parent : "ProjectItem" = None): + self.__storage = storage + self.name = name + self.project = project + self.parent = parent + self.__type : ItemType = None + self.__children : list = None + + """ + Gets the path relative to the project directory. + + Returns: + path relative to the project root folder. + """ + def path(self) -> str: + if self.parent: + return os.path.join(self.parent.path(), self.name) + return self.name + + """ + Gets the absolute path to this project item. + """ + def absolutePath(self) -> str: + return os.path.join(self.project.rootDir, self.path()) + + """ + Gets the type of this project item. + """ + def itemType(self) -> str: + if self.__type is None: + self.__type = self.__storage.itemType(self) + return self.__type + + """ + Gets the children project items. + """ + def children(self) -> List["ProjectItem"]: + if self.__children is None: + self.__children = list(self.__storage.itemChildren(self)) + return self.__children + + class Project(object): - def __init__(self, path): - self.root_dir = path - - def get_items(self): - pass \ No newline at end of file + def __init__(self, path : str, storage : "ProjectStorage"): + self.__storage = storage + self.projectFile : str = path + self.rootDir : str = None + self.videoBitsPerChannel : int = 8 + self.videoColorSpace : str = None + self.audioSampleRate : int = 48000 + self.__items : List[ProjectItem] = None + + def items(self) -> List[ProjectItem]: + if self.__items is None: + self.__items = list(self.__storage.projectItems(self)) + return self.__items \ No newline at end of file diff --git a/model/project_item.py b/model/project_item.py deleted file mode 100644 index 8063be7..0000000 --- a/model/project_item.py +++ /dev/null @@ -1,6 +0,0 @@ -class ProjectItem(object): - - def __init__(self, filename): - self.filename = filename - - \ No newline at end of file diff --git a/properties/config.py b/properties/config.py index b50b79e..2c5fe20 100644 --- a/properties/config.py +++ b/properties/config.py @@ -4,5 +4,11 @@ APP_AUTHOR = "Tiberiu Chibici" APP_AUTHOR_SHORT = "TibiCh" PROJECT_EXTENSION = "emproj" +SEQUENCE_EXTENSION = "emseq" +COMPOSITION_EXTENSION = "emcomp" -DEBUG = 1 \ No newline at end of file +DEBUG = 1 +DEBUG_SUPPORTED_IMAGE = [ "png", "jpg", "tiff", "jpeg" ] +DEBUG_SUPPORTED_VIDEO = [ "mp4", "avi", "wmv", "mkv" ] +DEBUG_SUPPORTED_AUDIO = [ "mp3", "wav", "ogg", "aiff", "flac" ] +DEBUG_SUPPORTED_SUB = [ "srt" ] \ No newline at end of file diff --git a/storage/project_storage.py b/storage/project_storage.py new file mode 100644 index 0000000..5b3dffb --- /dev/null +++ b/storage/project_storage.py @@ -0,0 +1,59 @@ +import os +import json +from typing import Iterable +from model import Project, ProjectItem, ItemType +from properties import config + +def loadProject(self, projFilePath) -> Project: + p = Project(projFilePath, self) + p.rootDir = os.path.dirname(projFilePath) + + +def saveProject(self, project : Project): + pass + +""" +Determines the type of the project item. +""" +def getItemType(self, projectItem : ProjectItem) -> ItemType: + path = projectItem.absolutePath() + + if os.path.isdir(path): + return ItemType.DIRECTORY + + elif os.path.isfile(path): + _, ext = os.path.splitext(path) + ext = ext.lower().lstrip('.') # remove leading . + + if ext == config.PROJECT_EXTENSION: + return ItemType.PROJECT + + elif ext == config.SEQUENCE_EXTENSION: + return ItemType.SEQUENCE + + elif ext == config.COMPOSITION_EXTENSION: + return ItemType.COMPOSITION + + elif ext in config.DEBUG_SUPPORTED_AUDIO: + return ItemType.AUDIO + + elif ext in config.DEBUG_SUPPORTED_VIDEO: + return ItemType.VIDEO + + elif ext in config.DEBUG_SUPPORTED_IMAGE: + return ItemType.IMAGE + + elif ext in config.DEBUG_SUPPORTED_SUB: + return ItemType.SUBTITLES + + return ItemType.UNKNOWN + + +def getItemChildren(self, projectItem : ProjectItem) -> Iterable[ProjectItem]: + if projectItem.itemType() == ItemType.DIRECTORY: + for item in os.listdir(projectItem.absolutePath()): + yield ProjectItem(item, projectItem.project, self, projectItem) + +def getProjectItems(self, project : Project) -> Iterable[ProjectItem]: + for item in os.listdir(project.rootDir): + yield ProjectItem(item, project, self, None)