def get_lyrics(artist_name, song): filename = song.replace(' ', '_') filenamenew = filename + '.gk' lyrics = pylyrics3.get_song_lyrics(artist_name, song) # print(lyrics) with open("{}{}.csv".format(neo4j_path, filename), "w") as f: f.write(lyrics) with open('{}{}.csv'.format(neo4j_path, filename), "r") as openfile: with open('{}{}.csv'.format(neo4j_path, filenamenew), "w") as out_file: for j, line in enumerate(openfile): out_file.write('{}{}'.format((j + 1), ',' + line.replace(",", ""))) with open('{}{}.csv'.format(neo4j_path, filenamenew), "r") as csv_header: csv_reader = csv.reader(csv_header) filenamefinal = 'final_' + filenamenew with open('{}{}.csv'.format(neo4j_path, filenamefinal), "w") as csv_final: csv_writer = csv.writer(csv_final) csv_writer.writerow(['Sequence', 'Songsentence']) for line in csv_reader: csv_writer.writerow(line) return filenamefinal, artist_name, song, lyrics
def getRandomSong(): # Pick a random song song = random.choice(songs) artist = song[0] title = song[1] # Retrieve lyrics from lyrics wiki and split into list string = pylyrics3.get_song_lyrics(artist, title) lyrics = str.splitlines(string) return artist, title, lyrics
def get_popular_song(): artist_song = read_songs('chart2000-songyear-0-3-0048.csv') N = len(artist_song) rn = random.randint(0, N) artist, song = artist_song[rn] lyrics = pylyrics3.get_song_lyrics(artist, song) if lyrics is None: return get_popular_song() lyrics = lyrics.split('\n') formatted_lyrics = [] for lyric in lyrics: formatted_lyrics.append(lyric.strip()) return formatted_lyrics, artist, song
def index(): song_lyrics = '' graphkaraoke = GraphKaraokeNeo4j() if request.method == 'POST': clean_db() # receiving the form artist_name = request.form['artist'] song_title = request.form['song_title'] print(artist_name) print(song_title) try: graphkaraoke.reset_youtubeplayer() song_lyrics = pylyrics3.get_song_lyrics(artist_name, song_title) get_lyrics(artist_name, song_title) filename = 'final_' + str(song_title).replace(' ', '_') loadfile = 'file:///{}.gk.csv'.format(filename) graphkaraoke.graph_karaoke(loadfile) graphkaraoke.add_artist_song(artist_name, song_title) return render_template('index.html', song_lyrics=song_lyrics, artist=request.form['artist'], song_title=request.form['song_title']) except Exception as e: print(e) error_msg = "Sorry the DJ, doesn't have caryy {} by {} :) Perahps you have a typo?".format( song_title, artist_name) return render_template('index.html', song_lyrics=song_lyrics, artist='', song_title=error_msg) else: clean_db() song_lyrics = '' return render_template('index.html', song_lyrics=song_lyrics)
def getlyrics(self, query): lyrics = None if "lyrics.fandom.com/wiki/" in query: try: log.debug("Lyrics: requesting {0}".format(query)) lyrics = pylyrics3.get_lyrics_from_url(query) except Exception: pass else: try: log.debug("Lyrics: requesting {0}".format(query)) query = query.split(",", 1) lyrics = pylyrics3.get_song_lyrics(query[0].strip(), query[1].strip()) except Exception: pass if lyrics: lyrics = re.sub(r"(?<!\.|\!|\?)\s+\n", ".", lyrics) lyrics = re.sub(r"\s+\n", "", lyrics) return lyrics else: return
def getlyrics(self, query, retries=0): lyrics = None while retries < 3: try: if "lyrics.fandom.com/wiki/" in query: log.debug("Lyrics: requesting {0}".format(query)) lyrics = pylyrics3.get_lyrics_from_url(query) else: log.debug("Lyrics: requesting {0}".format(query)) query = query.split(",", 1) lyrics = pylyrics3.get_song_lyrics(query[0].strip(), query[1].strip()) except: pass if lyrics: lyrics = re.sub(r"(?<!\.|\!|\?)\s+\n", ".", lyrics) lyrics = re.sub(r"\s+\n", "", lyrics) break else: log.debug("Lyrics: Failed to get lyrics. Retrying...") retries += 1 if not lyrics and retries > 2: log.info("Lyrics: maximum number of retries (3) reached.") return lyrics
def test_emo(self): '''PyLyrics3 can handle special characters + odd capitalization''' fame = pylyrics3.get_song_lyrics('fall out boy', 'fAME < iNFAMY') self.assertTrue('preacher' in fame)
def test_get_song_lyrics(self): '''PyLyrics3 can get a song given artist and (lowercase) title''' twenty2 = pylyrics3.get_song_lyrics('bon iver', '22 (over s∞∞n)') self.assertTrue('might be over soon' in twenty2)
num_tracks = 10000 playlistHeader = {'Authorization': 'Bearer ' + token} offset = 0 got = 0 dgot = 0 for i in range(int(num_tracks / 100) + 1): offsetString = '?offset=' + str(offset) res = r.get(url="https://api.spotify.com/v1/playlists/" + playlistID + '/tracks' + offsetString, headers=playlistHeader) print(res) data = res.json() f = open('D:\LyricLSTM\\lyrics.txt', "a") f2 = open('D:\LyricLSTM\\didntget.txt', "a") for t in data['items']: try: f.write( pl.get_song_lyrics(t['track']['artists'][0]['name'], t['track'] ['name']) + "\n") got += 1 except: dgot += 1 f2.write(t['track']['name'] + ' - ' + t['track']['artists'][0]['name'] + '\n') offset += 100 print(got, got + dgot)
def printlyrics(artist, title): return print(pylyrics3.get_song_lyrics(artist, title))
data = json.loads(json_results) # Write rows for track in data['items']: track_id = track['track']['id'] date_added = track['added_at'] track_name = track['track']['name'] first_artist = track['track']['artists'][0]['name'] # Track features features = get_features(track_id) # Try to get lyrics, if available lyrics = '' try: lyrics = pylyrics3.get_song_lyrics(first_artist, track_name) except: pass # Sentiment Analysis neg = None neu = None pos = None compound = None if lyrics: snt = sentiment_analyzer.polarity_scores(lyrics) neg = snt['neg'] neu = snt['neu'] pos = snt['pos'] compound = snt['compound']