-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhot100Lyrics.py
145 lines (132 loc) · 5.73 KB
/
hot100Lyrics.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#https://pypi.org/project/PyLyrics/
#from PyLyrics import *
#https://github.com/guoguo12/billboard-charts
#https://github.com/johnwmillr/LyricsGenius
import sys
from datetime import date, timedelta
import billboard
import lyricsgenius
# Set api key
genius = lyricsgenius.Genius("0KOm32ykagdXVPBan93S4QMYRt80vo3j_VnJoRZaL4yS2hiQS53HwrD7eWnJCXdz")
# ==================== Import arguments from command line =====================
# Most recent month (0 args)
if len(sys.argv) == 1:
yearInputStart = (date.today()).year
yearInputEnd = yearInputStart
monthInputStart = (date.today()).month
monthInputEnd = monthInputStart
# Year specified case (1 arg)
elif len(sys.argv) == 2:
yearInputStart = int(sys.argv[1])
yearInputEnd = yearInputStart + 1
monthInputStart = 1
monthInputEnd = 12
# Year and month specified case (2 args)
elif len(sys.argv) == 3:
yearInputStart = int(sys.argv[1])
yearInputEnd = yearInputStart
monthInputStart = int(sys.argv[2])
monthInputEnd = monthInputStart
# Start year, End year, Start Month, End month (4 args)
elif len(sys.argv) == 5:
yearInputStart = int(sys.argv[1])
monthInputStart = int(sys.argv[2])
yearInputEnd = int(sys.argv[3])
monthInputEnd = int(sys.argv[4])
else:
yearInputStart, yearInputEnd = -1
monthInputStart, monthInputEnd = -1
print("Entered Wrong format.")
datetime.date(yearInputStart)
dayInput = 1
for yearInput in range(yearInputStart, yearInputEnd + 1):
for monthInput in range(monthInputStart, monthInputEnd + 1):
# Make the date
dateOfBillboard = date(yearInput, monthInput, dayInput)
# Get the songs from the top 100
chart = billboard.ChartData('hot-100', dateOfBillboard.strftime("%Y-%m-%d"), fetch=True, timeout=5)
successList = []
failureList = []
allLyrics = []
successCounter = 0
failureCounter = 0
stringParseIndex = 0
# Parse song titles and song artists for better search
for song in chart:
# Artist Parse
if " Featuring " in song.artist:
# Find index of Featuring and subString out the main artist
stringParseIndex = song.artist.find("Featuring")
song.artist = song.artist[0:stringParseIndex-1]
print("Is artist " + song.artist + " correct? F")
if " X " in song.artist or " x " in song.artist:
# Find index of the X or x
stringParseIndex = song.artist.find(" X ")
if stringParseIndex == -1:
stringParseIndex = song.artist.find(" x ")
# subString the main artist out.
song.artist = song.artist[0:stringParseIndex]
print("Is artist " + song.artist + " correct? X")
# Title Parse
if " (" in song.title and ")" in song.title:
stringParseIndex = song.title.find(" (")
song.title = song.title[0:stringParseIndex]
print("Is title " + song.title + " correct? ()")
# Run Songs through LyricsGenius (genius)
# for song in chart:
# try:
# foundSong = genius.search_song(song.title, song.artist)
# allLyrics.append("{{" + song.title + " by " + song.artist + "}}" + "\n" + foundSong.lyrics)
# successCounter += 1
# except:
# failureCounter += 1
# TEST 10 VALUES
# for x in range(10):
# song = chart[x]
# try:
# foundSong = genius.search_song(song.title, song.artist)
# allLyrics.append(song.title + " by " + song.artist + "\n" + foundSong.lyrics)
# successCounter += 1
# except:
# failureCounter += 1
#
# Number of Successes and Failures of Genius
# print("genius -> Successes: " + str(successCounter) + " | Failures: " + str(failureCounter))
# Run Lyric search through PyLyrics (lyrics.wiki)
# for song in chart:
# try:
# parsedArtist = song.artist
# if "Featuring" in song.artist:
# Find index of Featuring
# stringParseIndex = song.artist.find("Featuring")
# Find the substring that only has the main artist
# newArtistStr = song.artist[0:stringParseIndex-1]
# lyrics = PyLyrics.getLyrics(song.artist, song.title)
# elif "X" in song.artist:
# Find index of Featuring
# stringParseIndex = song.artist.find("Featuring")
# Find the substring that only has the main artist
# newArtistStr = song.artist[0:stringParseIndex - 1]
# song.artist.find("X")
# print(song.artist)
# else:
# lyrics = PyLyrics.getLyrics(song.artist, song.title)
# allLyrics.append(lyrics)
# successList.append(song)
# successCounter += 1
# except:
# failureList.append(song)
# failureCounter += 1
# Number of Successes and Failures of PyLyrics
# print("lyrics.wiki -> Successes: " + str(successCounter) + " | Failures: " + str(failureCounter))
# successCounter = 0
# failureCounter = 0
# Check how many lyrics were actually fetched
# Print how many lyrics are in the Lyric List
# print("Lyric Count: " + str(len(allLyrics)))
#
# File writing
# f = open(dateOfBillboard.strftime("%Y-%m-%d") + "-Lyrics.txt", mode='w+', encoding='utf8')
# for lyric in allLyrics:
# f.write(lyric + "\n")
# f.close()