def _add_recording_performance(self, recordingid, artistid, perf_type, attrs):
        logger.info("  Adding recording performance...")
        artist = self.add_and_get_artist(artistid)

        # We don't expect to see these two relations here, as we know that all releases in MusicBrainz
        # for this collection have recording-level relationships.
        if perf_type in [release_importer.RELATION_RELEASE_VOCAL, release_importer.RELATION_RELEASE_INSTRUMENT]:
            raise release_importer.ImportFailedException("Found a release-level artist instrument relation on "
                                                         "recording {} which isn't supported".format(recordingid))

        is_lead = False
        instr_name = attrs[-1]
        if perf_type == release_importer.RELATION_RECORDING_VOCAL:
            instr_name = "voice"
            if "lead vocals" in attrs:
                is_lead = True
        elif perf_type == release_importer.RELATION_RECORDING_INSTRUMENT:
            instr_name = attrs[-1]
            attrs = attrs[:-1]
            if "lead" in attrs:
                is_lead = True

        instrument = self._get_instrument(instr_name)
        if instrument:
            recording = andalusian.models.Recording.objects.get(mbid=recordingid)
            perf = andalusian.models.InstrumentPerformance(recording=recording, instrument=instrument, performer=artist, lead=is_lead)
            perf.save()
 def _get_instrument(self, instname):
     if not instname:
         return None
     instname = instname.lower()
     try:
         return andalusian.models.Instrument.objects.get(name__iexact=instname)
     except andalusian.models.Instrument.DoesNotExist:
         raise release_importer.ImportFailedException("Instrument {} not found".format(instname))
Beispiel #3
0
    def _apply_tags(self, recording, works, tags):
        recording.forms.clear()
        recording.raagas.clear()
        recording.taalas.clear()

        # Check that there is not more than one form
        noform = False
        forms = recording.forms.all()
        if len(forms) > 1:
            raise release_importer.ImportFailedException(
                'TODO: Support more than one form per recording')
        elif len(forms) < 1:
            form = self._get_form_tag(tags)
            if form:
                # TODO: If there is more than one form, set sequence properly
                carnatic.models.RecordingForm.objects.create(
                    recording=recording, form=form, sequence=1)
            else:
                # If we have no form, we import anyway and put the tags on the recording
                noform = True
        else:
            form = forms[0]

        # If we are missing a work, or if the work is missing raaga & taala, we should
        # add the information to the recording from the tag
        nowork = False
        if len(works) == 0:
            nowork = True
        for w in works:
            if not w.raaga or not w.taala:
                nowork = True
                break

        if noform or form.attrfromrecording or nowork:
            # Create the relation with Raaga and Taala

            raaga_tag = self._get_raaga_tags(tags)
            taala_tag = self._get_taala_tags(tags)

            if raaga_tag:
                r = self._get_raaga(raaga_tag)
                if r:
                    carnatic.models.RecordingRaaga.objects.create(
                        recording=recording, raaga=r, sequence=1)

            if taala_tag:
                t = self._get_taala(taala_tag)
                if t:
                    carnatic.models.RecordingTaala.objects.create(
                        recording=recording, taala=t, sequence=1)
        elif not form.attrfromrecording:
            # In this case, we read attributes from the work. If the work has no attributes
            # we should add these tags to the recording anyway.
            pass