1616from app .services .recommendation .item_based import ItemBasedService
1717from app .services .recommendation .theme_based import ThemeBasedService
1818from app .services .recommendation .top_picks import TopPicksService
19+ from app .services .recommendation .utils import pad_to_min
1920from app .services .stremio .service import StremioBundle
2021from app .services .tmdb .service import get_tmdb_service
2122from app .services .token_store import token_store
@@ -98,16 +99,17 @@ async def get_catalog(
9899 )
99100
100101 # Pad if needed
101- # if len(recommendations) < min_items:
102- # recommendations = await pad_to_min(
103- # content_type,
104- # recommendations,
105- # min_items,
106- # services["tmdb"],
107- # user_settings,
108- # watched_tmdb,
109- # watched_imdb,
110- # )
102+ # TODO: This is risky because it can fetch too many unrelated items.
103+ if recommendations and len (recommendations ) < 8 :
104+ recommendations = await pad_to_min (
105+ content_type ,
106+ recommendations ,
107+ 10 , # only fetch 10 items if less than 8
108+ services ["tmdb" ],
109+ user_settings ,
110+ watched_tmdb ,
111+ watched_imdb ,
112+ )
111113
112114 logger .info (f"Returning { len (recommendations )} items for { content_type } " )
113115
@@ -304,22 +306,8 @@ async def _get_recommendations(
304306 logger .info (f"Found { len (recommendations )} top picks for { content_type } " )
305307
306308 # Based on what you loved
307- elif catalog_id == "watchly.all.loved" :
308- all_based_service : AllBasedService = services ["all_based" ]
309- recommendations = await all_based_service .get_recommendations_from_all_items (
310- library_items = library_items ,
311- content_type = content_type ,
312- watched_tmdb = watched_tmdb ,
313- watched_imdb = watched_imdb ,
314- whitelist = whitelist ,
315- limit = max_items ,
316- item_type = "loved" ,
317- profile = profile ,
318- )
319- logger .info (f"Found { len (recommendations )} recommendations based on all loved items" )
320-
321- # Based on what you liked
322- elif catalog_id == "watchly.liked.all" :
309+ elif catalog_id in ("watchly.all.loved" , "watchly.liked.all" ):
310+ item_type = "loved" if catalog_id == "watchly.all.loved" else "liked"
323311 all_based_service : AllBasedService = services ["all_based" ]
324312 recommendations = await all_based_service .get_recommendations_from_all_items (
325313 library_items = library_items ,
@@ -328,10 +316,10 @@ async def _get_recommendations(
328316 watched_imdb = watched_imdb ,
329317 whitelist = whitelist ,
330318 limit = max_items ,
331- item_type = "liked" ,
319+ item_type = item_type ,
332320 profile = profile ,
333321 )
334- logger .info (f"Found { len (recommendations )} recommendations based on all liked items" )
322+ logger .info (f"Found { len (recommendations )} recommendations based on all { item_type } items" )
335323
336324 else :
337325 logger .warning (f"Unknown catalog ID: { catalog_id } " )
0 commit comments