QFlow/qflow/models.py
2025-11-11 15:20:18 +08:00

44 lines
890 B
Python

from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
from typing import Optional
@dataclass(slots=True)
class FileState:
"""Represents a single file inside a torrent."""
torrent_hash: str
torrent_name: str
file_index: int
name: str
size: int
downloaded: int
progress: float
priority: int
remaining: int
save_path: Path
def full_path(self) -> Path:
return (self.save_path / self.name).resolve()
@property
def is_complete(self) -> bool:
return self.remaining <= 0 or self.progress >= 0.9999
@property
def is_downloading(self) -> bool:
return not self.is_complete and self.priority > 0
@dataclass(slots=True)
class UploadTask:
id: int
torrent_hash: str
file_index: int
path: Path
size: int
tries: int
last_error: Optional[str]