def getInfoLyric(self, video, numWord=10): """ Extraemos la informacion del API de MusixMatch. En caso de que el numero de palabras sea inferior a cinco devuelve la lista vacia. Aqui se define el numero maximo de palabras que quiere de la cancion""" trackToList = [] words = self.pieceOfLyric(video, numWord) while trackToList == []: # modificando esta linea se modifica el minimo para su validez if len(words.split()) < 3: break tracks = track.search(q=words) if tracks == []: words1 = self.didYouMean(words) if words != "": tracks = track.search(q=words1) for k in range(len(tracks)): trackToString = str(tracks[k])[18:] trackToDict = ast.literal_eval(trackToString) trackToList.append(trackToDict) wordSplit = words.split() wordSplitLessOne = wordSplit[1:] words = "" for ch in range(len(wordSplitLessOne)): words += str(wordSplitLessOne[ch]) + " " return trackToList
def getInfoLyric(self, video, numWord=10): """ Extraemos la informacion del API de MusixMatch. En caso de que el numero de palabras sea inferior a cinco devuelve la lista vacia. Aqui se define el numero maximo de palabras que quiere de la cancion""" trackToList = [] words = self.pieceOfLyric(video, numWord) while trackToList == []: # modificando esta linea se modifica el minimo para su validez if len(words.split()) < 3: break tracks = track.search(q = words) if tracks == []: words1 = self.didYouMean(words) if words != "": tracks = track.search(q = words1) for k in range(len(tracks)): trackToString = str(tracks[k])[18:] trackToDict = ast.literal_eval(trackToString) trackToList.append(trackToDict) wordSplit = words.split() wordSplitLessOne = wordSplit[1:] words = "" for ch in range(len(wordSplitLessOne)): words += str(wordSplitLessOne[ch]) + " " return trackToList
def searchQuery(artist, name): ''' Search for a song given the artist name and track name. Input: String artist - artist name to search for String name - song name to search for Return: List<Track> songs ''' searchStr = artist + ' ' + name songs = TRACK.search(q=searchStr) return songs
def get_lyrics(name=None, artist=None): track_result_list = track.search(q_track=name, q_artist=artist) result = filterLyrics(track_result_list[0].lyrics()["lyrics_body"]) return result
def get_lyrics_for_track_name(name="", artist="", lyrics=""): track_result_list = track.search(q_track=name, q_artist=artist, q_lyrics=lyrics) result = filterLyrics(track_result_list[0].lyrics()["lyrics_body"]) return result
print ' python test.py -go' sys.exit(0) if __name__ == '__main__': # help menu if len(sys.argv) < 2 or sys.argv[1] in ('help','-help','--help'): die_with_usage() # create a track track = TRACK.Track(4110618) print '*********** TRACK 4110618 ACQUIRED ************' print track # get a list of tracks from a search tracks = TRACK.search(q='Rick Astley Never Gonna Give You Up') print '********** LIST OF TRACKS ACQUIRED ************' for k in range(min(3,len(tracks))): print tracks[k] # get a list of tracks from charts tracks = TRACK.chart() print '****** LIST OF TRACKS FROM CHART ACQUIRED ******' for k in range(min(3,len(tracks))): print tracks[k] # lyrics lyrics_dict = track.lyrics() print '************* LYRICS ACQUIRED ************' print lyrics_dict
def get_lyrics_for_track_name(name='', artist='', lyrics=''): track_result_list = track.search(q_track=name, q_artist=artist, q_lyrics=lyrics) result = filterLyrics(track_result_list[0].lyrics()['lyrics_body']) return result
def getTracks(self, query): """Get tracks matching a query term""" ## Need to do the import here to be sure the environment var is set from musixmatch import track as TRACK return self.filterTracks(TRACK.search(q=query, page_size=20))
sys.exit(0) if __name__ == '__main__': # help menu if len(sys.argv) < 2 or sys.argv[1] in ('help', '-help', '--help'): die_with_usage() # create a track track = TRACK.Track(4110618) print '*********** TRACK 4110618 ACQUIRED ************' print track # get a list of tracks from a search tracks = TRACK.search(q='Rick Astley Never Gonna Give You Up') print '********** LIST OF TRACKS ACQUIRED ************' for k in range(min(3, len(tracks))): print tracks[k] # get a list of tracks from charts tracks = TRACK.chart() print '****** LIST OF TRACKS FROM CHART ACQUIRED ******' for k in range(min(3, len(tracks))): print tracks[k] # lyrics lyrics_dict = track.lyrics() print '************* LYRICS ACQUIRED ************' print lyrics_dict
def randomFetch(depth, seed="Radiohead"): """fetch subtitles from MusiXmatch through a seed artist""" try: # print "Step 1" artist = ARTIST.search(q_artist=seed)[0] except: errorMsg = "Cannot get seed artist." return errorMsg # print "Step 2" relatedArtistList = [] errorMsg = getRelatedArtists(artist, depth, relatedArtistList) if errorMsg: return errorMsg # assert type(relatedArtistList[0]) == ARTIST.Artist if not relatedArtistList: errorMsg = "Not enough related artists." return errorMsg # print "Step 3" tracks = [] for artist in relatedArtistList: trackList = TRACK.search(q_artist=artist.artistdata["artist_name"], q_lyrics="and") if len(trackList) > 1: index = random.randint(0, len(trackList)-1) tracks.append(trackList[index]) elif len(trackList): index = 0 tracks.append(trackList[index]) if not tracks: errorMsg = "Not enough tracks." return errorMsg # print "Step 4" subtitles = [] names = [] artistNames = [] for track in tracks: if track.trackdata["has_subtitles"]: subtitle = track.subtitles() if subtitle and len(subtitle["subtitle_body"]) > 0: # subtitle is not null subtitles.append(subtitle) names.append(track.trackdata["track_name"]) artistNames.append((track.trackdata["artist_name"])) if not subtitles: errorMsg = "Not enough subtitles." return errorMsg # print "Step 5" fileNames = [] for i in range(len(subtitles)): content = subtitles[i]["subtitle_body"] name = names[i] artistName = artistNames[i] # derive proper file name fileName = re.sub(r' ', "0tttt", name) fileName = re.sub(r'\W', '', fileName) fileName = fileName.replace("0tttt", " ") fileName2 = re.sub(r' ', "0tttt", artistName) fileName2 = re.sub(r'\W', '', fileName2) fileName2 = fileName2.replace("0tttt", " ") fileName2 = fileName + "-" + fileName2 + ".subtitle" writeSubtitleFile(content, getPath(fileName2)) fileNames.append(fileName2) print fileNames return fileNames