palltaruo commited on
Commit
30722b2
·
verified ·
1 Parent(s): 7c6c55a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -35,11 +35,11 @@ def search_youtube_guitar_tutorials(song_name: str) -> List[Dict[str, Any]]:
35
  base_url = "https://www.googleapis.com/youtube/v3/search"
36
  search_params = {
37
  'part': 'snippet',
38
- 'q': f"{song_name} guitar tutorial",
39
  'type': 'video',
40
  'videoDefinition': 'high',
41
- 'order': 'viewCount',
42
- 'maxResults': 5,
43
  'key': api_key
44
  }
45
  search_url = f"{base_url}?{urlencode(search_params)}"
@@ -65,9 +65,22 @@ def search_youtube_guitar_tutorials(song_name: str) -> List[Dict[str, Any]]:
65
  video_response = requests.get(video_details_url)
66
  video_response.raise_for_status()
67
  video_data = video_response.json()
68
-
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  results = []
70
- for item in video_data.get('items', [])[:3]: # Limit to top 3
71
  results.append({
72
  'title': item['snippet']['title'],
73
  'channel': item['snippet']['channelTitle'],
 
35
  base_url = "https://www.googleapis.com/youtube/v3/search"
36
  search_params = {
37
  'part': 'snippet',
38
+ 'q': f"{song_name} guitar tutorial how to play",
39
  'type': 'video',
40
  'videoDefinition': 'high',
41
+ 'order': 'relevance',
42
+ 'maxResults': 10,
43
  'key': api_key
44
  }
45
  search_url = f"{base_url}?{urlencode(search_params)}"
 
65
  video_response = requests.get(video_details_url)
66
  video_response.raise_for_status()
67
  video_data = video_response.json()
68
+
69
+ # Filter for actual guitar tutorials
70
+ tutorial_keywords = ['tutorial', 'lesson', 'how to play', 'guitar cover', 'chords', 'tabs']
71
+
72
+ filtered_items = []
73
+ for item in video_data.get('items', []):
74
+ title_lower = item['snippet']['title'].lower()
75
+ if any(keyword in title_lower for keyword in tutorial_keywords):
76
+ filtered_items.append(item)
77
+
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'],