Exemplo n.º 1
0
        private ReadarrIndexer BuildReadarrIndexer(IndexerDefinition indexer, DownloadProtocol protocol, int id = 0)
        {
            var cacheKey = $"{Settings.BaseUrl}";
            var schemas  = _schemaCache.Get(cacheKey, () => _readarrV1Proxy.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 readarrIndexer = new ReadarrIndexer
            {
                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,
            };

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

            return(readarrIndexer);
        }
Exemplo n.º 2
0
        public ValidationFailure TestConnection(ReadarrIndexer indexer, ReadarrSettings settings)
        {
            var request = BuildRequest(settings, $"/api/v1/indexer/test", HttpMethod.Post);

            request.SetContent(indexer.ToJson());

            try
            {
                Execute <ReadarrIndexer>(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, Readarr 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);
        }
Exemplo n.º 3
0
        public ReadarrIndexer UpdateIndexer(ReadarrIndexer indexer, ReadarrSettings settings)
        {
            var request = BuildRequest(settings, $"/api/v1/indexer/{indexer.Id}", HttpMethod.Put);

            request.SetContent(indexer.ToJson());

            return(Execute <ReadarrIndexer>(request));
        }
Exemplo n.º 4
0
        public ReadarrIndexer AddIndexer(ReadarrIndexer indexer, ReadarrSettings settings)
        {
            var request = BuildRequest(settings, "/api/v1/indexer", HttpMethod.Post);

            request.SetContent(indexer.ToJson());

            return(Execute <ReadarrIndexer>(request));
        }
Exemplo n.º 5
0
        public bool Equals(ReadarrIndexer 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);

            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);
        }