Пример #1
0
    def _create_artist_object(self,
                              ArtistKlass,
                              AliasKlass,
                              mbartist,
                              alias_ref="artist"):
        artistid = mbartist["id"]

        artist, created = ArtistKlass.objects.get_or_create(
            mbid=artistid, defaults={"name": mbartist["name"]})

        logger.info("  adding artist/composer %s" % (artistid, ))
        source = self.make_mb_source("http://musicbrainz.org/artist/%s" %
                                     artistid)
        artist.source = source
        artist.name = mbartist["name"]
        if mbartist.get("type") == "Person":
            artist.artist_type = "P"
        elif mbartist.get("type") == "Group":
            artist.artist_type = "G"
        if mbartist.get("gender") == "Male":
            artist.gender = "M"
        elif mbartist.get("gender") == "Female":
            artist.gender = "F"
        dates = mbartist.get("life-span")
        if dates:
            artist.begin = dates.get("begin")
            artist.end = dates.get("end")
        artist.save()

        # add wikipedia references if they exist
        artist.references.clear()
        for rel in mbartist.get("url-relation-list", []):
            if rel["type-id"] == RELEASE_TYPE_WIKIPEDIA:
                source = self.make_wikipedia_source(rel["target"])
                if not artist.references.filter(pk=source.pk).exists():
                    artist.references.add(source)

        # We can't 'clear' an alias list from artist because an alias
        # object requires an artist.
        # TODO Deleting these each time we overwrite means we churn the
        # alias ids. This may or may not be a good idea
        args = {}
        args[alias_ref] = artist
        AliasKlass.objects.filter(**args).delete()
        for alias in mbartist.get("alias-list", []):
            a = alias["alias"]
            primary = alias.get("primary")
            locale = alias.get("locale")
            args = {"alias": a}
            args[alias_ref] = artist
            aob, created = AliasKlass.objects.get_or_create(**args)
            if primary:
                aob.primary = True
            if locale:
                aob.locale = locale
            aob.save()

        external_data.import_artist_wikipedia(artist)
        return artist
Пример #2
0
    def _create_artist_object(self, ArtistKlass, AliasKlass, mbartist, alias_ref="artist"):
        artistid = mbartist["id"]

        artist, created = ArtistKlass.objects.get_or_create(
            mbid=artistid,
            defaults={"name": mbartist["name"]})

        if created or self.overwrite:
            logger.info("  adding artist/composer %s" % (artistid, ))
            source = self.make_mb_source("http://musicbrainz.org/artist/%s" % artistid)
            artist.source = source
            artist.name = mbartist["name"]
            if mbartist.get("type") == "Person":
                artist.artist_type = "P"
            elif mbartist.get("type") == "Group":
                artist.artist_type = "G"
            if mbartist.get("gender") == "Male":
                artist.gender = "M"
            elif mbartist.get("gender") == "Female":
                artist.gender = "F"
            dates = mbartist.get("life-span")
            if dates:
                artist.begin = dates.get("begin")
                artist.end = dates.get("end")
            artist.save()

            # add wikipedia references if they exist
            if self.overwrite:
                artist.references.clear()
            for rel in mbartist.get("url-relation-list", []):
                if rel["type-id"] == RELEASE_TYPE_WIKIPEDIA:
                    source = self.make_wikipedia_source(rel["target"])
                    if not artist.references.filter(pk=source.pk).exists():
                        artist.references.add(source)

            if self.overwrite:
                # We can't 'clear' an alias list from artist because an alias
                # object requires an artist.
                # TODO Deleting these each time we overwrite means we churn the
                # alias ids. This may or may not be a good idea
                args = {}
                args[alias_ref] = artist
                AliasKlass.objects.filter(**args).delete()
            for alias in mbartist.get("alias-list", []):
                a = alias["alias"]
                primary = alias.get("primary")
                locale = alias.get("locale")
                args = {"alias": a}
                args[alias_ref] = artist
                aob, created = AliasKlass.objects.get_or_create(**args)
                if primary:
                    aob.primary = True
                if locale:
                    aob.locale = locale
                aob.save()

            external_data.import_artist_wikipedia(artist, self.overwrite)
        return artist