Exemple #1
0
    def entity_create(title, year):
        # TODO: Support creating multiple movies
        l_movie = MovieEntityGenerator.entity_lookup(title, year)
        if len(l_movie) == 1:
            l_movie = l_movie[0]
        else:
            return None

        if "release_date" not in l_movie:
            print "'release'_date not found"
            return None

        date = l_movie["release_date"].split("-")
        if len(date) != 3 or len(date[0]) != 4:
            print "'release_date' unexpected value"
            return None

        year = None
        try:
            year = int(date[0])
        except ValueError:
            print "'release_date' unexpected value"
            return None

        _, e_movie, e_movie_created = EntityGenerator.db_create_entity(
            l_movie["id"], EntityReference.TYPE_THEMOVIEDB, Entity.TYPE_MOVIE, title=l_movie["title"], year=year
        )
        if e_movie_created:
            print "Movie Created"

            for company in l_movie["production_companies"]:
                e_company = MovieEntityGenerator._create_company_recipient(company)
                e_movie.recipient.add(e_company)

        return e_movie
Exemple #2
0
    def entity_create(artist, album=None, track=None):
        l_artist, l_releases, l_recording = \
            MusicEntityGenerator.entity_lookup(artist, album, track)

        #
        # Create Artist Recipient
        #
        _, recipient, _ = EntityGenerator.db_create_recipient(
            l_artist['id'], l_artist['name'],
            RecipientReference.TYPE_MUSICBRAINZ,
            Recipient.TYPE_MUSIC_ARTIST
        )

        #
        # Create Artist Entity
        #
        _, e_artist, e_artist_created = \
            EntityGenerator.db_create_entity(
                l_artist['id'],
                EntityReference.TYPE_MUSICBRAINZ, Entity.TYPE_MUSIC,
                artist=l_artist['name']
            )
        if e_artist_created:
            print "Artist Created"
            e_artist.recipient.add(recipient)

        #
        # Create Album Entity
        #
        e_album = None
        if l_releases:
            _, e_album, e_album_created = \
                EntityGenerator.db_create_entity(
                    l_releases[0][0]['id'],
                    EntityReference.TYPE_MUSICBRAINZ, Entity.TYPE_MUSIC,
                    artist=l_artist['name'],
                    album=l_releases[0][0]['title'],
                    parent=e_artist
                )
            if e_album_created:
                print "Album Created"
                e_album.recipient.add(recipient)

        #
        # Create Track Entity
        #
        e_track = None
        if l_recording:
            _, e_track, e_track_created = \
                EntityGenerator.db_create_entity(
                    l_recording['id'],
                    EntityReference.TYPE_MUSICBRAINZ, Entity.TYPE_MUSIC,
                    artist=l_artist['name'],
                    album=l_releases[0][0]['title'],
                    track=l_recording['title'],
                    parent=e_album
                )
            if e_track_created:
                print "Track Created"
                e_track.recipient.add(recipient)

        #
        # Return Entity
        #
        if e_track:
            return e_track
        elif e_album:
            return e_album
        elif e_artist:
            return e_artist
        return None