Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -36,14 +36,14 @@ def get_iso8601_date(time_frame):
|
|
36 |
else:
|
37 |
return ""
|
38 |
|
39 |
-
def youtube_search(query, upload_date, video_type, duration,
|
40 |
search_url = "https://www.googleapis.com/youtube/v3/search"
|
41 |
all_results = []
|
42 |
params = {
|
43 |
"part": "snippet",
|
44 |
"q": query,
|
45 |
"maxResults": 50,
|
46 |
-
"order":
|
47 |
}
|
48 |
|
49 |
if upload_date:
|
@@ -178,12 +178,11 @@ with gr.Blocks(css="""
|
|
178 |
upload_date_input = gr.Dropdown(label="Upload Date", choices=["", "Last Hour", "Today", "This Week", "This Month", "This Year"])
|
179 |
video_type_input = gr.Dropdown(label="Type", choices=["All", "Video", "Channel", "Playlist"])
|
180 |
duration_input = gr.Dropdown(label="Duration", choices=["", "Short (<4 mins)", "Medium (4-20 mins)", "Long (>20 mins)"])
|
181 |
-
sort_by_input = gr.Dropdown(label="Sort By", choices=["relevance", "date", "viewCount", "rating"], value="relevance")
|
182 |
search_button = gr.Button("Search")
|
183 |
search_output = gr.Gallery(label="Search Results", columns=1, height="800px", elem_id="search_output")
|
184 |
|
185 |
-
def update_search_results(query, upload_date, video_type, duration
|
186 |
-
search_results = youtube_search(query, upload_date, video_type, duration
|
187 |
gallery_items = []
|
188 |
video_ids = []
|
189 |
video_types = []
|
@@ -207,7 +206,7 @@ with gr.Blocks(css="""
|
|
207 |
|
208 |
search_button.click(
|
209 |
update_search_results,
|
210 |
-
inputs=[search_query_input, upload_date_input, video_type_input, duration_input
|
211 |
outputs=[search_output, video_ids_state, video_types_state]
|
212 |
)
|
213 |
search_output.select(
|
|
|
36 |
else:
|
37 |
return ""
|
38 |
|
39 |
+
def youtube_search(query, upload_date, video_type, duration, max_results=50):
|
40 |
search_url = "https://www.googleapis.com/youtube/v3/search"
|
41 |
all_results = []
|
42 |
params = {
|
43 |
"part": "snippet",
|
44 |
"q": query,
|
45 |
"maxResults": 50,
|
46 |
+
"order": "relevance" # Default ordering
|
47 |
}
|
48 |
|
49 |
if upload_date:
|
|
|
178 |
upload_date_input = gr.Dropdown(label="Upload Date", choices=["", "Last Hour", "Today", "This Week", "This Month", "This Year"])
|
179 |
video_type_input = gr.Dropdown(label="Type", choices=["All", "Video", "Channel", "Playlist"])
|
180 |
duration_input = gr.Dropdown(label="Duration", choices=["", "Short (<4 mins)", "Medium (4-20 mins)", "Long (>20 mins)"])
|
|
|
181 |
search_button = gr.Button("Search")
|
182 |
search_output = gr.Gallery(label="Search Results", columns=1, height="800px", elem_id="search_output")
|
183 |
|
184 |
+
def update_search_results(query, upload_date, video_type, duration):
|
185 |
+
search_results = youtube_search(query, upload_date, video_type, duration)
|
186 |
gallery_items = []
|
187 |
video_ids = []
|
188 |
video_types = []
|
|
|
206 |
|
207 |
search_button.click(
|
208 |
update_search_results,
|
209 |
+
inputs=[search_query_input, upload_date_input, video_type_input, duration_input],
|
210 |
outputs=[search_output, video_ids_state, video_types_state]
|
211 |
)
|
212 |
search_output.select(
|