class ArtistTest(TestCase): def setUp(self) -> None: self.genius = Genius(GENIUS_ACCESS_TOKEN) def test_artist(self): artist = self.genius.get_artist(17237) self.assertEqual(artist.name, "Foo Fighters") self.assertFalse(artist._fully_loaded_) social_media = artist.social_media self.assertTrue(artist._fully_loaded_) facebook = social_media["facebook"] self.assertEqual(facebook.handle, "foofighters") instagram = social_media["instagram"] self.assertEqual(instagram.handle, "foofighters") twitter = social_media["twitter"] self.assertEqual(twitter.handle, "foofighters") for index, song in enumerate(artist.songs): self.assertEqual(song.artist.id, artist.id) self.assertEqual(song.artist.name, artist.name) if index > 10: break for index, song in enumerate(artist.songs_by_popularity): self.assertEqual(song.artist.id, artist.id) self.assertEqual(song.artist.name, artist.name) if index > 10: break
class SongTest(TestCase): def setUp(self) -> None: self.genius = Genius(GENIUS_ACCESS_TOKEN) def test_song(self): song = self.genius.get_song(3027414) self.assertEqual(song.title, "Andromeda") self.assertEqual(song.artist.name, "Gorillaz") self.assertFalse(song._fully_loaded_) self.assertEqual(song.album.name, "Humanz (Deluxe)") self.assertEqual(song.album.artist.name, "Gorillaz") self.assertEqual(song.release_date_for_display, "March 23, 2017") self.assertTrue(song._fully_loaded_) featured = song.features[0] self.assertEqual(featured.id, 241761) self.assertEqual(featured.name, "Shelley FKA DRAM") writers = {writer.id: writer.name for writer in song.writers} self.assertIn(1974, writers) self.assertEqual(writers[1974], "Damon Albarn") self.assertIn(241761, writers) self.assertEqual(writers[241761], "Shelley FKA DRAM") media = song.media self.assertIn("1217912232", media["apple-music"].url) self.assertIn("9W44NWYwa1g", media["youtube"].url) def test_lyrics(self): self.skipTest("flaky") song = self.genius.get_song(3027414) self.assertEqual(song.title, "Andromeda") self.assertEqual(song.artist.name, "Gorillaz") self.assertFalse(song._fully_loaded_) lyrics = song.lyrics self.assertNotEqual(lyrics, []) self.assertIn("Take it in your heart now, love her", lyrics) self.assertFalse(song._fully_loaded_)
import unittest from genius.api import _API, Genius from genius.artist import Artist from genius.song import Song api = Genius() class TestCredentials(unittest.TestCase): @classmethod def setUp(cls): print('\n---------------------\nTesting credentials...\n' 'Comparing to pops Genius API keys...\n') cls.client_id = '8g35AydfE3iLO0pzUloc0hIsX9f7HJUSvI8rzMJPe142jEGaeN4bDRbsgexCNSkO' cls.client_secret = 'vp4tmXezkMJyf7J1-Nu1PUyepjZMOEAuZR3JOBxkdbTVJ0T84eWiPrkxp18rIeqtNYOUJfCMXjNc9TbO1V6dOA' cls.client_access_token = 'Ofx6Mjnd9uIp0yb_Rh-ukkWqTWu8JJ4hUAQUB363BE18WgvszI-GFHh6pAfkL_EM' def test_load_client_access_token(self): """ Check the scraper correctly loads the credentials. :return: """ assert _API._load_credentials() == self.client_access_token class TestArtist(unittest.TestCase): @classmethod def setUpClass(cls): print("\n---------------------\nSetting up Artist tests...\n") cls.artist_name = "The Beatles"
def setUp(self) -> None: self.genius = Genius(GENIUS_ACCESS_TOKEN)
if args.verbose: logging.basicConfig(level=logging.DEBUG) artists = ['NF', 'Eminem'] logger.info(f'Lyrics saved in directory{args.lyrics_dir}.') logger.info(f'Number of artists to scrap {len(artists)}') notDownloaded = [] dirname = os.path.dirname(__file__) lyrics_folder = args.lyrics_dir artist_processed_counter = 0 for artist in artists: # Initialization api = Genius() logger.info(f'Processing artist {artist}') try: artistScrap = api.search_artist(artist, max_songs=args.songs_per_artists) if artistScrap.num_songs > 0: lyrics = '' for song in artistScrap.songs: new_lyrics = song._body['lyrics'] lyrics = f'{lyrics}\n{new_lyrics}' logger.info(f'Nb characters for {artist}: {len(lyrics)}') if not os.path.exists(lyrics_folder): os.makedirs(lyrics_folder) with open(