@@ -14,7 +14,11 @@ def __init__(self):
1414 self .tmdb_service = TMDBService ()
1515
1616 async def discover_recommendations (
17- self , profile : UserTasteProfile , content_type : str , limit : int = 20
17+ self ,
18+ profile : UserTasteProfile ,
19+ content_type : str ,
20+ limit : int = 20 ,
21+ excluded_genres : list [int ] | None = None ,
1822 ) -> list [dict ]:
1923 """
2024 Find content that matches the user's taste profile.
@@ -33,52 +37,78 @@ async def discover_recommendations(
3337 top_crew = profile .get_top_crew (limit = 1 ) # e.g. [(555, 1.0)] - Director
3438
3539 top_countries = profile .get_top_countries (limit = 2 )
40+ top_year = profile .get_top_year (limit = 1 )
3641
3742 if not top_genres and not top_keywords and not top_cast :
3843 # Fallback if profile is empty
3944 return []
4045
4146 tasks = []
47+ base_params = {}
48+ if excluded_genres :
49+ base_params ["without_genres" ] = "|" .join ([str (g ) for g in excluded_genres ])
4250
4351 # Query 1: Top Genres Mix
4452 if top_genres :
4553 genre_ids = "|" .join ([str (g [0 ]) for g in top_genres ])
46- params_popular = {"with_genres" : genre_ids , "sort_by" : "popularity.desc" , "vote_count.gte" : 100 }
54+ params_popular = {
55+ "with_genres" : genre_ids ,
56+ "sort_by" : "popularity.desc" ,
57+ "vote_count.gte" : 500 ,
58+ ** base_params ,
59+ }
4760 tasks .append (self ._fetch_discovery (content_type , params_popular ))
4861
4962 # fetch atleast two pages of results
5063 for i in range (2 ):
5164 params_rating = {
5265 "with_genres" : genre_ids ,
5366 "sort_by" : "ratings.desc" ,
54- "vote_count.gte" : 300 ,
67+ "vote_count.gte" : 500 ,
5568 "page" : i + 1 ,
69+ ** base_params ,
5670 }
5771 tasks .append (self ._fetch_discovery (content_type , params_rating ))
5872
5973 # Query 2: Top Keywords
6074 if top_keywords :
6175 keyword_ids = "|" .join ([str (k [0 ]) for k in top_keywords ])
62- params_keywords = {"with_keywords" : keyword_ids , "sort_by" : "popularity.desc" }
76+ params_keywords = {
77+ "with_keywords" : keyword_ids ,
78+ "sort_by" : "popularity.desc" ,
79+ "vote_count.gte" : 500 ,
80+ ** base_params ,
81+ }
6382 tasks .append (self ._fetch_discovery (content_type , params_keywords ))
6483
6584 # fetch atleast two pages of results
6685 for i in range (3 ):
6786 params_rating = {
6887 "with_keywords" : keyword_ids ,
6988 "sort_by" : "ratings.desc" ,
70- "vote_count.gte" : 300 ,
89+ "vote_count.gte" : 500 ,
7190 "page" : i + 1 ,
91+ ** base_params ,
7292 }
7393 tasks .append (self ._fetch_discovery (content_type , params_rating ))
7494
7595 # Query 3: Top Actors
7696 for actor in top_cast :
7797 actor_id = actor [0 ]
78- params_actor = {"with_cast" : str (actor_id ), "sort_by" : "popularity.desc" }
98+ params_actor = {
99+ "with_cast" : str (actor_id ),
100+ "sort_by" : "popularity.desc" ,
101+ "vote_count.gte" : 500 ,
102+ ** base_params ,
103+ }
79104 tasks .append (self ._fetch_discovery (content_type , params_actor ))
80105
81- params_rating = {"with_cast" : str (actor_id ), "sort_by" : "ratings.desc" , "vote_count.gte" : 300 }
106+ params_rating = {
107+ "with_cast" : str (actor_id ),
108+ "sort_by" : "ratings.desc" ,
109+ "vote_count.gte" : 500 ,
110+ ** base_params ,
111+ }
82112 tasks .append (self ._fetch_discovery (content_type , params_rating ))
83113
84114 # Query 4: Top Director
@@ -87,19 +117,47 @@ async def discover_recommendations(
87117 params_director = {
88118 "with_crew" : str (director_id ),
89119 "sort_by" : "vote_average.desc" , # Directors imply quality preference
120+ "vote_count.gte" : 500 ,
121+ ** base_params ,
90122 }
91123 tasks .append (self ._fetch_discovery (content_type , params_director ))
92124
93- params_rating = {"with_crew" : str (director_id ), "sort_by" : "ratings.desc" , "vote_count.gte" : 300 }
125+ params_rating = {
126+ "with_crew" : str (director_id ),
127+ "sort_by" : "ratings.desc" ,
128+ "vote_count.gte" : 500 ,
129+ ** base_params ,
130+ }
94131 tasks .append (self ._fetch_discovery (content_type , params_rating ))
95132
96133 # Query 5: Top Countries
97134 if top_countries :
98135 country_ids = "|" .join ([str (c [0 ]) for c in top_countries ])
99- params_country = {"with_origin_country" : country_ids , "sort_by" : "popularity.desc" , "vote_count.gte" : 100 }
136+ params_country = {
137+ "with_origin_country" : country_ids ,
138+ "sort_by" : "popularity.desc" ,
139+ "vote_count.gte" : 100 ,
140+ ** base_params ,
141+ }
100142 tasks .append (self ._fetch_discovery (content_type , params_country ))
101143
102- params_rating = {"with_origin_country" : country_ids , "sort_by" : "ratings.desc" , "vote_count.gte" : 300 }
144+ params_rating = {
145+ "with_origin_country" : country_ids ,
146+ "sort_by" : "ratings.desc" ,
147+ "vote_count.gte" : 300 ,
148+ ** base_params ,
149+ }
150+ tasks .append (self ._fetch_discovery (content_type , params_rating ))
151+
152+ # query 6: Top year
153+ if top_year :
154+ year = top_year [0 ][0 ]
155+ params_rating = {
156+ "year" : year ,
157+ "sort_by" : "ratings.desc" ,
158+ "vote_count.gte" : 500 ,
159+ ** base_params ,
160+ }
103161 tasks .append (self ._fetch_discovery (content_type , params_rating ))
104162
105163 # 3. Execute Parallel Queries
0 commit comments