Files
snoopy 6f551ba439 Initial release — MediaTracker v1.0
Dockerized media library scanner for NAS drives.
Identifies movies and series from filenames, fetches posters
via the public IMDB suggestion API (no key required), and
exposes a dark-themed web UI with multilingual search support.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 11:40:44 +00:00

57 lines
1.6 KiB
Python

import os
from fastapi import APIRouter
from database import Episode, Movie, NasSource, ScanHistory, Season, Series, UnmatchedFile, get_session
router = APIRouter(prefix="/api", tags=["stats"])
@router.get("/stats")
def get_stats():
session = get_session()
try:
movies_count = session.query(Movie).count()
series_count = session.query(Series).count()
episodes_count = session.query(Episode).count()
nas_count = session.query(NasSource).count()
unmatched_count = session.query(UnmatchedFile).count()
last_scan = (
session.query(ScanHistory)
.filter_by(status="completed")
.order_by(ScanHistory.finished_at.desc())
.first()
)
return {
"movies": movies_count,
"series": series_count,
"episodes": episodes_count,
"nas_count": nas_count,
"unmatched_files": unmatched_count,
"last_scan": last_scan.finished_at.isoformat() if last_scan and last_scan.finished_at else None,
}
finally:
session.close()
@router.get("/nas")
def get_nas_list():
session = get_session()
try:
sources = session.query(NasSource).all()
result = []
for nas in sources:
accessible = os.path.isdir(nas.path)
result.append({
"id": nas.id,
"name": nas.name,
"path": nas.path,
"accessible": accessible,
"last_scan": nas.last_scan.isoformat() if nas.last_scan else None,
})
return result
finally:
session.close()