def init_genius(token): # get the genius instanse genius = Genius(token) # 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 = ["(Remix)", "(Live)"] return genius
def main(): genius = Genius(apikeys.genius) genius.excluded_terms = ['(How to pronounce)'] genius.remove_section_headers = True genius.skip_non_songs = True pinyin = Pinyin() song_info = [ input("Enter the song name\n"), input( "Enter the artist name (recommended, leave blank if you don't know)\n" ) ] song = genius.search_song(song_info[0], song_info[1]) lyrics = song.lyrics pinyin_lyrics = pinyin.get_pinyin(lyrics, splitter=' ', tone_marks='marks') pinyin_lyrics = cleanup(pinyin_lyrics) print(pinyin_lyrics) outfile_path = "C:\\Users\\Declan\\Desktop\\" + song.title + ', ' + song.artist + '-Pinyin.txt' outfile = open(outfile_path, 'w', encoding='utf-8') outfile.write(pinyin_lyrics) outfile.close()
from datetime import datetime from Creds import token, csv_pre from lyricsgenius import Genius import os import pandas as pd genius = Genius(token, timeout=10) path = 'Songs/' # genius formatting genius.remove_section_headers = True genius.skip_non_songs = True genius.excluded_terms = ["(Remix)"] class ReadArtist: def __init__(self, artist): self.time = datetime.now() self.artist = artist self.artist_dict = {} self.file_n = path + artist + csv_pre self.artist_time = {} def collect_song_data(self, song_obj): song_dict = song_obj.to_dict() song_dict['Artist'] = self.artist if type(song_dict['year']) == float: str(song_dict['year']) if song_dict['year'] == 'nan':
else: return(None, None, None) lyrics = Lyrics.getSongLyrics(title, artist, genius) return(title, artist, lyrics) if __name__ == '__main__': logging.basicConfig( format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO) # api authentication tokens auth_manager = SpotifyClientCredentials( client_id=API_Keys.spotify_client_id, client_secret=API_Keys.spotify_secret) sp = spotipy.Spotify(auth_manager=auth_manager) genius = Genius(API_Keys.genius_access_token) genius.excluded_terms = ["(Remix)", "(Live)"] genius.timeout = 15 genius.sleep_time = 2 tokenizer = RegexpTokenizer(r'\w+') lemmatizer = WordNetLemmatizer() playlists = sp.user_playlists(USER) playlistsUsed = set() docs = [] songsUsed = set() with open('outputs/songsUsed.csv', mode='w', newline='') as songsUsedCSV, open('outputs/songLyrics.txt', mode='w') as songLyrics: songsUsedWriter = csv.writer( songsUsedCSV, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) while len(playlistsUsed) <= 50: