Skip to content

Commit

Permalink
Fix error for cases with no song/video results
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Apr 10, 2020
1 parent fe5af6e commit d31699b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion YouTube.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def get_best_fit_song_id(self, results, song):

match_score[res['videoId']] = sum(scores) / len(scores)

if len(match_score) == 0:
return None

#don't return songs with titles <45% match
max_score = max(match_score, key=match_score.get)
return max_score if title_score[max_score] > 0.45 else None
Expand All @@ -46,7 +49,7 @@ def search_songs(self, tracks):
videoIds = []
songs = list(tracks)
notFound = list()
for i, song in enumerate(songs):
for i, song in enumerate(songs[130:140]):
query = song['artist'] + ' ' + song['name']
query = query.replace(" &", "")
result = self.api.search(query)
Expand Down

0 comments on commit d31699b

Please sign in to comment.