This commit is contained in:
team3
2026-09-18 23:47:25 +02:00
parent db77c1f985
commit a90044b0a7
21 changed files with 1111 additions and 253 deletions

View File

@@ -36,6 +36,7 @@ def build_movie(data):
"images": tmdb.pick_backdrops(data),
"trailer_key": tmdb.pick_trailer(data),
"imdb_id": data.get("imdb_id"),
"rentable": tmdb.pick_rentable(data),
# Die echte Titel-ID trägt fill_netflix_links nach
"netflix_id": None,
"netflix_url": tmdb.pick_watch_link(data)
@@ -178,6 +179,37 @@ async def katalog_nachtragen():
return len(filme)
async def leihbarkeit_nachtragen():
"""Filme, bei denen noch nicht steht, ob man sie leihen kann — der
Altbestand von vor dieser Spalte. Der tägliche Sync hält es danach
aktuell, hier geht es nur um das erste Mal."""
with db.connect() as conn:
offen = [r["id"] for r in conn.execute("SELECT id FROM movies WHERE rentable IS NULL")]
if not offen:
return 0
bremse = asyncio.Semaphore(TMDB_CONCURRENCY)
async def hole(http, movie_id):
async with bremse:
try:
resp = await http.get(f"/movie/{movie_id}/watch/providers")
resp.raise_for_status()
return movie_id, tmdb.pick_rentable({"watch/providers": resp.json()})
except Exception:
return movie_id, None
async with tmdb.client() as http:
stand = await asyncio.gather(*(hole(http, i) for i in offen))
with db.connect() as conn:
conn.executemany(
"UPDATE movies SET rentable = ? WHERE id = ?",
[(wert, i) for i, wert in stand if wert is not None],
)
log.info("Leihbarkeit für %s Filme nachgetragen", sum(1 for _, w in stand if w is not None))
return len(offen)
async def run():
log.info("Sync startet")
canon_places = await resolve_canon()