Exemple #1
0
        private SonarrIndexer BuildSonarrIndexer(IndexerDefinition indexer, DownloadProtocol protocol, int id = 0)
        {
            var cacheKey = $"{Settings.BaseUrl}";
            var schemas  = _schemaCache.Get(cacheKey, () => _sonarrV3Proxy.GetIndexerSchema(Settings), TimeSpan.FromDays(7));

            var newznab = schemas.Where(i => i.Implementation == "Newznab").First();
            var torznab = schemas.Where(i => i.Implementation == "Torznab").First();

            var schema = protocol == DownloadProtocol.Usenet ? newznab : torznab;

            var sonarrIndexer = new SonarrIndexer
            {
                Id                      = id,
                Name                    = $"{indexer.Name} (Prowlarr)",
                EnableRss               = indexer.Enable && indexer.AppProfile.Value.EnableRss,
                EnableAutomaticSearch   = indexer.Enable && indexer.AppProfile.Value.EnableAutomaticSearch,
                EnableInteractiveSearch = indexer.Enable && indexer.AppProfile.Value.EnableInteractiveSearch,
                Priority                = indexer.Priority,
                Implementation          = indexer.Protocol == DownloadProtocol.Usenet ? "Newznab" : "Torznab",
                ConfigContract          = schema.ConfigContract,
                Fields                  = schema.Fields,
            };

            sonarrIndexer.Fields.FirstOrDefault(x => x.Name == "baseUrl").Value         = $"{Settings.ProwlarrUrl.TrimEnd('/')}/{indexer.Id}/";
            sonarrIndexer.Fields.FirstOrDefault(x => x.Name == "apiPath").Value         = "/api";
            sonarrIndexer.Fields.FirstOrDefault(x => x.Name == "apiKey").Value          = _configFileProvider.ApiKey;
            sonarrIndexer.Fields.FirstOrDefault(x => x.Name == "categories").Value      = JArray.FromObject(indexer.Capabilities.Categories.SupportedCategories(Settings.SyncCategories.ToArray()));
            sonarrIndexer.Fields.FirstOrDefault(x => x.Name == "animeCategories").Value = JArray.FromObject(indexer.Capabilities.Categories.SupportedCategories(Settings.AnimeSyncCategories.ToArray()));

            return(sonarrIndexer);
        }
Exemple #2
0
        public ValidationFailure TestConnection(SonarrIndexer indexer, SonarrSettings settings)
        {
            var request = BuildRequest(settings, $"/api/v3/indexer/test", HttpMethod.Post);

            request.SetContent(indexer.ToJson());

            try
            {
                Execute <SonarrIndexer>(request);
            }
            catch (HttpException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    _logger.Error(ex, "API Key is invalid");
                    return(new ValidationFailure("ApiKey", "API Key is invalid"));
                }

                if (ex.Response.StatusCode == HttpStatusCode.BadRequest)
                {
                    _logger.Error(ex, "Prowlarr URL is invalid");
                    return(new ValidationFailure("ProwlarrUrl", "Prowlarr url is invalid, Sonarr cannot connect to Prowlarr"));
                }

                _logger.Error(ex, "Unable to send test message");
                return(new ValidationFailure("BaseUrl", "Unable to complete application test"));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Unable to send test message");
                return(new ValidationFailure("", "Unable to send test message"));
            }

            return(null);
        }
Exemple #3
0
        public SonarrIndexer UpdateIndexer(SonarrIndexer indexer, SonarrSettings settings)
        {
            var request = BuildRequest(settings, $"/api/v3/indexer/{indexer.Id}", HttpMethod.Put);

            request.SetContent(indexer.ToJson());

            return(Execute <SonarrIndexer>(request));
        }
Exemple #4
0
        public SonarrIndexer AddIndexer(SonarrIndexer indexer, SonarrSettings settings)
        {
            var request = BuildRequest(settings, "/api/v3/indexer", HttpMethod.Post);

            request.SetContent(indexer.ToJson());

            return(Execute <SonarrIndexer>(request));
        }
        public ValidationFailure TestConnection(SonarrIndexer indexer, SonarrSettings settings)
        {
            var request = BuildRequest(settings, $"/api/v3/indexer/test", HttpMethod.Post);

            request.SetContent(indexer.ToJson());

            try
            {
                Execute <SonarrIndexer>(request);
            }
            catch (HttpException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    _logger.Error(ex, "API Key is invalid");
                    return(new ValidationFailure("ApiKey", "API Key is invalid"));
                }

                if (ex.Response.StatusCode == HttpStatusCode.BadRequest)
                {
                    _logger.Error(ex, "Prowlarr URL is invalid");
                    return(new ValidationFailure("ProwlarrUrl", "Prowlarr url is invalid, Sonarr cannot connect to Prowlarr"));
                }

                if (ex.Response.StatusCode == HttpStatusCode.SeeOther)
                {
                    _logger.Error(ex, "Sonarr returned redirect and is invalid");
                    return(new ValidationFailure("BaseUrl", "Sonarr url is invalid, Prowlarr cannot connect to Sonarr - are you missing a url base?"));
                }

                if (ex.Response.StatusCode == HttpStatusCode.NotFound)
                {
                    _logger.Error(ex, "Sonarr not found");
                    return(new ValidationFailure("BaseUrl", "Sonarr url is invalid, Prowlarr cannot connect to Sonarr. Is Sonarr running and accessible? Sonarr v2 is not supported."));
                }

                _logger.Error(ex, "Unable to send test message");
                return(new ValidationFailure("BaseUrl", "Unable to complete application test"));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Unable to send test message");
                return(new ValidationFailure("", "Unable to send test message"));
            }

            return(null);
        }
Exemple #6
0
        public bool Equals(SonarrIndexer other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            var baseUrl   = (string)Fields.FirstOrDefault(x => x.Name == "baseUrl").Value == (string)other.Fields.FirstOrDefault(x => x.Name == "baseUrl").Value;
            var apiPath   = (string)Fields.FirstOrDefault(x => x.Name == "apiPath").Value == (string)other.Fields.FirstOrDefault(x => x.Name == "apiPath").Value;
            var apiKey    = (string)Fields.FirstOrDefault(x => x.Name == "apiKey").Value == (string)other.Fields.FirstOrDefault(x => x.Name == "apiKey").Value;
            var cats      = JToken.DeepEquals((JArray)Fields.FirstOrDefault(x => x.Name == "categories").Value, (JArray)other.Fields.FirstOrDefault(x => x.Name == "categories").Value);
            var animeCats = JToken.DeepEquals((JArray)Fields.FirstOrDefault(x => x.Name == "animeCategories").Value, (JArray)other.Fields.FirstOrDefault(x => x.Name == "animeCategories").Value);

            return(other.EnableRss == EnableRss &&
                   other.EnableAutomaticSearch == EnableAutomaticSearch &&
                   other.EnableInteractiveSearch == EnableInteractiveSearch &&
                   other.Name == Name &&
                   other.Implementation == Implementation &&
                   other.Priority == Priority &&
                   other.Id == Id &&
                   apiKey && apiPath && baseUrl && cats && animeCats);
        }