Small refactor
This commit is contained in:
parent
cc123b8910
commit
546f08174a
2 changed files with 23 additions and 14 deletions
|
@ -1,9 +1,18 @@
|
||||||
from .structures import PathClassification, FileClassification
|
from .structures import PathInfo, FileInfo
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def classify_files(path: str) -> PathClassification:
|
def classify_files(path: str) -> PathInfo:
|
||||||
return PathClassification(Path(path))
|
path_info = PathInfo(Path(path))
|
||||||
|
|
||||||
|
# Go over all files
|
||||||
|
for root, dirs, files in os.walk(path_info.path):
|
||||||
|
for filename in files:
|
||||||
|
filepath = os.path.join(root, filename)
|
||||||
|
print(filepath)
|
||||||
|
|
||||||
|
return path_info
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -4,7 +4,7 @@ from pathlib import Path
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
|
|
||||||
class FileCategory(Enum):
|
class FileInfo(Enum):
|
||||||
UNCLASSIFIED = "unclassified"
|
UNCLASSIFIED = "unclassified"
|
||||||
"""File has not been classified yet."""
|
"""File has not been classified yet."""
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class FileCategory(Enum):
|
||||||
"""Poster, background, thumb and other meta image formats often used in Jellyfin and Plex."""
|
"""Poster, background, thumb and other meta image formats often used in Jellyfin and Plex."""
|
||||||
|
|
||||||
|
|
||||||
class PathCategory(Enum):
|
class PathInfo(Enum):
|
||||||
UNCLASSIFIED = "unclassified"
|
UNCLASSIFIED = "unclassified"
|
||||||
"""Not yet classified."""
|
"""Not yet classified."""
|
||||||
|
|
||||||
|
@ -45,14 +45,14 @@ class PathCategory(Enum):
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class FileClassification:
|
class FileInfo:
|
||||||
original_path: Path
|
original_path: Path
|
||||||
"""Original Path to file, before any processing."""
|
"""Original Path to file, before any processing."""
|
||||||
|
|
||||||
parent_path: "PathClassification"
|
parent_path: "PathInfo"
|
||||||
"""Parent path classification that the file is a part of."""
|
"""Parent path classification that the file is a part of."""
|
||||||
|
|
||||||
category: FileCategory = FileCategory.UNCLASSIFIED
|
category: FileInfo = FileInfo.UNCLASSIFIED
|
||||||
"""Category of file content."""
|
"""Category of file content."""
|
||||||
|
|
||||||
new_file_name: str | None = None
|
new_file_name: str | None = None
|
||||||
|
@ -76,18 +76,18 @@ class FileClassification:
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class PathClassification:
|
class PathInfo:
|
||||||
path: Path
|
path: Path
|
||||||
"""Parent directory of analysed content."""
|
"""Parent directory of analysed content."""
|
||||||
|
|
||||||
category: PathCategory = PathCategory.UNCLASSIFIED
|
category: PathInfo = PathInfo.UNCLASSIFIED
|
||||||
"""Category of path media."""
|
"""Category of path media."""
|
||||||
|
|
||||||
files: list[FileClassification] = []
|
is_bluray_quality: bool = False
|
||||||
|
|
||||||
|
files: list[FileInfo] = []
|
||||||
"""List of all files in the path."""
|
"""List of all files in the path."""
|
||||||
|
|
||||||
def get_files_by_category(
|
def get_files_by_category(self, category: FileInfo) -> filter[FileInfo]:
|
||||||
self, category: FileCategory
|
|
||||||
) -> filter[FileClassification]:
|
|
||||||
"""Get all files of a specific category."""
|
"""Get all files of a specific category."""
|
||||||
return filter(lambda f: f.category == category, self.files)
|
return filter(lambda f: f.category == category, self.files)
|
||||||
|
|
Loading…
Reference in a new issue