Exemple #1
0
    def perform_create(self, serializer):
        super().perform_create(serializer)

        # save a watch tv season instance to try and download the whole season immediately
        watch_tv_season, _ = WatchTVSeason.objects.get_or_create(
            watch_tv_show=WatchTVShow.objects.get(
                id=serializer.data['watch_tv_show']),
            season_number=serializer.data['season_number'],
            defaults=dict(
                # add non-unique constraint fields for the default values
                user=self.request.user, ),
        )
        # send a websocket message for this new season
        media_type, data = websocket.get_media_type_and_serialized_watch_media(
            watch_tv_season)
        send_websocket_message_task.delay(websocket.ACTION_UPDATED, media_type,
                                          data)

        # delete any individual episodes (including in transmission) now that we're watching the entire season
        for episode in WatchTVEpisode.objects.filter(
                watch_tv_show=watch_tv_season.watch_tv_show,
                season_number=watch_tv_season.season_number):
            # send a websocket message for this removed episode
            media_type, data = websocket.get_media_type_and_serialized_watch_media(
                episode)
            send_websocket_message_task.delay(websocket.ACTION_REMOVED,
                                              media_type, data)
            # delete from transmission
            destroy_transmission_result(episode)
            # delete the episode
            episode.delete()

        # create a task to download the whole season (fallback to individual episodes if it fails)
        watch_tv_show_season_task.delay(watch_tv_season.id)
Exemple #2
0
    def perform_create(self, serializer):
        super().perform_create(serializer)

        # save a watch tv season instance to try and download the whole season immediately
        watch_tv_season, _ = WatchTVSeason.objects.get_or_create(
            watch_tv_show=WatchTVShow.objects.get(
                id=serializer.data['watch_tv_show']),
            season_number=serializer.data['season_number'],
            defaults=dict(
                # add non-unique constraint fields for the default values
                user=self.request.user, ),
        )

        # create a task to download the whole season (fallback to individual episodes if it fails)
        watch_tv_show_season_task.delay(watch_tv_season.id)

        return Response(serializer.data)
Exemple #3
0
    def watch_entire_season(self, request, pk):
        watch_tv_show = self.get_object()  # type: WatchTVShow
        data = request.query_params or request.data

        if 'season_number' not in data:
            raise ValidationError(
                {'season_number': ['This field is required']})

        watch_tv_season, was_created = WatchTVSeason.objects.get_or_create(
            user=request.user,
            watch_tv_show=watch_tv_show,
            season_number=data['season_number'],
        )

        if was_created:
            watch_tv_season.save()

        # create a task to download the whole season
        watch_tv_show_season_task.delay(watch_tv_season.id)

        return Response(WatchTVSeasonSerializer(watch_tv_season).data)
Exemple #4
0
 def _watch_media_task(self, watch_media_id: int):
     """
     blacklist & retry function to queue the new task
     """
     watch_tv_show_season_task.delay(watch_media_id)
Exemple #5
0
 def perform_create(self, serializer):
     super().perform_create(serializer)
     # create a task to download the episode
     watch_tv_show_season_task.delay(serializer.instance.id)
Exemple #6
0
 def _watch_media_task(self, watch_media_id: int):
     watch_tv_show_season_task.delay(watch_media_id)