Small refactor

This commit is contained in:
Maximilian Giller 2025-09-11 01:36:24 +02:00
parent cc123b8910
commit 546f08174a
2 changed files with 23 additions and 14 deletions

View file

@ -1,9 +1,18 @@
from .structures import PathClassification, FileClassification
from .structures import PathInfo, FileInfo
from pathlib import Path
import os
def classify_files(path: str) -> PathClassification:
return PathClassification(Path(path))
def classify_files(path: str) -> PathInfo:
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__":

View file

@ -4,7 +4,7 @@ from pathlib import Path
from os import path
class FileCategory(Enum):
class FileInfo(Enum):
UNCLASSIFIED = "unclassified"
"""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."""
class PathCategory(Enum):
class PathInfo(Enum):
UNCLASSIFIED = "unclassified"
"""Not yet classified."""
@ -45,14 +45,14 @@ class PathCategory(Enum):
@dataclass
class FileClassification:
class FileInfo:
original_path: Path
"""Original Path to file, before any processing."""
parent_path: "PathClassification"
parent_path: "PathInfo"
"""Parent path classification that the file is a part of."""
category: FileCategory = FileCategory.UNCLASSIFIED
category: FileInfo = FileInfo.UNCLASSIFIED
"""Category of file content."""
new_file_name: str | None = None
@ -76,18 +76,18 @@ class FileClassification:
@dataclass
class PathClassification:
class PathInfo:
path: Path
"""Parent directory of analysed content."""
category: PathCategory = PathCategory.UNCLASSIFIED
category: PathInfo = PathInfo.UNCLASSIFIED
"""Category of path media."""
files: list[FileClassification] = []
is_bluray_quality: bool = False
files: list[FileInfo] = []
"""List of all files in the path."""
def get_files_by_category(
self, category: FileCategory
) -> filter[FileClassification]:
def get_files_by_category(self, category: FileInfo) -> filter[FileInfo]:
"""Get all files of a specific category."""
return filter(lambda f: f.category == category, self.files)