1- from app .core .settings import UserSettings
1+ from app .core .settings import CatalogConfig , UserSettings
22from app .services .row_generator import RowGeneratorService
33from app .services .scoring import ScoringService
44from app .services .stremio_service import StremioService
@@ -26,7 +26,7 @@ def normalize_type(type_):
2626 def build_catalog_entry (self , item , label , config_id ):
2727 item_id = item .get ("_id" , "" )
2828 # Use watchly.{config_id}.{item_id} format for better organization
29- if config_id == "watchly.item" :
29+ if config_id in [ "watchly.item" , "watchly.loved" , "watchly.watched" ] :
3030 # New Item-based catalog format
3131 catalog_id = f"{ config_id } .{ item_id } "
3232 elif item_id .startswith ("tt" ) and config_id in ["watchly.loved" , "watchly.watched" ]:
@@ -103,35 +103,38 @@ async def get_dynamic_catalogs(
103103 """
104104 Generate all dynamic catalog rows.
105105 """
106- lang = user_settings .language if user_settings else "en-US"
107-
108- include_item_based_rows = bool (
109- next ((c for c in user_settings .catalogs if c .id == "watchly.item" and c .enabled ), True )
110- )
111- include_theme_based_rows = bool (
112- next ((c for c in user_settings .catalogs if c .id == "watchly.theme" and c .enabled ), True )
113- )
114106 catalogs = []
107+ lang = user_settings .language if user_settings else "en-US"
115108
116- if include_theme_based_rows :
109+ # Theme Based
110+ theme_config = next ((c for c in user_settings .catalogs if c .id == "watchly.theme" ), None )
111+ if not theme_config or theme_config .enabled :
117112 catalogs .extend (await self .get_theme_based_catalogs (library_items , user_settings ))
118113
119- # 3. Add Item-Based Rows
120- if include_item_based_rows :
121- # For Movies
122- await self ._add_item_based_rows (catalogs , library_items , "movie" , lang )
123- # For Series
124- await self ._add_item_based_rows (catalogs , library_items , "series" , lang )
114+ # Item Based (Loved/Watched)
115+ loved_config = next ((c for c in user_settings .catalogs if c .id == "watchly.loved" ), None )
116+ watched_config = next ((c for c in user_settings .catalogs if c .id == "watchly.watched" ), None )
117+
118+ # Fallback for old settings (watchly.item)
119+ if not loved_config and not watched_config :
120+ old_config = next ((c for c in user_settings .catalogs if c .id == "watchly.item" ), None )
121+ if old_config and old_config .enabled :
122+ # Create temporary configs
123+ loved_config = CatalogConfig (id = "watchly.loved" , name = None , enabled = True )
124+ watched_config = CatalogConfig (id = "watchly.watched" , name = None , enabled = True )
125+
126+ # Movies
127+ await self ._add_item_based_rows (catalogs , library_items , "movie" , lang , loved_config , watched_config )
128+ # Series
129+ await self ._add_item_based_rows (catalogs , library_items , "series" , lang , loved_config , watched_config )
125130
126131 return catalogs
127132
128- async def _add_item_based_rows (self , catalogs : list , library_items : dict , content_type : str , language : str ):
133+ async def _add_item_based_rows (
134+ self , catalogs : list , library_items : dict , content_type : str , language : str , loved_config , watched_config
135+ ):
129136 """Helper to add 'Because you watched' and 'More like' rows."""
130137
131- # Translate labels
132- label_more_like = await translation_service .translate ("More like" , language )
133- label_bc_watched = await translation_service .translate ("Because you watched" , language )
134-
135138 # Helper to parse date
136139 def get_date (item ):
137140 import datetime
@@ -154,24 +157,35 @@ def get_date(item):
154157 return datetime .datetime .min .replace (tzinfo = datetime .UTC )
155158
156159 # 1. More Like <Loved Item>
157- loved = [i for i in library_items .get ("loved" , []) if i .get ("type" ) == content_type ]
158- loved .sort (key = get_date , reverse = True )
160+ last_loved = None # Initialize for the watched check
161+ if loved_config and loved_config .enabled :
162+ loved = [i for i in library_items .get ("loved" , []) if i .get ("type" ) == content_type ]
163+ loved .sort (key = get_date , reverse = True )
164+
165+ last_loved = loved [0 ] if loved else None
166+ if last_loved :
167+ label = loved_config .name
168+ if not label or label == "More like what you loved" : # Default
169+ label = await translation_service .translate ("More like what you loved" , language )
159170
160- last_loved = loved [0 ] if loved else None
161- if last_loved :
162- catalogs .append (self .build_catalog_entry (last_loved , label_more_like , "watchly.item" ))
171+ catalogs .append (self .build_catalog_entry (last_loved , label , "watchly.loved" ))
163172
164173 # 2. Because you watched <Watched Item>
165- watched = [i for i in library_items .get ("watched" , []) if i .get ("type" ) == content_type ]
166- watched .sort (key = get_date , reverse = True )
167-
168- last_watched = None
169- for item in watched :
170- # Avoid duplicate row if it's the same item as 'More like'
171- if last_loved and item .get ("_id" ) == last_loved .get ("_id" ):
172- continue
173- last_watched = item
174- break
175-
176- if last_watched :
177- catalogs .append (self .build_catalog_entry (last_watched , label_bc_watched , "watchly.item" ))
174+ if watched_config and watched_config .enabled :
175+ watched = [i for i in library_items .get ("watched" , []) if i .get ("type" ) == content_type ]
176+ watched .sort (key = get_date , reverse = True )
177+
178+ last_watched = None
179+ for item in watched :
180+ # Avoid duplicate row if it's the same item as 'More like'
181+ if last_loved and item .get ("_id" ) == last_loved .get ("_id" ):
182+ continue
183+ last_watched = item
184+ break
185+
186+ if last_watched :
187+ label = watched_config .name
188+ if not label or label == "Because you watched" :
189+ label = await translation_service .translate ("Because you watched" , language )
190+
191+ catalogs .append (self .build_catalog_entry (last_watched , label , "watchly.watched" ))
0 commit comments