Пример #1
0
 def add_contribution(self, song, entity, performed=False, texted=False,
                      translated=False, composed=False):
     contribution = EntityContribution()
     contribution.song = song
     contribution.entity = entity
     contribution.performed = performed
     contribution.texted = texted
     contribution.translated = translated
     contribution.composed = composed
     contribution.save()
Пример #2
0
    def handle(self, *args, **options):
        youtube = build(
            YOUTUBE_API_SERVICE_NAME,
            YOUTUBE_API_VERSION,
            developerKey=settings.GOOGLE_API_SERVER_KEY)

        count_all = 0
        count_none = 0
        count_incorrect = 0
        for song in Song.objects.all():
            print(str(song))
            count_all += 1
            if not song.youtube_id():
                print(' - no link')
                count_none += 1
            else:
                id = song.youtube_id()
                response = youtube.videos().list(
                    part='id,snippet', id=id).execute()
                if not response['items']:
                    print(' - incorrect link, deleting')
                    count_incorrect += 1
                    song.link_youtube = None
                    song.save()

            if song.youtube_id():
                print(' - OK')
                continue

            # The link is missing - try to find a new one.
            head_contribution = EntityContribution.head_contribution(
                EntityContribution.objects.filter(song=song.id))
            query = str(song) + ' ' + str(head_contribution.artist)
            print(' - would look for: ' + query)
            candidates = youtube.search().list(
                maxResults=1, part='id,snippet', q=query).execute()
            if not candidates['items']:
                print(' - no results :(')
            else:
                candidate = candidates['items'][0]
                title = candidate['snippet']['title']
                channelTitle = candidate['snippet']['channelTitle']
                print(' - top: ' + title + ' (' + channelTitle + ')')
                print('   does it look good? (y/n)')
                answer = input()
                if answer == 'y' or answer == 'yes':
                    song.set_youtube_id(candidate['id']['videoId'])
                    song.save()
                    print(' - set!')

        print('all songs: ' + str(count_all))
        print('no link: ' + str(count_none))
        print('invalid link (fixed): ' + str(count_incorrect))
Пример #3
0
    def post(self, request, *args, **kwargs):
        form = self.get_form()
        formset = self.formset

        # This updates |instance| fields in the formset with parsed objects.
        if not formset.is_valid():
            return self.form_invalid(form)

        # Pick head contribution to put into the slug.
        head = EntityContribution.head_contribution(
            [x.instance for x in self.formset])
        assert head
        form.set_artist_for_slug(head.artist.__str__())

        if form.is_valid():
            return self.form_valid(form)
        else:
            return self.form_invalid(form)
Пример #4
0
    def setUp(self):
        author = testing.create_user()
        song = Song.create_for_testing(author)
        entity = Entity.create_for_testing()
        contribution = EntityContribution()
        contribution.song = song
        contribution.entity = entity
        contribution.texted = True
        contribution.save()

        song.old_slug = "some-old-slug"
        song.reviewed = True
        song.save()

        self.song = song
        self.entity = entity
Пример #5
0
    def handle(self, *args, **options):
        print("Creating entities for Artists.")
        for artist in Artist.objects.all():
            if not artist.entity:
                entity = Entity()
                entity.name = artist.lastname
                entity.first_name = artist.firstname
                entity.slug = artist.slug
                entity.featured = artist.display
                entity.kind = artist.kind
                entity.website = artist.website
                entity.is_band = False
                entity.save()

                artist.entity = entity
                artist.save()
                print("Created entity: " + str(entity))
            else:
                print(str(artist) + " already has an Entity.")

        print("Creating entities for Bands.")
        for band in Band.objects.all():
            if not band.entity:
                entity = Entity()
                entity.name = band.name
                entity.slug = band.slug
                entity.featured = band.display
                entity.website = band.website
                entity.is_band = True
                entity.kind = Entity.TYPE_BAND
                entity.save()

                band.entity = entity
                band.save()
                print("Created entity: " + str(entity))
            else:
                print(str(band) + " already has an Entity.")

        print("Converting ArtistContributions.")
        for artist_contribution in ArtistContribution.objects.all():
            if not artist_contribution.entity_contribution:
                entity_contribution = EntityContribution()
                entity_contribution.song = artist_contribution.song
                entity_contribution.entity = artist_contribution.artist.entity
                entity_contribution.performed = artist_contribution.performed
                entity_contribution.texted = artist_contribution.texted
                entity_contribution.translated = artist_contribution.translated
                entity_contribution.composed = artist_contribution.composed
                entity_contribution.save()

                artist_contribution.entity_contribution = entity_contribution
                artist_contribution.save()
                print("Created entity cont.: " + str(entity_contribution))
            else:
                print(str(artist_contribution) + " already has an Entity.")

        print("Converting BandContributions.")
        for band_contribution in BandContribution.objects.all():
            if not band_contribution.entity_contribution:
                entity_contribution = EntityContribution()
                entity_contribution.song = band_contribution.song
                entity_contribution.entity = band_contribution.band.entity
                entity_contribution.performed = band_contribution.performed
                entity_contribution.texted = False
                entity_contribution.translated = False
                entity_contribution.composed = False
                entity_contribution.save()

                band_contribution.entity_contribution = entity_contribution
                band_contribution.save()
                print("Created entity cont.: " + str(entity_contribution))
            else:
                print(str(band_contribution) + " already has an Entity.")

        print("Converting artist performances.")
        for event in Event.objects.all():
            for artist in event.artists.all():
                entity_performance = EntityPerformance()
                entity_performance.event = event
                entity_performance.entity = artist.entity
                entity_performance.save()

                artist.entity.still_plays = True
                artist.entity.save()
                print("Added entity " + str(entity_performance.entity) + " on event " + str(event))

            for band in event.bands.all():
                entity_performance = EntityPerformance()
                entity_performance.event = event
                entity_performance.entity = band.entity
                entity_performance.save()

                band.entity.still_plays = True
                band.entity.save()
                print("Added entity " + str(entity_performance.entity) + " on event " + str(event))