Exemple #1
0
        public ValidationFailure TestConnection(LidarrIndexer indexer, LidarrSettings settings)
        {
            var request = BuildRequest(settings, $"/api/v1/indexer/test", HttpMethod.Post);

            request.SetContent(indexer.ToJson());

            try
            {
                Execute <LidarrIndexer>(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, Lidarr 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 #2
0
        private LidarrIndexer BuildLidarrIndexer(IndexerDefinition indexer, DownloadProtocol protocol, int id = 0)
        {
            var cacheKey = $"{Settings.BaseUrl}";
            var schemas  = _schemaCache.Get(cacheKey, () => _lidarrV1Proxy.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 lidarrIndexer = new LidarrIndexer
            {
                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,
            };

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

            return(lidarrIndexer);
        }
Exemple #3
0
        public LidarrIndexer UpdateIndexer(LidarrIndexer indexer, LidarrSettings settings)
        {
            var request = BuildRequest(settings, $"/api/v1/indexer/{indexer.Id}", HttpMethod.Put);

            request.SetContent(indexer.ToJson());

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

            request.SetContent(indexer.ToJson());

            return(Execute <LidarrIndexer>(request));
        }
Exemple #5
0
        public bool Equals(LidarrIndexer 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);
        }