Beispiel #1
0
    def add_and_get_work(self, workid):
        mbwork = compmusic.mb.get_work_by_id(workid,
                                             includes=["artist-rels"])["work"]
        import_logger.info("adding work %s", mbwork["title"])
        work, created = self._WorkClass.objects.get_or_create(
            mbid=workid, defaults={"title": mbwork["title"]})

        source = self.make_mb_source("http://musicbrainz.org/work/%s" % workid)
        work.source = source
        work.title = mbwork["title"]
        work.save()

        self._clear_work_composers(work)
        self._add_work_attributes(work, mbwork, created)

        for artist in mbwork.get("artist-relation-list", []):
            if artist["type-id"] == RELATION_COMPOSER:
                composer = self.add_and_get_composer(artist["target"])
                if not work.composers.filter(pk=composer.pk).exists():
                    work.composers.add(composer)
            elif artist["type-id"] == RELATION_LYRICIST:
                lyricist = self.add_and_get_composer(artist["target"])
                if not work.lyricists.filter(pk=lyricist.pk).exists():
                    work.lyricists.add(lyricist)

        return work
Beispiel #2
0
    def add_and_get_recording(self, recordingid):
        mbrec = compmusic.mb.get_recording_by_id(
            recordingid,
            includes=["tags", "work-rels", "artist-rels", "artists"])
        mbrec = mbrec["recording"]

        rec, created = self._RecordingClass.objects.get_or_create(
            mbid=recordingid)
        logger.info("  adding recording %s" % (recordingid, ))
        import_logger.info("importing recording %s", mbrec["title"])
        source = self.make_mb_source("http://musicbrainz.org/recording/%s" %
                                     recordingid)
        rec.source = source
        rec.length = mbrec.get("length")
        rec.title = mbrec["title"]
        rec.save()

        artistids = []
        # Create recording primary artists
        for a in mbrec.get("artist-credit", []):
            if isinstance(a, dict):
                artistid = a["artist"]["id"]
                artistids.append(artistid)
        self._add_recording_artists(rec, artistids)

        works = []
        for work in mbrec.get("work-relation-list", []):
            if work["type"] == "performance":
                w = self.add_and_get_work(work["target"])
                works.append(w)

        tags = mbrec.get("tag-list", [])
        # Join recording and works in a subclass because some models
        # have 1 work per recording and others have many
        self._join_recording_and_works(rec, works)

        # Sometime we attach tags to works, sometimes to recordings
        self._apply_tags(rec, works, tags)

        IPClass = rec.get_object_map("performance")
        IPClass.objects.filter(recording=rec).delete()
        for perf in self._get_artist_performances(
                mbrec.get("artist-relation-list", [])):
            artistid, perf_type, attrs = perf
            self._add_recording_performance(recordingid, artistid, perf_type,
                                            attrs)

        return rec
Beispiel #3
0
    def _apply_tags(self, recording, work, tags):
        raags = self._get_raag_tags(tags)
        taals = self._get_taal_tags(tags)
        layas = self._get_laya_tags(tags)
        forms = self._get_form_tags(tags)

        hindustani.models.RecordingTaal.objects.filter(recording=recording).delete()
        hindustani.models.RecordingLaya.objects.filter(recording=recording).delete()
        hindustani.models.RecordingRaag.objects.filter(recording=recording).delete()
        hindustani.models.RecordingForm.objects.filter(recording=recording).delete()

        if not layas:
            import_logger.warning("No laya tags found on recording")
        for l in layas:
            import_logger.info("Found laya tag %s", l)
            lpos = l[0]
            lob = self._get_laya(l[1])
            if lob:
                hindustani.models.RecordingLaya.objects.create(recording=recording, laya=lob, sequence=lpos)
            else:
                print "couldn't find a laya", l

        if not taals:
            import_logger.warning("No taal tags found on recording")
        for t in taals:
            import_logger.info("Found taal tag %s", t)
            tpos = t[0]
            tob = self._get_taal(t[1])
            if tob:
                hindustani.models.RecordingTaal.objects.create(recording=recording, taal=tob, sequence=tpos)
            else:
                print "couldn't find a taal", t

        if not raags:
            import_logger.warning("No raag tags found on recording")
        for r in raags:
            import_logger.info("Found raag tag %s", r)
            rpos = r[0]
            rob = self._get_raag(r[1])
            if rob:
                hindustani.models.RecordingRaag.objects.create(recording=recording, raag=rob, sequence=rpos)
            else:
                print "could't find a raag", r

        if not forms:
            import_logger.warning("No form tags found on recording")
        for f in forms:
            import_logger.info("Found form tag %s", f)
            fpos = f[0]
            fob = self._get_form(f[1])
            if fob:
                hindustani.models.RecordingForm.objects.create(recording=recording, form=fob, sequence=fpos)
            else:
                print "couldn't find a form", f
Beispiel #4
0
    def add_and_get_recording(self, recordingid):
        mbrec = compmusic.mb.get_recording_by_id(recordingid, includes=["tags", "work-rels", "artist-rels", "artists"])
        mbrec = mbrec["recording"]

        rec, created = self._RecordingClass.objects.get_or_create(mbid=recordingid)
        logger.info("  adding recording %s" % (recordingid,))
        import_logger.info("importing recording %s", mbrec["title"])
        rec.length = mbrec.get("length")
        rec.title = mbrec["title"]
        rec.save()

        artistids = []
        # Create recording primary artists
        for a in mbrec.get("artist-credit", []):
            if isinstance(a, dict):
                artistid = a["artist"]["id"]
                artistids.append(artistid)
        self._add_recording_artists(rec, artistids)

        works = []
        for work in mbrec.get("work-relation-list", []):
            if work["type"] == "performance":
                w = self.add_and_get_work(work["target"])
                works.append(w)

        tags = mbrec.get("tag-list", [])
        # Join recording and works in a subclass because some models
        # have 1 work per recording and others have many
        self._join_recording_and_works(rec, works)

        # Sometime we attach tags to works, sometimes to recordings
        self._apply_tags(rec, works, tags)

        IPClass = rec.get_object_map("performance")
        IPClass.objects.filter(recording=rec).delete()
        for perf in self._get_artist_performances(mbrec.get("artist-relation-list", [])):
            artistid, perf_type, attrs = perf
            self._add_recording_performance(recordingid, artistid, perf_type, attrs)

        return rec
Beispiel #5
0
    def add_and_get_work(self, workid):
        mbwork = compmusic.mb.get_work_by_id(workid, includes=["artist-rels"])["work"]
        import_logger.info("adding work %s", mbwork["title"])
        work, created = self._WorkClass.objects.get_or_create(
            mbid=workid,
            defaults={"title": mbwork["title"]})

        work.title = mbwork["title"]
        work.save()

        self._clear_work_composers(work)
        self._add_work_attributes(work, mbwork, created)

        for artist in mbwork.get("artist-relation-list", []):
            if artist["type-id"] == RELATION_COMPOSER:
                composer = self.add_and_get_composer(artist["target"])
                if not work.composers.filter(pk=composer.pk).exists():
                    work.composers.add(composer)
            elif artist["type-id"] == RELATION_LYRICIST:
                lyricist = self.add_and_get_composer(artist["target"])
                if not work.lyricists.filter(pk=lyricist.pk).exists():
                    work.lyricists.add(lyricist)

        return work