Example #1
0
        private async Task UpdateExistingMovie(MovieRequest request, Movie movie)
        {
            RadarrCategory category = null;

            var radarrMovieId = int.Parse(movie.DownloadClientId);
            var response      = await HttpGetAsync($"{BaseURL}/movie/{radarrMovieId}");

            if (!response.IsSuccessStatusCode)
            {
                if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    await CreateMovieInRadarr(request, movie);

                    return;
                }

                await response.ThrowIfNotSuccessfulAsync("RadarrGetMovie failed", x => x.error);
            }

            var jsonResponse = await response.Content.ReadAsStringAsync();

            dynamic radarrMovie = JObject.Parse(jsonResponse);

            try
            {
                category = RadarrSettings.Categories.Single(x => x.Id == request.CategoryId);
            }
            catch
            {
                _logger.LogError($"An error occurred while requesting movie \"{movie.Title}\" from Radarr, could not find category with id {request.CategoryId}");
                throw new System.Exception($"An error occurred while requesting movie \"{movie.Title}\" from Radarr, could not find category with id {request.CategoryId}");
            }

            radarrMovie.profileId           = category.ProfileId;
            radarrMovie.minimumAvailability = category.MinimumAvailability;
            radarrMovie.monitored           = RadarrSettings.MonitorNewRequests;

            response = await HttpPutAsync($"{BaseURL}/movie/{radarrMovieId}", JsonConvert.SerializeObject(radarrMovie));

            await response.ThrowIfNotSuccessfulAsync("RadarrUpdateMovie failed", x => x.error);

            if (RadarrSettings.SearchNewRequests)
            {
                try
                {
                    response = await HttpPostAsync($"{BaseURL}/command", JsonConvert.SerializeObject(new
                    {
                        name     = "moviesSearch",
                        movieIds = new[] { radarrMovieId },
                    }));

                    await response.ThrowIfNotSuccessfulAsync("RadarrMovieSearchCommand failed", x => x.error);
                }
                catch (System.Exception ex)
                {
                    _logger.LogError(ex, $"An error while sending search command for movie \"{movie.Title}\" to Radarr: " + ex.Message);
                    throw;
                }
            }
        }
Example #2
0
        private async Task CreateMovieInRadarr(MovieRequest request, Movie movie)
        {
            RadarrCategory category = null;

            try
            {
                category = RadarrSettings.Categories.Single(x => x.Id == request.CategoryId);
            }
            catch
            {
                _logger.LogError($"An error occurred while requesting movie \"{movie.Title}\" from Radarr, could not find category with id {request.CategoryId}");
                throw new System.Exception($"An error occurred while requesting movie \"{movie.Title}\" from Radarr, could not find category with id {request.CategoryId}");
            }

            var jsonMovie = await SearchMovieByMovieDbId(int.Parse(movie.TheMovieDbId));

            var response = await HttpPostAsync($"{BaseURL}/movie", JsonConvert.SerializeObject(new
            {
                title               = jsonMovie.title,
                qualityProfileId    = category.ProfileId,
                titleSlug           = jsonMovie.titleSlug,
                monitored           = RadarrSettings.MonitorNewRequests,
                tags                = JToken.FromObject(category.Tags),
                images              = new string[0],
                tmdbId              = int.Parse(movie.TheMovieDbId),
                year                = jsonMovie.year,
                rootFolderPath      = category.RootFolder,
                minimumAvailability = category.MinimumAvailability,
                addOptions          = new
                {
                    ignoreEpisodesWithFiles    = false,
                    ignoreEpisodesWithoutFiles = false,
                    searchForMovie             = RadarrSettings.SearchNewRequests
                }
            }));

            await response.ThrowIfNotSuccessfulAsync("RadarrMovieCreation failed", x => x.error);
        }