Beispiel #1
0
        private async Task CreateMovieInRadarr(Movie movie)
        {
            var isAnime = false;

            try
            {
                var movieDbResponse = await TheMovieDb.GetMovieFromTheMovieDbAsync(_httpClientFactory.CreateClient(), movie.TheMovieDbId);

                await movieDbResponse.ThrowIfNotSuccessfulAsync("TheMovieDbFindMovie failed", x => x.status_message);

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

                var theMovieDbMovie = JsonConvert.DeserializeObject <TheMovieDbMovie>(jsonResponse);

                isAnime = theMovieDbMovie.IsAnime;
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex, $"An error occurred while requesting movie: " + ex.Message);
            }

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

            int[] tags = Array.Empty <int>();

            if (RadarrSettings.Version != "2")
            {
                tags = isAnime ? RadarrSettings.AnimeTags : RadarrSettings.MovieTags;
            }

            var response = await HttpPostAsync($"{BaseURL}/movie", JsonConvert.SerializeObject(new
            {
                title               = jsonMovie.title,
                qualityProfileId    = isAnime ? RadarrSettings.AnimeProfileId : RadarrSettings.MovieProfileId,
                titleSlug           = jsonMovie.titleSlug,
                monitored           = RadarrSettings.MonitorNewRequests,
                tags                = tags,
                images              = new string[0],
                tmdbId              = int.Parse(movie.TheMovieDbId),
                year                = jsonMovie.year,
                rootFolderPath      = isAnime ? RadarrSettings.AnimeRootFolder : RadarrSettings.MovieRootFolder,
                minimumAvailability = isAnime ? RadarrSettings.AnimeMinimumAvailability : RadarrSettings.MovieMinimumAvailability,
                addOptions          = new
                {
                    ignoreEpisodesWithFiles    = false,
                    ignoreEpisodesWithoutFiles = false,
                    searchForMovie             = RadarrSettings.SearchNewRequests
                }
            }));

            await response.ThrowIfNotSuccessfulAsync("RadarrMovieCreation failed", x => x.error);
        }
Beispiel #2
0
        private async Task CreateMovieInRadarr(Movie movie)
        {
            var response = await TheMovieDb.GetMovieFromTheMovieDbAsync(_httpClientFactory.CreateClient(), movie.TheMovieDbId);

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception(response.ReasonPhrase);
            }

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

            var theMovieDbMovie = JsonConvert.DeserializeObject <TheMovieDbMovie>(jsonResponse);

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

            int[] tags = Array.Empty <int>();

            if (RadarrSettings.Version != "2")
            {
                tags = theMovieDbMovie.IsAnime ? RadarrSettings.AnimeTags : RadarrSettings.MovieTags;
            }

            response = await HttpPostAsync($"{BaseURL}/movie", JsonConvert.SerializeObject(new
            {
                title               = jsonMovie.title,
                qualityProfileId    = theMovieDbMovie.IsAnime ? RadarrSettings.AnimeProfileId : RadarrSettings.MovieProfileId,
                titleSlug           = jsonMovie.titleSlug,
                monitored           = true,
                tags                = tags,
                images              = new string[0],
                tmdbId              = int.Parse(movie.TheMovieDbId),
                year                = jsonMovie.year,
                rootFolderPath      = theMovieDbMovie.IsAnime ? RadarrSettings.AnimeRootFolder : RadarrSettings.MovieRootFolder,
                minimumAvailability = theMovieDbMovie.IsAnime ? RadarrSettings.AnimeMinimumAvailability : RadarrSettings.MovieMinimumAvailability,
                addOptions          = new
                {
                    ignoreEpisodesWithFiles    = false,
                    ignoreEpisodesWithoutFiles = false,
                    searchForMovie             = true
                }
            }));

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception(response.ReasonPhrase);
            }
        }
Beispiel #3
0
        private async Task UpdateExistingMovie(Movie movie)
        {
            var isAnime       = false;
            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(movie);

                    return;
                }

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

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

            dynamic radarrMovie = JObject.Parse(jsonResponse);

            try
            {
                var movieDbResponse = await TheMovieDb.GetMovieFromTheMovieDbAsync(_httpClientFactory.CreateClient(), movie.TheMovieDbId);

                await movieDbResponse.ThrowIfNotSuccessfulAsync("TheMovieDbFindMovie failed", x => x.status_message);

                var movieDbJsonResponse = await movieDbResponse.Content.ReadAsStringAsync();

                var theMovieDbMovie = JsonConvert.DeserializeObject <TheMovieDbMovie>(movieDbJsonResponse);

                isAnime = theMovieDbMovie.IsAnime;
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex, $"An error occurred while requesting movie: " + ex.Message);
            }

            radarrMovie.profileId           = isAnime ? RadarrSettings.AnimeProfileId : RadarrSettings.MovieProfileId;
            radarrMovie.minimumAvailability = isAnime ? RadarrSettings.AnimeMinimumAvailability : RadarrSettings.MovieMinimumAvailability;
            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);
                }
            }
        }
Beispiel #4
0
        private async Task UpdateExistingMovie(Movie movie)
        {
            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(movie);

                    return;
                }

                throw new Exception(response.ReasonPhrase);
            }

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

            dynamic radarrMovie = JObject.Parse(jsonResponse);

            response = await TheMovieDb.GetMovieFromTheMovieDbAsync(_httpClientFactory.CreateClient(), movie.TheMovieDbId);

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception(response.ReasonPhrase);
            }

            jsonResponse = await response.Content.ReadAsStringAsync();

            var theMovieDbMovie = JsonConvert.DeserializeObject <TheMovieDbMovie>(jsonResponse);

            if (RadarrSettings.Version == "2")
            {
                radarrMovie.profileId = theMovieDbMovie.IsAnime ? RadarrSettings.AnimeProfileId : RadarrSettings.MovieProfileId;
            }
            else
            {
                radarrMovie.tags             = JToken.FromObject(theMovieDbMovie.IsAnime ? RadarrSettings.AnimeTags : RadarrSettings.MovieTags);
                radarrMovie.qualityProfileId = theMovieDbMovie.IsAnime ? RadarrSettings.AnimeProfileId : RadarrSettings.MovieProfileId;
            }

            radarrMovie.minimumAvailability = theMovieDbMovie.IsAnime ? RadarrSettings.AnimeMinimumAvailability : RadarrSettings.MovieMinimumAvailability;
            radarrMovie.monitored           = true;

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

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception(response.ReasonPhrase);
            }

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

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
            catch (System.Exception ex)
            {
                _logger.LogWarning($"An error while sending search command for movie \"{movie.Title}\" to Radarr: " + ex.Message);
            }
        }