forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlyrics.py
49 lines (42 loc) · 1.5 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
import lyricsgenius as lg
# File for writing the Lyrics
filename = input('Enter a filename: ') or 'Lyrics.txt'
file = open(filename, "w+")
# Acquire a Access Token to connect with Genius API
genius = lg.Genius(
'Client_Access_Token_Goes_Here',
# Skip song listing
skip_non_songs=True,
# Terms that are redundant song names with same lyrics, e.g. Old Town Raod and Old Town Road Remix
# have same lyrics
excluded_terms=["(Remix)", "(Live)"],
# In order to keep headers like [Chorus], [Bridge] etc.
remove_section_headers=True)
# List of Artist and Maximum Songs
input_string = input("Enter name of Artists separated by spaces: ")
artists = input_string.split(" ")
def get_lyrics(arr, max_song):
"""
Returns: Number of songs grabbed by Function
Saves : Text File with Lyrics
Parameters :
arr : Artist
max_song : Number of maximum songs to be grabbed
"""
# Write lyrics of k songs by each artist in arr
c = 0
# A counter
for name in arr:
try:
songs = (genius.search_artist(name,
max_songs=max_song,
sort='popularity')).songs
s = [song.lyrics for song in songs]
# A custom delimiter
file.write("\n \n <|endoftext|> \n \n".join(s))
c += 1
print(f"Songs grabbed:{len(s)}")
except:
print(f"some exception at {name}: {c}")
# Function Call
get_lyrics(artists, 3)