Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +34 -18
src/streamlit_app.py
CHANGED
|
@@ -94,55 +94,71 @@ def filter_content(content_list, filters):
|
|
| 94 |
filtered = []
|
| 95 |
|
| 96 |
for content in content_list:
|
|
|
|
|
|
|
| 97 |
# For debugging
|
| 98 |
title = content.get('title', 'N/A')
|
| 99 |
|
| 100 |
-
# Type filter
|
| 101 |
-
if filters['content_type']
|
| 102 |
-
|
|
|
|
|
|
|
| 103 |
|
| 104 |
# Genre filter - check if ALL selected genres are in the content's genres
|
| 105 |
if filters['genres']:
|
| 106 |
-
content_genres =
|
| 107 |
-
selected_genres =
|
| 108 |
-
|
|
|
|
|
|
|
| 109 |
continue
|
| 110 |
|
| 111 |
# Rating filter
|
| 112 |
-
if filters['ratings']
|
| 113 |
-
|
|
|
|
|
|
|
| 114 |
|
| 115 |
# Release year filter
|
| 116 |
try:
|
| 117 |
release_year = int(content.get('release_year', 0))
|
| 118 |
if release_year < filters['year_range'][0] or release_year > filters['year_range'][1]:
|
|
|
|
| 119 |
continue
|
| 120 |
except (ValueError, TypeError):
|
|
|
|
| 121 |
continue
|
| 122 |
|
| 123 |
# Duration filter (different handling for movies and shows)
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
continue
|
| 130 |
-
except (ValueError, IndexError):
|
| 131 |
-
continue
|
| 132 |
|
| 133 |
# Director filter (optional)
|
| 134 |
if filters['director']:
|
| 135 |
director = (content.get('director', '') or '').lower()
|
| 136 |
-
if
|
|
|
|
| 137 |
continue
|
| 138 |
|
| 139 |
# Cast filter (optional)
|
| 140 |
if filters['cast']:
|
| 141 |
cast = (content.get('cast', '') or '').lower()
|
| 142 |
-
if
|
|
|
|
| 143 |
continue
|
| 144 |
|
| 145 |
-
|
|
|
|
| 146 |
|
| 147 |
return filtered
|
| 148 |
|
|
|
|
| 94 |
filtered = []
|
| 95 |
|
| 96 |
for content in content_list:
|
| 97 |
+
matches_all_filters = True
|
| 98 |
+
|
| 99 |
# For debugging
|
| 100 |
title = content.get('title', 'N/A')
|
| 101 |
|
| 102 |
+
# Type filter - only apply if not "All"
|
| 103 |
+
if filters['content_type']:
|
| 104 |
+
if content.get('type') != filters['content_type']:
|
| 105 |
+
matches_all_filters = False
|
| 106 |
+
continue
|
| 107 |
|
| 108 |
# Genre filter - check if ALL selected genres are in the content's genres
|
| 109 |
if filters['genres']:
|
| 110 |
+
content_genres = set(g.strip().lower() for g in content.get('listed_in', '').split(','))
|
| 111 |
+
selected_genres = set(g.strip().lower() for g in filters['genres'])
|
| 112 |
+
|
| 113 |
+
if not selected_genres.issubset(content_genres):
|
| 114 |
+
matches_all_filters = False
|
| 115 |
continue
|
| 116 |
|
| 117 |
# Rating filter
|
| 118 |
+
if filters['ratings']:
|
| 119 |
+
if content.get('rating') not in filters['ratings']:
|
| 120 |
+
matches_all_filters = False
|
| 121 |
+
continue
|
| 122 |
|
| 123 |
# Release year filter
|
| 124 |
try:
|
| 125 |
release_year = int(content.get('release_year', 0))
|
| 126 |
if release_year < filters['year_range'][0] or release_year > filters['year_range'][1]:
|
| 127 |
+
matches_all_filters = False
|
| 128 |
continue
|
| 129 |
except (ValueError, TypeError):
|
| 130 |
+
matches_all_filters = False
|
| 131 |
continue
|
| 132 |
|
| 133 |
# Duration filter (different handling for movies and shows)
|
| 134 |
+
if filters['content_type'] == 'Movie':
|
| 135 |
+
duration = content.get('duration', '')
|
| 136 |
+
if 'min' in duration:
|
| 137 |
+
try:
|
| 138 |
+
minutes = int(duration.split()[0])
|
| 139 |
+
if minutes < filters['duration_range'][0] or minutes > filters['duration_range'][1]:
|
| 140 |
+
matches_all_filters = False
|
| 141 |
+
continue
|
| 142 |
+
except (ValueError, IndexError):
|
| 143 |
+
matches_all_filters = False
|
| 144 |
continue
|
|
|
|
|
|
|
| 145 |
|
| 146 |
# Director filter (optional)
|
| 147 |
if filters['director']:
|
| 148 |
director = (content.get('director', '') or '').lower()
|
| 149 |
+
if not any(name.strip().lower() in director for name in filters['director'].split(',')):
|
| 150 |
+
matches_all_filters = False
|
| 151 |
continue
|
| 152 |
|
| 153 |
# Cast filter (optional)
|
| 154 |
if filters['cast']:
|
| 155 |
cast = (content.get('cast', '') or '').lower()
|
| 156 |
+
if not any(name.strip().lower() in cast for name in filters['cast'].split(',')):
|
| 157 |
+
matches_all_filters = False
|
| 158 |
continue
|
| 159 |
|
| 160 |
+
if matches_all_filters:
|
| 161 |
+
filtered.append(content)
|
| 162 |
|
| 163 |
return filtered
|
| 164 |
|