44 lines
983 B
Python
44 lines
983 B
Python
|
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):
|
||
|
__gtype_name__ = "FileItem"
|
||
|
|
||
|
def __init__(
|
||
|
self,
|
||
|
name: str,
|
||
|
file_type: FileType,
|
||
|
full_path: str,
|
||
|
):
|
||
|
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}")
|