Work
This commit is contained in:
parent
037843d14f
commit
144c3e3e25
@ -1,2 +1,2 @@
|
||||
from .recent_project import RecentProject
|
||||
from .project import Project
|
||||
from .project import Project, ProjectItem, ItemType
|
@ -1,2 +1,2 @@
|
||||
class CompositionClip(object):
|
||||
|
||||
pass
|
@ -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
|
||||
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
|
@ -1,6 +0,0 @@
|
||||
class ProjectItem(object):
|
||||
|
||||
def __init__(self, filename):
|
||||
self.filename = filename
|
||||
|
||||
|
@ -4,5 +4,11 @@ APP_AUTHOR = "Tiberiu Chibici"
|
||||
APP_AUTHOR_SHORT = "TibiCh"
|
||||
|
||||
PROJECT_EXTENSION = "emproj"
|
||||
SEQUENCE_EXTENSION = "emseq"
|
||||
COMPOSITION_EXTENSION = "emcomp"
|
||||
|
||||
DEBUG = 1
|
||||
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" ]
|
59
storage/project_storage.py
Normal file
59
storage/project_storage.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user