Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +19 -18
src/streamlit_app.py
CHANGED
|
@@ -65,21 +65,15 @@ def get_streaming_content():
|
|
| 65 |
offset = (page - 1) * page_size
|
| 66 |
url = f"{NOCODB_URL}?limit={page_size}&offset={offset}"
|
| 67 |
|
| 68 |
-
# Debug information
|
| 69 |
-
st.write(f"Attempting to fetch data from: {url}")
|
| 70 |
-
st.write(f"With headers: {headers}")
|
| 71 |
-
|
| 72 |
response = requests.get(url, headers=headers)
|
| 73 |
|
| 74 |
-
# Debug response
|
| 75 |
-
st.write(f"Response status code: {response.status_code}")
|
| 76 |
-
if response.status_code != 200:
|
| 77 |
-
st.write(f"Response content: {response.text}")
|
| 78 |
-
|
| 79 |
if response.status_code == 200:
|
| 80 |
data = response.json()
|
| 81 |
current_page_data = data.get('list', [])
|
| 82 |
|
|
|
|
|
|
|
|
|
|
| 83 |
if not current_page_data: # No more data to fetch
|
| 84 |
break
|
| 85 |
|
|
@@ -93,7 +87,9 @@ def get_streaming_content():
|
|
| 93 |
page += 1
|
| 94 |
else:
|
| 95 |
st.error(f"Failed to fetch data: {response.status_code}")
|
| 96 |
-
return []
|
|
|
|
|
|
|
| 97 |
|
| 98 |
return all_content
|
| 99 |
|
|
@@ -107,6 +103,9 @@ def filter_content(content_list, filters):
|
|
| 107 |
filtered = []
|
| 108 |
|
| 109 |
for content in content_list:
|
|
|
|
|
|
|
|
|
|
| 110 |
matches_all_filters = True
|
| 111 |
|
| 112 |
# Streaming service filter
|
|
@@ -123,7 +122,7 @@ def filter_content(content_list, filters):
|
|
| 123 |
|
| 124 |
# Genre filter - check if ALL selected genres are in the content's genres
|
| 125 |
if filters['genres']:
|
| 126 |
-
content_genres = set(g.strip().lower() for g in content.get('listed_in', '').split(','))
|
| 127 |
selected_genres = set(g.strip().lower() for g in filters['genres'])
|
| 128 |
|
| 129 |
if not selected_genres.issubset(content_genres):
|
|
@@ -146,9 +145,9 @@ def filter_content(content_list, filters):
|
|
| 146 |
matches_all_filters = False
|
| 147 |
continue
|
| 148 |
|
| 149 |
-
# Duration filter (different handling for movies
|
| 150 |
if filters['content_type'] == 'Movie':
|
| 151 |
-
duration = content.get('duration', '')
|
| 152 |
if 'min' in duration:
|
| 153 |
try:
|
| 154 |
minutes = int(duration.split()[0])
|
|
@@ -161,14 +160,14 @@ def filter_content(content_list, filters):
|
|
| 161 |
|
| 162 |
# Director filter (optional)
|
| 163 |
if filters['director']:
|
| 164 |
-
director = (content.get('director', '')
|
| 165 |
if not any(name.strip().lower() in director for name in filters['director'].split(',')):
|
| 166 |
matches_all_filters = False
|
| 167 |
continue
|
| 168 |
|
| 169 |
# Cast filter (optional)
|
| 170 |
if filters['cast']:
|
| 171 |
-
cast = (content.get('cast', '')
|
| 172 |
if not any(name.strip().lower() in cast for name in filters['cast'].split(',')):
|
| 173 |
matches_all_filters = False
|
| 174 |
continue
|
|
@@ -423,12 +422,14 @@ def main():
|
|
| 423 |
|
| 424 |
# Duration range slider (for movies only)
|
| 425 |
movie_durations = [
|
| 426 |
-
int(c.get('duration', '0 min').split()[0])
|
| 427 |
for c in all_content
|
| 428 |
-
if c.get('type') == 'Movie' and 'min' in c.get('duration', '')
|
| 429 |
]
|
|
|
|
| 430 |
if movie_durations:
|
| 431 |
-
min_duration
|
|
|
|
| 432 |
duration_range = st.slider(
|
| 433 |
"Movie Duration (minutes)",
|
| 434 |
min_value=min_duration,
|
|
|
|
| 65 |
offset = (page - 1) * page_size
|
| 66 |
url = f"{NOCODB_URL}?limit={page_size}&offset={offset}"
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
response = requests.get(url, headers=headers)
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
if response.status_code == 200:
|
| 71 |
data = response.json()
|
| 72 |
current_page_data = data.get('list', [])
|
| 73 |
|
| 74 |
+
# Filter out None values and ensure all items are dictionaries
|
| 75 |
+
current_page_data = [item for item in current_page_data if item and isinstance(item, dict)]
|
| 76 |
+
|
| 77 |
if not current_page_data: # No more data to fetch
|
| 78 |
break
|
| 79 |
|
|
|
|
| 87 |
page += 1
|
| 88 |
else:
|
| 89 |
st.error(f"Failed to fetch data: {response.status_code}")
|
| 90 |
+
if not all_content: # Only return [] if we haven't fetched any data
|
| 91 |
+
return []
|
| 92 |
+
break # If we have some data, return what we've got
|
| 93 |
|
| 94 |
return all_content
|
| 95 |
|
|
|
|
| 103 |
filtered = []
|
| 104 |
|
| 105 |
for content in content_list:
|
| 106 |
+
if not content or not isinstance(content, dict):
|
| 107 |
+
continue
|
| 108 |
+
|
| 109 |
matches_all_filters = True
|
| 110 |
|
| 111 |
# Streaming service filter
|
|
|
|
| 122 |
|
| 123 |
# Genre filter - check if ALL selected genres are in the content's genres
|
| 124 |
if filters['genres']:
|
| 125 |
+
content_genres = set(g.strip().lower() for g in str(content.get('listed_in', '')).split(','))
|
| 126 |
selected_genres = set(g.strip().lower() for g in filters['genres'])
|
| 127 |
|
| 128 |
if not selected_genres.issubset(content_genres):
|
|
|
|
| 145 |
matches_all_filters = False
|
| 146 |
continue
|
| 147 |
|
| 148 |
+
# Duration filter (different handling for movies)
|
| 149 |
if filters['content_type'] == 'Movie':
|
| 150 |
+
duration = str(content.get('duration', ''))
|
| 151 |
if 'min' in duration:
|
| 152 |
try:
|
| 153 |
minutes = int(duration.split()[0])
|
|
|
|
| 160 |
|
| 161 |
# Director filter (optional)
|
| 162 |
if filters['director']:
|
| 163 |
+
director = str(content.get('director', '')).lower()
|
| 164 |
if not any(name.strip().lower() in director for name in filters['director'].split(',')):
|
| 165 |
matches_all_filters = False
|
| 166 |
continue
|
| 167 |
|
| 168 |
# Cast filter (optional)
|
| 169 |
if filters['cast']:
|
| 170 |
+
cast = str(content.get('cast', '')).lower()
|
| 171 |
if not any(name.strip().lower() in cast for name in filters['cast'].split(',')):
|
| 172 |
matches_all_filters = False
|
| 173 |
continue
|
|
|
|
| 422 |
|
| 423 |
# Duration range slider (for movies only)
|
| 424 |
movie_durations = [
|
| 425 |
+
int(str(c.get('duration', '0 min')).split()[0])
|
| 426 |
for c in all_content
|
| 427 |
+
if c and c.get('type') == 'Movie' and 'min' in str(c.get('duration', ''))
|
| 428 |
]
|
| 429 |
+
|
| 430 |
if movie_durations:
|
| 431 |
+
min_duration = min(d for d in movie_durations if d > 0)
|
| 432 |
+
max_duration = max(movie_durations)
|
| 433 |
duration_range = st.slider(
|
| 434 |
"Movie Duration (minutes)",
|
| 435 |
min_value=min_duration,
|