palltaruo commited on
Commit
d18bba7
·
verified ·
1 Parent(s): 3e483eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
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
- results = []
83
- for item in filtered_items[:3]: # Limit to top 3
84
- results.append({
85
- 'title': item['snippet']['title'],
86
- 'channel': item['snippet']['channelTitle'],
87
- 'views': int(item['statistics'].get('viewCount', 0)),
88
- 'url': f"https://www.youtube.com/watch?v={item['id']}"
89
- })
90
 
91
- return results
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}")