예제 #1
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);
            }
        }
예제 #2
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);
            }
        }
예제 #3
0
 public Task <MovieDetails> GetMovieDetails(string theMovieDbId)
 {
     return(TheMovieDb.GetMovieDetailsAsync(_httpClientFactory.CreateClient(), theMovieDbId));
 }