Files
alfred/alfred/infrastructure/persistence/memory/ltm/components/library.py
T
francwa 249c5de76a feat: major architectural refactor
- Refactor memory system (episodic/STM/LTM with components)
- Implement complete subtitle domain (scanner, matcher, placer)
- Add YAML workflow infrastructure
- Externalize knowledge base (patterns, release groups)
- Add comprehensive testing suite
- Create manual testing CLIs
2026-05-11 21:55:06 +02:00

65 lines
2.2 KiB
Python

"""Library — owned movies and TV shows."""
import logging
from dataclasses import dataclass, field
from datetime import datetime
logger = logging.getLogger(__name__)
@dataclass
class Library:
movies: list[dict] = field(default_factory=list)
tv_shows: list[dict] = field(default_factory=list)
def add(self, media_type: str, media: dict) -> None:
"""Add a media item, skipping duplicates by imdb_id."""
collection = self._collection(media_type)
if collection is None:
return
existing_ids = [m.get("imdb_id") for m in collection]
if media.get("imdb_id") not in existing_ids:
media["added_at"] = datetime.now().isoformat()
collection.append(media)
logger.info(f"Library: Added {media.get('title')} to {media_type}")
def get(self, media_type: str) -> list[dict]:
"""Get all items for a media type."""
return self._collection(media_type) or []
@classmethod
def describe(cls) -> dict:
return {
"name": "Library",
"tier": "ltm",
"access": "read-write",
"description": (
"Catalogue of media owned by the user. "
"Read to check if a title is already in the library before downloading. "
"Write (add) after successfully moving a media file to its destination."
),
"fields": {
"movies": "List of owned movies. Each entry has imdb_id, title, year, quality, file_path, added_at.",
"tv_shows": "List of owned TV shows. Each entry has imdb_id, title, seasons, added_at.",
},
}
def _collection(self, media_type: str) -> list[dict] | None:
if media_type == "movies":
return self.movies
if media_type == "tv_shows":
return self.tv_shows
logger.warning(f"Library: Unknown media type '{media_type}'")
return None
def to_dict(self) -> dict:
return {"movies": self.movies, "tv_shows": self.tv_shows}
@classmethod
def from_dict(cls, data: dict) -> "Library":
return cls(
movies=data.get("movies", []),
tv_shows=data.get("tv_shows", []),
)