def import_release(self, releaseid, directories): if releaseid in self.imported_releases: print "Release already updated in this import. Not doing it again" return self._ReleaseClass.objects.get(mbid=releaseid) rel = compmusic.mb.get_release_by_id(releaseid, includes=[ "artists", "recordings", "artist-rels", "release-groups" ]) rel = rel["release"] mbid = rel["id"] logger.info("Adding release %s" % mbid) release = self._create_release_object(rel) # Create release primary artists release.artists.clear() for a in rel["artist-credit"]: if isinstance(a, dict): artistid = a["artist"]["id"] artist = self.add_and_get_release_artist(artistid) logger.info(" artist: %s" % artist) if not release.artists.filter(pk=artist.pk).exists(): logger.info(" - adding to artist list") release.artists.add(artist) recordings = [] for mnum, medium in enumerate(rel["medium-list"], 1): for tnum, track in enumerate(medium["track-list"], 1): recordings.append((track["recording"]["id"], mnum, tnum)) release.recordings.clear() trackorder = 1 for recid, mnum, tnum in recordings: recob = self.add_and_get_recording(recid) self._link_release_recording(release, recob, trackorder, mnum, tnum) trackorder += 1 for perf in self._get_artist_performances( rel.get("artist-relation-list", [])): artistid, perf_type, attrs = perf self._add_release_performance(release.mbid, artistid, perf_type, attrs) self._add_release_artists_as_relationship(release, rel["artist-credit"]) external_data.import_release_image(release, directories) self.imported_releases.append(releaseid) return release
def import_release(self, releaseid, directories): if releaseid in self.imported_releases: print "Release already updated in this import. Not doing it again" return self._ReleaseClass.objects.get(mbid=releaseid) rel = compmusic.mb.get_release_by_id(releaseid, includes=["artists", "recordings", "artist-rels"]) rel = rel["release"] mbid = rel["id"] logger.info("Adding release %s" % mbid) release = self._create_release_object(rel) # Create release primary artists if self.overwrite: # If it already exists and we're doing an overwrite release.artists.clear() for a in rel["artist-credit"]: if isinstance(a, dict): artistid = a["artist"]["id"] artist = self.add_and_get_artist(artistid) logger.info(" artist: %s" % artist) if not release.artists.filter(pk=artist.pk).exists(): logger.info(" - adding to artist list") release.artists.add(artist) recordings = [] for medium in rel["medium-list"]: for track in medium["track-list"]: recordings.append(track["recording"]["id"]) print recordings if self.overwrite: release.tracks.clear() trackorder = 1 for recid in recordings: recob = self.add_and_get_recording(recid) self._link_release_recording(release, recob, trackorder) trackorder += 1 if self.overwrite: self._clear_release_performances(release) for perf in self._get_artist_performances(rel.get("artist-relation-list", [])): artistid, instrument, is_lead = perf self._add_release_performance(release.mbid, artistid, instrument, is_lead) external_data.import_release_image(release, directories, self.overwrite) self.imported_releases.append(releaseid) return release
def import_release(self, releaseid, directories): if releaseid in self.imported_releases: print "Release already updated in this import. Not doing it again" return self._ReleaseClass.objects.get(mbid=releaseid) rel = compmusic.mb.get_release_by_id(releaseid, includes=["artists", "recordings", "artist-rels", "release-groups"]) rel = rel["release"] mbid = rel["id"] logger.info("Adding release %s" % mbid) release = self._create_release_object(rel) # Create release primary artists release.artists.clear() for a in rel["artist-credit"]: if isinstance(a, dict): artistid = a["artist"]["id"] artist = self.add_and_get_release_artist(artistid) logger.info(" artist: %s" % artist) if not release.artists.filter(pk=artist.pk).exists(): logger.info(" - adding to artist list") release.artists.add(artist) recordings = [] for mnum, medium in enumerate(rel["medium-list"], 1): for tnum, track in enumerate(medium["track-list"], 1): recordings.append( (track["recording"]["id"], mnum, tnum)) release.recordings.clear() trackorder = 1 for recid, mnum, tnum in recordings: recob = self.add_and_get_recording(recid) self._link_release_recording(release, recob, trackorder, mnum, tnum) trackorder += 1 for perf in self._get_artist_performances(rel.get("artist-relation-list", [])): artistid, perf_type, attrs = perf self._add_release_performance(release.mbid, artistid, perf_type, attrs) self._add_release_artists_as_relationship(release, rel["artist-credit"]) external_data.import_release_image(release, directories) self.imported_releases.append(releaseid) return release
def _add_image_to_release(self, release, directories): external_data.import_release_image(release, directories)