mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 05:53:33 -07:00
Newznab providers will be compared based on url, not name.
Built-in Newznab providers cannot be deleted (they would be re-added anyways), nor can the URL be changed.
This commit is contained in:
parent
b7fea36045
commit
b930eb0993
7 changed files with 79 additions and 14 deletions
103
NzbDrone.Core/Providers/NewznabProvider.cs
Normal file
103
NzbDrone.Core/Providers/NewznabProvider.cs
Normal file
|
@ -0,0 +1,103 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Ninject;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Providers.Indexer;
|
||||
using NzbDrone.Core.Repository;
|
||||
using PetaPoco;
|
||||
|
||||
namespace NzbDrone.Core.Providers
|
||||
{
|
||||
public class NewznabProvider
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly IDatabase _database;
|
||||
|
||||
[Inject]
|
||||
public NewznabProvider(IDatabase database)
|
||||
{
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public NewznabProvider()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual List<NewznabDefinition> Enabled()
|
||||
{
|
||||
return _database.Fetch<NewznabDefinition>("WHERE Enable = 1");
|
||||
}
|
||||
|
||||
public virtual List<NewznabDefinition> All()
|
||||
{
|
||||
return _database.Fetch<NewznabDefinition>();
|
||||
}
|
||||
|
||||
public virtual int Save(NewznabDefinition definition)
|
||||
{
|
||||
//Cleanup the URL if it is not null or whitespace
|
||||
if (!String.IsNullOrWhiteSpace(definition.Url))
|
||||
definition.Url = (new Uri(definition.Url).ParentUriString());
|
||||
|
||||
if (definition.Id == 0)
|
||||
{
|
||||
Logger.Debug("Adding Newznab definitions for {0}", definition.Name);
|
||||
return Convert.ToInt32(_database.Insert(definition));
|
||||
}
|
||||
|
||||
Logger.Debug("Updating Newznab definitions for {0}", definition.Name);
|
||||
return _database.Update(definition);
|
||||
}
|
||||
|
||||
public virtual void SaveAll(IEnumerable<NewznabDefinition> definitions)
|
||||
{
|
||||
var definitionsList = definitions.ToList();
|
||||
|
||||
//Cleanup the URL for each definition
|
||||
definitionsList.ForEach(p => p.Url = (new Uri(p.Url).ParentUriString()));
|
||||
|
||||
_database.UpdateMany(definitionsList);
|
||||
}
|
||||
|
||||
public virtual void InitializeNewznabIndexers(IList<NewznabDefinition> indexers)
|
||||
{
|
||||
Logger.Debug("Initializing Newznab indexers. Count {0}", indexers.Count);
|
||||
|
||||
var currentIndexers = All();
|
||||
|
||||
foreach (var feedProvider in indexers)
|
||||
{
|
||||
NewznabDefinition indexerLocal = feedProvider;
|
||||
var currentIndexer = currentIndexers
|
||||
.SingleOrDefault(c => new Uri(c.Url.ToLower()).Host == new Uri(indexerLocal.Url.ToLower()).Host);
|
||||
|
||||
if (currentIndexer == null)
|
||||
{
|
||||
var settings = new NewznabDefinition
|
||||
{
|
||||
Enable = false,
|
||||
Name = indexerLocal.Name,
|
||||
Url = indexerLocal.Url,
|
||||
ApiKey = indexerLocal.ApiKey,
|
||||
BuiltIn = true
|
||||
};
|
||||
|
||||
Save(settings);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
currentIndexer.BuiltIn = true;
|
||||
Save(currentIndexer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Delete(int id)
|
||||
{
|
||||
_database.Delete<NewznabDefinition>(id);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue