def register_songs(self): """Discovers and creates db entries for the Songs of this Album through the musixmatch api. usage: >>> from api.music import Artist >>> a = Artist.get(tag="ExplosionsintheSky") >>> a.albums[0].register_songs() """ songs = Musix.album_songs(self.musixmatch) for song in songs: print(song) try: s = Song.get(musixmatch=str(song['track_id'])) except core.GrooveboxException: s = Song(musixmatch=str(song['track_id']), name=song['track_name'], artist_id=self.artist_id) s.create() s.albums.append(self) try: s.save() except Exception: db.remove()
def discography(self, songs=False): """Creates a discography for this artist by:" 1. Updating the Artist with metadata + genres 2. Creating a db entry for each of the Artist's `Albums` 3. For each album, create (if !exists) or fetch Song and map to Album 4. For each Song, map Tracks whose titles match with >80% confidence """ def fillin_artist(m): self.musixmatch = m['artist']['artist_id'] self.mbid = m['artist']['artist_mbid'] or None genres = [x['music_genre']['music_genre_name'] for x in m['artist']['primary_genres']['music_genre_list']] for genre in genres: try: g = Genre.get(name=genre) if g not in self.genres: self.genres.append(g) except: self.genres.append(Genre(name=genre)) def create_albums(albums, songs=False): albums = m['albums'] for data in albums: album = data['album'] try: a = Album.get(musixmatch=album['album_id']) except: a = Album(name=album['album_name'], mbid=album['album_mbid'] or None, musixmatch=album['album_id'], coverart=album['album_coverart_800x800']) self.albums.append(a) if songs: a.register_songs() m = Musix.artist(self.name, albums=True) fillin_artist(m) create_albums(m['albums']) self.save()
def registeralbums(self, artist_id=None): if artist_id and not self.musixmatch: self.musixmatch = artist_id if self.musixmatch: return Musix.albums(self.musixmatch)