2025-03-08 23:34:19 +01:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import os
|
|
|
|
from enum import Enum, auto
|
|
|
|
|
|
|
|
import gi
|
|
|
|
|
|
|
|
gi.require_version("GObject", "2.0")
|
|
|
|
from gi.repository import GObject # NOQA: E402
|
|
|
|
|
|
|
|
|
|
|
|
class FileType(Enum):
|
|
|
|
DIRECTORY = auto()
|
|
|
|
VIDEO = auto()
|
|
|
|
|
|
|
|
|
|
|
|
class FileItem(GObject.Object):
|
2025-03-09 09:51:10 +01:00
|
|
|
file_type: FileType
|
|
|
|
full_path: str
|
|
|
|
|
2025-03-08 23:34:19 +01:00
|
|
|
__gtype_name__ = "FileItem"
|
|
|
|
|
2025-03-09 09:51:10 +01:00
|
|
|
def __init__(self, name: str, file_type: FileType, full_path: str):
|
2025-03-08 23:34:19 +01:00
|
|
|
super().__init__()
|
|
|
|
self.name = name
|
|
|
|
self.file_type = file_type
|
|
|
|
self.full_path = full_path
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def from_path(path: str) -> FileItem:
|
|
|
|
name = os.path.basename(path)
|
|
|
|
if path.endswith("/"):
|
|
|
|
return FileItem(name, FileType.DIRECTORY, path)
|
|
|
|
|
|
|
|
parts = name.split(".")
|
|
|
|
suffix = parts[-1].lower() if len(parts) >= 2 else ""
|
|
|
|
|
|
|
|
if suffix in ("mkv", "mp4", "avi"):
|
|
|
|
return FileItem(name, FileType.VIDEO, path)
|
|
|
|
|
|
|
|
raise ValueError(f"Unsupported file type: {path}")
|