async def get_lyrics(request, source, artist, song): """A route to indicate what to do after the source info is in.""" artist = artist.replace("%20", " ") song = song.replace("%20", " ") if source == "metro": return json({ "source": "MetroLyrics", "artist": artist, "Song": song, "Lyrics": lw.get_lyrics('metrolyrics', artist, song) }) # if source == 'az': # return json({ # "source": "az", # "artist": artist, # "Song": song, # "Lyrics": az.lyrics_get(az.urlmaker(artist, song)) # }) if source == 'lyricswikia': return json({ "source": 'lyricswikia', "artist": artist, "Song": song, "Lyrics": lw.get_lyrics('metrolyrics', artist, song) }) if source == 'genius': return json({ "source": 'genius', "artist": artist, "Song": song, "Lyrics": lw.get_lyrics('genius', artist, song) }) else: return text("Bad Request! Try visiting Home page for help")
async def lyrics(ctx, *args): """Ex: '!lyrics artist name - song name'""" try: arr = '{}'.format(" ".join(args)).split(' - ') lyrics = lyricfetcher.get_lyrics('lyricswikia', arr[0], arr[1]) if lyrics is None or lyrics == 404 or lyrics == "404": message = await client.say('Not found. ¯\_(ツ)_/¯ \ *Format:* `"Artist - Song"`') await asyncio.sleep(10) await client.delete_message(message) else: await client.say('```' + lyrics + '```') except: await client.send_message(ctx.message.channel, \ "Bad syntax - Format: `artist - song`")
def main(artist, songs, google_model): matrix = [] graph = {} with open("./src/graph.json") as data_file: graph = json.load(data_file) data_file.close() for i, song in enumerate(songs): lyrics = lyricfetcher.get_lyrics('metrolyrics', artist, song) #lyrics = clean_text(lyrics) print(lyrics) if (lyrics != None and lyrics != 404 and lyrics != "404"): matrix.append([artist, song, lyrics]) for i, song in enumerate(matrix, start=0): dict = {"id": i, "name": song[1], "artist": song[0]} graph["nodes"].append(dict) for i, song in enumerate(matrix, start=0): for j, song_2 in enumerate(matrix[:i], start=0): #try : weight = min((google_model.wmdistance(song[2], song_2[2])), 1) if (weight == float('inf') or weight == ""): weight = 0 dict = { "source": i, "target": j, # "song 1": song, # "song 2": song_2, "weight": weight } if (dict["weight"] == None): dict["weight"] = 0 graph["edges"].append(dict) #except : # pass with open('./src/graph.json', 'w') as fp: print(json.dumps(graph)) json.dump(graph, fp) fp.close()
def test_metrolyrics(self): """Method to test metrolyrics.""" bad_res = lw.get_lyrics('metrolyrics', 'eminem', 'los yourself') good_res = lw.get_lyrics('metrolyrics', 'eminem', 'lose yourself') self.assertEqual(bad_res, 404) self.assertTrue(good_res)
def test_lyricswikia(self): """Method to test Lyricswikia.""" bad_res = lw.get_lyrics('lyricswikia', 'eminem', 'los yourself') good_res = lw.get_lyrics('lyricswikia', 'eminem', 'lose yourself') self.assertEqual(bad_res, 404) self.assertTrue(good_res)