Beispiel #1
0
    def perform_destroy(self, watch_tv_show: WatchTVShow):
        # delete all seasons, season requests, episodes and remove from transmission

        # delete season requests
        WatchTVSeasonRequest.objects.filter(
            watch_tv_show=watch_tv_show).delete()

        # delete instance and from transmission and send websocket messages
        queries = [
            WatchTVSeason.objects.filter(watch_tv_show=watch_tv_show),
            WatchTVEpisode.objects.filter(watch_tv_show=watch_tv_show)
        ]
        for qs in queries:
            for media in qs:
                # send a websocket message that this media was removed
                media_type, data = websocket.get_media_type_and_serialized_watch_media(
                    media)
                send_websocket_message_task.delay(websocket.ACTION_REMOVED,
                                                  media_type, data)
                # delete from transmission
                destroy_transmission_result(media)
                # delete the media
                media.delete()

        return super().perform_destroy(watch_tv_show)
Beispiel #2
0
 def perform_destroy(self, instance):
     # send websocket message first then remove
     media_type, data = websocket.get_media_type_and_serialized_watch_media(
         instance)
     send_websocket_message_task.delay(websocket.ACTION_REMOVED, media_type,
                                       data)
     super().perform_destroy(instance)
Beispiel #3
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)
Beispiel #4
0
 def perform_create(self, serializer):
     # create instance first then send websocket message
     super().perform_create(serializer)
     # send websocket message media was updated
     media_type, data = websocket.get_media_type_and_serialized_watch_media(
         serializer.instance)
     send_websocket_message_task.delay(websocket.ACTION_UPDATED, media_type,
                                       data)
Beispiel #5
0
 def perform_destroy(self, watch_tv_season_request: WatchTVSeasonRequest):
     # destroy watch tv season instances as well, including any related torrents in transmission
     query_args = dict(
         watch_tv_show=watch_tv_season_request.watch_tv_show,
         season_number=watch_tv_season_request.season_number,
     )
     for season in WatchTVSeason.objects.filter(**query_args):
         # send a websocket message that this season was removed
         media_type, data = websocket.get_media_type_and_serialized_watch_media(
             season)
         send_websocket_message_task.delay(websocket.ACTION_REMOVED,
                                           media_type, data)
         # delete from transmission
         destroy_transmission_result(season)
         # delete the season
         season.delete()
     return super().perform_destroy(watch_tv_season_request)