Skip to content

Commit

Permalink
Fix issues related to ytmusicapi 0.7 update
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed May 8, 2020
1 parent cb5ce66 commit fc7bbc4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions YouTube.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ def get_best_fit_song_id(self, results, song):
titleSplit = title.split('-')
if len(titleSplit) == 2:
title = titleSplit[1]
artists = res['artist']
else:
artists = ' '.join([a['name'] for a in res['artists']])

title_score[res['videoId']] = difflib.SequenceMatcher(a=title.lower(), b=song['name'].lower()).ratio()

scores = [durationMatch * 5, title_score[res['videoId']],
difflib.SequenceMatcher(a=res['artist'].lower(), b=song['artist'].lower()).ratio()]
difflib.SequenceMatcher(a=artists.lower(), b=song['artist'].lower()).ratio()]

#add album for songs only
if res['resultType'] == 'song' and 'album' in res:
scores.append(difflib.SequenceMatcher(a=res['album'].lower(), b=song['album'].lower()).ratio())
if res['resultType'] == 'song' and res['album'] is not None:
scores.append(difflib.SequenceMatcher(a=res['album']['name'].lower(), b=song['album'].lower()).ratio())

match_score[res['videoId']] = sum(scores) / (len(scores) + 1) * max(1, int(res['resultType'] == 'song') * 1.5)

Expand Down

0 comments on commit fc7bbc4

Please sign in to comment.