mirror of
https://github.com/darkzoul5/YoutubePlaylistSync.git
synced 2026-09-18 20:43:54 +03:00
refactor: use path directly instead of filesystemEntry
This commit is contained in:
@@ -49,8 +49,3 @@ class SyncAction:
|
||||
from_name: Optional[str] = None
|
||||
to_name: Optional[str] = None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class FilesystemEntry:
|
||||
name: str
|
||||
path: Path
|
||||
|
||||
@@ -3,15 +3,14 @@ from __future__ import annotations
|
||||
from pathlib import Path
|
||||
from typing import List, Sequence
|
||||
|
||||
from ..models import FilesystemEntry
|
||||
|
||||
|
||||
def list_files(root: Path, extensions: Sequence[str]) -> List[FilesystemEntry]:
|
||||
def list_files(root: Path, extensions: Sequence[str]) -> List[Path]:
|
||||
"""List all files in root directory with given extensions."""
|
||||
exts = {e.lower() for e in extensions}
|
||||
results: List[FilesystemEntry] = []
|
||||
results: List[Path] = []
|
||||
if not root.exists():
|
||||
return results
|
||||
for p in root.glob("**/*"):
|
||||
if p.is_file() and p.suffix.lower() in exts:
|
||||
results.append(FilesystemEntry(name=p.name, path=p))
|
||||
results.append(p)
|
||||
return results
|
||||
|
||||
@@ -4,7 +4,7 @@ from pathlib import Path
|
||||
from typing import Iterable, List, Mapping, Sequence
|
||||
|
||||
from ..database.db import Database
|
||||
from ..models import FilesystemEntry, PlaylistItem, SyncAction, SyncActionType
|
||||
from ..models import PlaylistItem, SyncAction, SyncActionType
|
||||
from ..scanner.playlist_scanner import PlaylistScanner
|
||||
from ..sync.filesystem import list_files
|
||||
from ..utils.naming import sanitize_title
|
||||
@@ -36,7 +36,7 @@ class SyncService:
|
||||
self,
|
||||
remote: Sequence[PlaylistItem],
|
||||
db_index: Mapping[str, PlaylistItem],
|
||||
fs_entries: Iterable[FilesystemEntry],
|
||||
fs_entries: Iterable[Path],
|
||||
extension: str,
|
||||
) -> List[SyncAction]:
|
||||
"""Compare remote items, database state, and filesystem to produce actions.
|
||||
@@ -50,7 +50,7 @@ class SyncService:
|
||||
for item in remote
|
||||
}
|
||||
|
||||
fs_by_name = {e.name: e for e in fs_entries}
|
||||
fs_by_name = {p.name: p for p in fs_entries}
|
||||
|
||||
for item in remote:
|
||||
desired_name = desired_names[item.video_id]
|
||||
|
||||
Reference in New Issue
Block a user