Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -78,17 +78,23 @@ def search_youtube_guitar_tutorials(song_name: str) -> List[Dict[str, Any]]:
|
|
| 78 |
# Sort by views if we have enough tutorials
|
| 79 |
if len(filtered_items) >= 3:
|
| 80 |
filtered_items.sort(key=lambda x: int(x['statistics'].get('viewCount', 0)), reverse=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
'url': f"https://www.youtube.com/watch?v={item['id']}"
|
| 89 |
-
})
|
| 90 |
|
| 91 |
-
return
|
| 92 |
|
| 93 |
except requests.exceptions.RequestException as e:
|
| 94 |
print(f"Error searching YouTube: {e}")
|
|
|
|
| 78 |
# Sort by views if we have enough tutorials
|
| 79 |
if len(filtered_items) >= 3:
|
| 80 |
filtered_items.sort(key=lambda x: int(x['statistics'].get('viewCount', 0)), reverse=True)
|
| 81 |
+
|
| 82 |
+
if not filtered_items:
|
| 83 |
+
return "No guitar tutorials found."
|
| 84 |
+
|
| 85 |
+
formatted_results = ["Here are the top guitar tutorials:"]
|
| 86 |
+
for i, item in enumerate(filtered_items[:3], 1):
|
| 87 |
+
views = int(item['statistics'].get('viewCount', 0))
|
| 88 |
+
formatted_views = f"{views:,}" if views > 0 else "N/A"
|
| 89 |
|
| 90 |
+
formatted_results.append(
|
| 91 |
+
f"\n{i}. {item['snippet']['title']}\n"
|
| 92 |
+
f" Channel: {item['snippet']['channelTitle']}\n"
|
| 93 |
+
f" Views: {formatted_views}\n"
|
| 94 |
+
f" Link: https://www.youtube.com/watch?v={item['id']}\n"
|
| 95 |
+
)
|
|
|
|
|
|
|
| 96 |
|
| 97 |
+
return "\n".join(formatted_results)
|
| 98 |
|
| 99 |
except requests.exceptions.RequestException as e:
|
| 100 |
print(f"Error searching YouTube: {e}")
|