-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlyrics.py
86 lines (59 loc) · 2.35 KB
/
lyrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import lyricsgenius
from copy import deepcopy
# genius token get
with open('genius_token.txt') as f:
genius_token = f.readline()
genius = lyricsgenius.Genius(genius_token)
#artist = genius.search_artist("Drake", max_songs=3, sort="title")
# print(artist.songs)
# Turn off status messages
genius.verbose = False
# Remove section headers (e.g. [Chorus]) from lyrics when searching
genius.remove_section_headers = True
# Include hits thought to be non-songs (e.g. track lists)
genius.skip_non_songs = False
# Exclude songs with these words in their title
genius.excluded_terms = ["(Live)"]
# takes song and artist name and returns a list of strings containing the
# lyrics without punctuation
def get_lyric_list(song_name: str, artist_name: str):
song = genius.search_song(song_name, artist_name)
# song.lyrics --> string of lyrics with punctuation
#print(song.lyrics + "\n-----------------------\n")
lower_lyr = song.lyrics.lower()
lyric_list = lower_lyr.split() # might contain punc. at end of words
punctuation = [',', ';', ':', '!', '?',
'&', '(', ')', '-', '[', ']', '{', '}']
lyric_list_noPunc = deepcopy(lyric_list)
# print(lyric_list_noPunc)
# removes punctuation at beginning and end of word
for i in range(len(lyric_list_noPunc)):
for char in punctuation:
lyric_list_noPunc[i] = lyric_list_noPunc[i].replace(char, "")
# print('\n-------------------\n')
return lyric_list_noPunc # list of lyrics
# Takes two lists of strings and returns a score value
def compare_lyrics_old(lyric_list: list, user_list: list):
sum = 0
for i in range(len(lyric_list)):
if(i >= len(user_list)):
break
if(lyric_list[i] == user_list[i]):
sum += 1
diff = sum / len(lyric_list) * 100
return diff
# Takes two lists of strings and returns a score value
def compare_lyrics(song_lyrics, user_lyrics):
print('I')
intersection = []
for word in song_lyrics:
print('II')
if word in user_lyrics:
print('III')
intersection.append(word)
print('IV')
return len(intersection) / len(song_lyrics) * 100
# Function to print the lyrics str of the desired song
def print_lyrics(song_name: str, artist_name: str):
song = genius.search_song(song_name, artist_name)
return song.lyrics