-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlyrics.py
More file actions
39 lines (33 loc) · 1.12 KB
/
Copy pathlyrics.py
File metadata and controls
39 lines (33 loc) · 1.12 KB
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
import os
from pathlib import Path
import lyricsgenius
GENIUS_API_KEY = os.getenv("GENIUS_API_KEY")
if not GENIUS_API_KEY:
raise RuntimeError("Set GENIUS_API_KEY in your environment before running this script.")
genius = lyricsgenius.Genius(GENIUS_API_KEY)
def save_lyrics(songs, artist_name, album_name):
artist_folder = Path("songs") / "_".join(artist_name.split(" "))
artist_folder.mkdir(parents=True, exist_ok=True)
for i in range(len(songs
)):
song_title = songs[i]
song = genius.search_song(song_title, artist_name)
if song is None:
continue
lyrics = song.lyrics
output_name = "{}_{}_{}.txt".format(i + 1, album_name, "-".join("".join(song_title.split("'")).split(" ")))
with open(artist_folder / output_name, "w") as f:
f.writelines(lyrics.split('\\n'))
if __name__ == '__main__':
songs = [
'the box',
'down below',
'project dreams',
'die young',
'boom boom room',
'high fashion',
'roll dice',
'war baby',
'every season'
]
save_lyrics(songs, 'roddy ricch', '')