Use user-scoped Items queries for Jellyfin movie discovery

This commit is contained in:
Kenny Bondelie committed 2026-09-16 14:44:53 -07:00
1 parent 8507a77215
commit 641cb68da2
3 files changed
+130 -26

No files matched your search

+34 -23
View File
@@ -1,4 +1,5 @@
import httpx
from app.config import settings
@@ -74,8 +75,9 @@ async def get_all_movies(user_id: str) -> list[dict]:
while True:
try:
res = await client.get(
f"/Users/{user_id}/Items",
"/Items",
params={
"UserId": user_id,
"IncludeItemTypes": "Movie",
"Recursive": "true",
"Fields": fields,
@@ -95,31 +97,39 @@ async def get_all_movies(user_id: str) -> list[dict]:
for item in items:
runtime_ticks = item.get("RunTimeTicks")
runtime_minutes = int(runtime_ticks / 600_000_000) if runtime_ticks else None
runtime_minutes = (
int(runtime_ticks / 600_000_000) if runtime_ticks else None
)
people = []
for person in (item.get("People") or [])[:5]:
people.append({
"name": person.get("Name", ""),
"role": person.get("Role", person.get("Type", "")),
})
people.append(
{
"name": person.get("Name", ""),
"role": person.get("Role", person.get("Type", "")),
}
)
movies.append({
"jellyfin_id": item["Id"],
"title": item.get("Name", "Unknown"),
"sort_title": item.get("SortName"),
"year": item.get("ProductionYear"),
"genres": item.get("Genres", []),
"overview": item.get("Overview"),
"community_rating": item.get("CommunityRating"),
"critic_rating": item.get("CriticRating"),
"runtime_minutes": runtime_minutes,
"content_rating": item.get("OfficialRating"),
"studios": [s.get("Name", "") for s in (item.get("Studios") or [])],
"people": people,
"tags": item.get("Tags", []),
"is_played": item.get("UserData", {}).get("Played", False),
})
movies.append(
{
"jellyfin_id": item["Id"],
"title": item.get("Name", "Unknown"),
"sort_title": item.get("SortName"),
"year": item.get("ProductionYear"),
"genres": item.get("Genres", []),
"overview": item.get("Overview"),
"community_rating": item.get("CommunityRating"),
"critic_rating": item.get("CriticRating"),
"runtime_minutes": runtime_minutes,
"content_rating": item.get("OfficialRating"),
"studios": [
s.get("Name", "") for s in (item.get("Studios") or [])
],
"people": people,
"tags": item.get("Tags", []),
"is_played": item.get("UserData", {}).get("Played", False),
}
)
total = data.get("TotalRecordCount", 0)
start_index += page_size
@@ -141,8 +151,9 @@ async def get_played_movie_ids(user_id: str) -> set[str]:
while True:
try:
res = await client.get(
f"/Users/{user_id}/Items",
"/Items",
params={
"UserId": user_id,
"IncludeItemTypes": "Movie",
"Recursive": "true",
"IsPlayed": "true",