def addReleases(artist_id, update_artist = True): artist_record = Artist.get(id=artist_id) musicbrainz_artist = musicbrainz.getBestArtistMatch(artist_record.name) release_ids = [] for release in musicbrainz_artist.getReleases(): release_ids.append(utils.extractUuid(release.id)) # These release results do not contain all the information, we must re-query for that info... for rid in release_ids: release = musicbrainz.getRelease(rid) if not release: continue release_group_id = utils.extractUuid(release.getReleaseGroup().id) try: release_group_tracked = Album.get(release_group_id=release_group_id) except peewee.DoesNotExist: release_group_tracked = None if release_group_tracked: continue release_record = Album.create( musicbrainz_id = rid, asin = release.getAsin(), release_group_id = release_group_id, artist_id = artist_id, name = release.getTitle(), type = release.getType(), released_on = release.getEarliestReleaseDate(), state = 'wanted') track_number = 1 for track in release.getTracks(): Track.create( album_id = release_record.id, number = track_number, title = track.getTitle(), length = track.getDuration(), state = 'wanted') track_number += 1 # Rescan the Music Library after adding new releases to see if the user has # them or not. Will not run if explicitly told not to by the caller. if(update_artist): ThreadPool.put(updateArtist, {'artist_id': artist_id})
def addArtist(id3_artist_name, path): musicbrainz_artist = musicbrainz.getBestArtistMatch(id3_artist_name) if musicbrainz_artist is None: unique_name = id3_artist_name artist_mb_id = None else: unique_name = musicbrainz_artist.getUniqueName() artist_mb_id = utils.extractUuid(musicbrainz_artist.id) try: artist = Artist.get(peewee.Q(musicbrainz_id=artist_mb_id) | peewee.Q(unique_name=unique_name)) except peewee.DoesNotExist: artist = Artist.create( name = id3_artist_name, unique_name = unique_name, location = path, state = 'wanted', musicbrainz_id = artist_mb_id) return artist