Exemple #1
0
    def get(self, request):
        nefarious_settings = NefariousSettings.get()
        transmission_client = get_transmission_client(nefarious_settings)

        watch_movies = request.query_params.getlist('watch_movies', [])
        watch_tv_shows = request.query_params.getlist('watch_tv_shows', [])

        results = []
        querysets = []

        # movies
        if watch_movies:
            querysets.append(WatchMovie.objects.filter(id__in=watch_movies))
        # tv shows
        if watch_tv_shows:
            querysets.append(
                WatchTVEpisode.objects.filter(
                    watch_tv_show__id__in=watch_tv_shows))
            querysets.append(
                WatchTVSeason.objects.filter(
                    watch_tv_show__id__in=watch_tv_shows))

        for qs in querysets:

            for media in qs:

                if isinstance(media, WatchTVSeason):
                    media_serializer = WatchTVSeasonSerializer
                elif isinstance(media, WatchTVEpisode):
                    media_serializer = WatchTVEpisodeSerializer
                else:
                    media_serializer = WatchMovieSerializer

                result = {
                    'watchMedia': media_serializer(media).data,
                }

                if media.transmission_torrent_hash:

                    try:
                        torrent = transmission_client.get_torrent(
                            media.transmission_torrent_hash)
                    except (KeyError, ValueError
                            ):  # torrent no longer exists or was invalid
                        pass
                    except Exception as e:
                        logger_foreground.error(str(e))
                        raise e
                    else:
                        result['torrent'] = TransmissionTorrentSerializer(
                            torrent).data

                results.append(result)

        return Response(results)
Exemple #2
0
 def post(self, request, media_type):
     if not settings.HOST_DOWNLOAD_PATH:
         raise exceptions.APIException('HOST_DOWNLOAD_PATH is not defined')
     try:
         # create task to import library
         import_library_task.delay(media_type, request.user.id)
     except AlreadyQueued as e:
         logger_foreground.exception(e)
         msg = 'Import task for {} already exists'.format(media_type)
         logger_foreground.error(msg)
         raise exceptions.APIException(msg)
     return Response({'success': True})