47baee854b
Test coverage: - test_utils.py: formatting helpers (human_size, ticks_to_minutes, format_duration, format_bitrate, ffprobe summaries, stream parsing) - test_path_utils.py: path resolution (prefix, media root mapping, edge cases with spaces/special chars) - test_domain_media.py: Jellyfin item normalization (HDR detection, media sources, stream extraction, display formatting) - test_jobs.py: job template rendering and shell quoting safety - test_media_index.py: SQLite index CRUD, querying, filtering, sorting, pagination - test_config.py: pydantic-settings env loading - test_api.py: full FastAPI integration tests with mocked SSH/Jellyfin (all endpoints: dashboard, monitoring, media, files, jobs) All tests run without network/SSH dependencies using mocks.
Backend - Media Library Viewer API
FastAPI backend serving the REST API for Jellyfin media browsing, SSH file inspection, and server monitoring.
Project structure
backend/
├── pyproject.toml
├── README.md
├── src/
│ └── media_library_viewer_api/
│ ├── __init__.py
│ ├── main.py # FastAPI app entrypoint
│ ├── config.py # pydantic-settings config
│ ├── dependencies.py # Dependency injection
│ ├── path_utils.py # Jellyfin→SSH path resolution
│ ├── jobs.py # Job templates
│ ├── utils.py # Formatting helpers
│ ├── routers/
│ │ ├── dashboard.py
│ │ ├── monitoring.py
│ │ ├── media.py
│ │ ├── files.py
│ │ └── jobs.py
│ ├── clients/
│ │ ├── jellyfin.py
│ │ ├── resources.py
│ │ └── ssh.py
│ ├── domain/
│ │ └── media.py
│ └── services/
│ └── media_index.py
└── tests/
Setup
cd backend
python -m venv .venv
source .venv/bin/activate
pip install -e '.[dev]'
Configuration
Create a .env file in the project root (or set environment variables):
JELLYFIN_URL=https://jellyfin.example.com
JELLYFIN_API_KEY=your-api-key
JELLYFIN_USER_ID=
SSH_HOST=media-server.example.com
SSH_USERNAME=username
SSH_PORT=22
SSH_KEY_FILENAME=/home/username/.ssh/id_rsa
SSH_PASSWORD=
REMOTE_MEDIA_ROOT=/srv/media
REMOTE_PATH_PREFIX=
Running
cd backend
uvicorn media_library_viewer_api.main:app --reload --port 8000
Or with PYTHONPATH if not installed:
PYTHONPATH=src uvicorn media_library_viewer_api.main:app --reload --port 8000
API docs available at: http://localhost:8000/docs
API Endpoints
GET /api/dashboard/counts— Movie/series/episode totalsGET /api/dashboard/libraries— Per-library breakdownGET /api/dashboard/now-playing— Active playback sessionsGET /api/monitoring/status— Collector statusGET /api/monitoring/metrics— Resource samples (last hour)GET /api/monitoring/disk— Disk spacePOST /api/monitoring/start|stop|restart— Collector controlsGET /api/monitoring/diagnostics— Collector debug infoGET /api/media/status— Index statusPOST /api/media/build— Rebuild indexGET /api/media/query— Query with filters/sort/paginationGET /api/files/list?path=— Directory listingGET /api/files/ffprobe?path=— ffprobe JSONGET /api/files/stat?path=— stat outputGET /api/files/resolve-path?path=— Path resolutionGET /api/jobs/templates— Available jobsPOST /api/jobs/run— Execute a job