"""Mirror a locally-reachable Plex library into Siftlode's own catalog (plex_* tables). Playback is from the local physical file, so this only mirrors METADATA + the physical-media facts (codecs/container/path) needed to browse, search, and later play. It reuses Plex's own codec info (no ffprobe needed) to classify each item's browser playability. Movies + episodes become playable LEAF rows (plex_items); shows/seasons are mirrored for the drill-down + episode ordering. The sync is a full reconcile of the enabled sections (upsert by rating_key). Pruning of items that disappeared from Plex is intentionally left for later (a follow-up can diff rating_keys per library). Cast + intro/credit markers are fetched lazily on the item-detail/player path (P2), not here. """ import logging from datetime import datetime, timezone from sqlalchemy.orm import Session from app import sysconfig from app.models import PlexItem, PlexLibrary, PlexSeason, PlexShow from app.plex.client import PlexClient, PlexError, PlexNotConfigured log = logging.getLogger("siftlode.plex") # Codecs/containers a browser can play in a native