updates and compile-able

pull/2/head
Devin Buhl 8 years ago
parent 47824426c6
commit ec1c81e3ed

@ -1,35 +0,0 @@
using System;
using System.Collections.Generic;
using FluentValidation.Results;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.AutoImport
{
public abstract class AutoImportBase<TSettings> : IAutoImport where TSettings : IProviderConfig, new()
{
public abstract string Name { get; }
public Type ConfigContract => typeof(TSettings);
public virtual ProviderMessage Message => null;
public IEnumerable<ProviderDefinition> DefaultDefinitions => new List<ProviderDefinition>();
public ProviderDefinition Definition { get; set; }
public abstract ValidationResult Test();
public abstract string Link { get; }
protected TSettings Settings => (TSettings)Definition.Settings;
public override string ToString()
{
return GetType().Name;
}
public abstract bool Enabled { get; }
public virtual object RequestAction(string action, IDictionary<string, string> query) { return null; }
}
}

@ -1,18 +0,0 @@
using System.Collections.Generic;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.AutoImport
{
public class AutoImportDefinition : ProviderDefinition
{
public AutoImportDefinition()
{
Tags = new HashSet<int>();
}
public bool Enabled { get; set; }
public HashSet<int> Tags { get; set; }
public override bool Enable => Enabled;
}
}

@ -1,20 +0,0 @@
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.AutoImport
{
public interface IAutoImportRepository : IProviderRepository<AutoImportDefinition>
{
}
public class AutoImportRepository : ProviderRepository<AutoImportDefinition>, IAutoImportRepository
{
public AutoImportRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}
}
}

@ -1,12 +0,0 @@
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.AutoImport
{
public interface IAutoImport : IProvider
{
string Link { get; }
bool Enabled { get; }
// void OnGrab(GrabMessage grabMessage);
}
}

@ -1,43 +0,0 @@

using System.Collections.Generic;
using FluentValidation.Results;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Tv;
using NzbDrone.Core.AutoImport;
using NzbDrone.Core.AutoImport.IMDbWatchList;
using System;
namespace NzbDrone.Core.AutoImpoter.IMDbWatchList
{
public class IMDbWatchList : AutoImportBase<IMDbWatchListSettings>
{
public override bool Enabled
{
get
{
throw new NotImplementedException();
}
}
//private readonly INotifyMyAndroidProxy _proxy;
//public NotifyMyAndroid(INotifyMyAndroidProxy proxy)
//{
// _proxy = proxy;
//}
public override string Link => "http://rss.imdb.com/";
public override string Name => "IMDb Public Watchlist";
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();
// failures.AddIfNotNull(_proxy.Test(Settings));
return new ValidationResult(failures);
}
}
}

@ -0,0 +1,18 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(119)]
public class create_netimport_table : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Create.TableForModel("NetImport")
.WithColumn("Enabled").AsBoolean()
.WithColumn("Name").AsString().Unique()
.WithColumn("Implementation").AsString()
.WithColumn("Settings").AsString().Nullable();
}
}
}

@ -0,0 +1,23 @@
using NzbDrone.Common.Exceptions;
namespace NzbDrone.Core.NetImport.Exceptions
{
public class NetImportException : NzbDroneException
{
private readonly NetImportResponse _netImportResponse;
public NetImportException(NetImportResponse response, string message, params object[] args)
: base(message, args)
{
_netImportResponse = response;
}
public NetImportException(NetImportResponse response, string message)
: base(message)
{
_netImportResponse = response;
}
public NetImportResponse Response => _netImportResponse;
}
}

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using FluentValidation.Results;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Http.CloudFlare;
using NzbDrone.Core.Indexers.Exceptions;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.NetImport
{
public abstract class HttpNetImportBase<TSettings> : NetImportBase<TSettings>
where TSettings : IProviderConfig, new()
{
protected const int MaxNumResultsPerQuery = 1000;
protected readonly IHttpClient _httpClient;
public override bool Enabled => true;
public virtual TimeSpan RateLimit => TimeSpan.FromSeconds(2);
public abstract INetImportRequestGenerator GetRequestGenerator();
public abstract IParseNetImportResponse GetParser();
public HttpNetImportBase(IHttpClient httpClient, IConfigService configService, IParsingService parsingService, Logger logger)
: base(configService, parsingService, logger)
{
_httpClient = httpClient;
}
public override IList<Movie> Fetch()
{
return new List<Movie>();
}
protected override void Test(List<ValidationFailure> failures)
{
throw new NotImplementedException();
}
protected virtual ValidationFailure TestConnection()
{
throw new NotImplementedException();
}
}
}

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using FluentValidation.Results;
using NLog;
using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.PassThePopcorn;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.NetImport.IMDbWatchList
{
public class IMDbWatchList : HttpNetImportBase<IMDbWatchListSettings>
{
public override string Name => "IMDbWatchList";
public override string Link => "http://rss.imdb.com/list/";
public override bool Enabled => true;
public IMDbWatchList(IHttpClient httpClient, IConfigService configService, IParsingService parsingService, Logger logger)
: base(httpClient, configService, parsingService, logger)
{ }
public override INetImportRequestGenerator GetRequestGenerator()
{
return new IMDbWatchListRequestGenerator() { Settings = Settings };
}
public override IParseNetImportResponse GetParser()
{
return new IMDbWatchListParser(Settings);
}
}
}

@ -0,0 +1,40 @@
using System.Collections.Generic;
using System.Xml.Serialization;
namespace NzbDrone.Core.NetImport.IMDbWatchList
{
class IMDbWatchListAPI
{
[XmlRoot(ElementName = "item")]
public class Movie
{
[XmlElement(ElementName = "pubDate")]
public string PublishDate { get; set; }
[XmlElement(ElementName = "title")]
public string Title { get; set; }
[XmlElement(ElementName = "link")]
public string Link { get; set; }
[XmlElement(ElementName = "guid")]
public string Guid { get; set; }
[XmlElement(ElementName = "description")]
public string Description { get; set; }
}
[XmlRoot(ElementName = "channel")]
public class Channel
{
[XmlElement(ElementName = "title")]
public string Title { get; set; }
[XmlElement(ElementName = "link")]
public string Link { get; set; }
[XmlElement(ElementName = "description")]
public string Description { get; set; }
[XmlElement(ElementName = "pubDate")]
public string PublishDate { get; set; }
[XmlElement(ElementName = "lastBuildDate")]
public string LastBuildDate { get; set; }
[XmlElement(ElementName = "item")]
public List<Movie> Movie { get; set; }
}
}
}

@ -0,0 +1,54 @@
using Newtonsoft.Json;
using NzbDrone.Core.NetImport.Exceptions;
using NzbDrone.Core.Tv;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
namespace NzbDrone.Core.NetImport.IMDbWatchList
{
public class IMDbWatchListParser : IParseNetImportResponse
{
private readonly IMDbWatchListSettings _settings;
public IMDbWatchListParser(IMDbWatchListSettings settings)
{
_settings = settings;
}
public IList<Movie> ParseResponse(NetImportResponse netImportResponse)
{
var torrentInfos = new List<Movie>();
if (netImportResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
{
throw new NetImportException(netImportResponse,
"Unexpected response status {0} code from API request",
netImportResponse.HttpResponse.StatusCode);
}
var jsonResponse = JsonConvert.DeserializeObject<IMDbWatchListAPI.Channel>(netImportResponse.Content);
var responseData = jsonResponse.Movie;
if (responseData == null)
{
throw new NetImportException(netImportResponse,
"This list has no movies");
}
foreach (var result in responseData)
{
torrentInfos.Add(new Movie()
{
Title = Parser.Parser.ParseMovieTitle(result.Title, false).MovieTitle,
Year = Parser.Parser.ParseMovieTitle(result.Title, false).Year,
ImdbId = Parser.Parser.ParseImdbId(result.Link).ToString()
});
}
return torrentInfos.ToArray();
}
}
}

@ -8,7 +8,7 @@ using NzbDrone.Core.Exceptions;
using RestSharp;
using NzbDrone.Core.Rest;
namespace NzbDrone.Core.AutoImport.IMDbWatchList
namespace NzbDrone.Core.NetImport.IMDbWatchList
{
public interface IIMDbWatchListProxy
{
@ -64,8 +64,8 @@ namespace NzbDrone.Core.AutoImport.IMDbWatchList
{
try
{
Verify(settings.IMDbWatchListId);
ImportMovies(settings.IMDbWatchListId);
Verify(settings.Link);
ImportMovies(settings.Link);
}
catch (Exception ex)
{

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.IndexerSearch.Definitions;
namespace NzbDrone.Core.NetImport.IMDbWatchList
{
public class IMDbWatchListRequestGenerator : INetImportRequestGenerator
{
public IMDbWatchListSettings Settings { get; set; }
public virtual NetImportPageableRequestChain GetMovies()
{
var pageableRequests = new NetImportPageableRequestChain();
pageableRequests.Add(GetMovies(null));
return pageableRequests;
}
public NetImportPageableRequestChain GetSearchRequests(MovieSearchCriteria searchCriteria)
{
return new NetImportPageableRequestChain();
}
private IEnumerable<NetImportRequest> GetMovies(string searchParameters)
{
var request = new NetImportRequest($"{Settings.Link.Trim()}", HttpAccept.Rss);
yield return request;
}
}
}

@ -3,13 +3,13 @@ using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.AutoImport.IMDbWatchList
namespace NzbDrone.Core.NetImport.IMDbWatchList
{
public class IMDbWatchListSettingsValidator : AbstractValidator<IMDbWatchListSettings>
{
public IMDbWatchListSettingsValidator()
{
RuleFor(c => c.IMDbWatchListId).NotEmpty();
RuleFor(c => c.Link).NotEmpty();
}
}
@ -17,10 +17,15 @@ namespace NzbDrone.Core.AutoImport.IMDbWatchList
{
private static readonly IMDbWatchListSettingsValidator Validator = new IMDbWatchListSettingsValidator();
[FieldDefinition(0, Label = "Watch List Id", HelpLink = "http://rss.imdb.com/list/")]
public string IMDbWatchListId { get; set; }
public IMDbWatchListSettings()
{
Link = "http://rss.imdb.com/list/";
}
[FieldDefinition(0, Label = "Watch List RSS link", HelpLink = "http://rss.imdb.com/list/")]
public string Link { get; set; }
public bool IsValid => !string.IsNullOrWhiteSpace(IMDbWatchListId);
public bool IsValid => !string.IsNullOrWhiteSpace(Link);
public NzbDroneValidationResult Validate()
{

@ -4,9 +4,9 @@ using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.AutoImporter
namespace NzbDrone.Core.NetImport
{
public interface IAutoImporter : IProvider
public interface INetImport : IProvider
{
string Link { get; }
bool Enabled { get; }

@ -0,0 +1,9 @@
using NzbDrone.Core.IndexerSearch.Definitions;
namespace NzbDrone.Core.NetImport
{
public interface INetImportRequestGenerator
{
NetImportPageableRequestChain GetMovies();
}
}

@ -0,0 +1,11 @@
using System.Collections.Generic;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.NetImport
{
public interface IParseNetImportResponse
{
IList<Movie> ParseResponse(NetImportResponse netMovieImporterResponse);
}
}

@ -11,9 +11,9 @@ using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.AutoImporter
namespace NzbDrone.Core.NetImport
{
public abstract class AutoImporterBase<TSettings> : IAutoImporter
public abstract class NetImportBase<TSettings> : INetImport
where TSettings : IProviderConfig, new()
{
protected readonly IConfigService _configService;
@ -25,7 +25,7 @@ namespace NzbDrone.Core.AutoImporter
public abstract bool Enabled { get; }
public AutoImporterBase(IConfigService configService, IParsingService parsingService, Logger logger)
public NetImportBase(IConfigService configService, IParsingService parsingService, Logger logger)
{
_configService = configService;
_parsingService = parsingService;
@ -42,7 +42,7 @@ namespace NzbDrone.Core.AutoImporter
{
var config = (IProviderConfig)new TSettings();
yield return new AutoImporterDefinition
yield return new NetImportDefinition
{
Name = GetType().Name,
Link = Link,

@ -1,8 +1,8 @@
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.AutoImporter
namespace NzbDrone.Core.NetImport
{
public class AutoImporterDefinition : ProviderDefinition
public class NetImportDefinition : ProviderDefinition
{
public bool Enabled { get; set; }
public string Link { get; set; }

@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
namespace NzbDrone.Core.NetImport
{
public class NetImportPageableRequest : IEnumerable<NetImportRequest>
{
private readonly IEnumerable<NetImportRequest> _enumerable;
public NetImportPageableRequest(IEnumerable<NetImportRequest> enumerable)
{
_enumerable = enumerable;
}
public IEnumerator<NetImportRequest> GetEnumerator()
{
return _enumerable.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return _enumerable.GetEnumerator();
}
}
}

@ -0,0 +1,48 @@
using System.Collections.Generic;
using System.Linq;
namespace NzbDrone.Core.NetImport
{
public class NetImportPageableRequestChain
{
private List<List<NetImportPageableRequest>> _chains;
public NetImportPageableRequestChain()
{
_chains = new List<List<NetImportPageableRequest>>();
_chains.Add(new List<NetImportPageableRequest>());
}
public int Tiers => _chains.Count;
public IEnumerable<NetImportPageableRequest> GetAllTiers()
{
return _chains.SelectMany(v => v);
}
public IEnumerable<NetImportPageableRequest> GetTier(int index)
{
return _chains[index];
}
public void Add(IEnumerable<NetImportRequest> request)
{
if (request == null) return;
_chains.Last().Add(new NetImportPageableRequest(request));
}
public void AddTier(IEnumerable<NetImportRequest> request)
{
AddTier();
Add(request);
}
public void AddTier()
{
if (_chains.Last().Count == 0) return;
_chains.Add(new List<NetImportPageableRequest>());
}
}
}

@ -0,0 +1,20 @@
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.NetImport
{
public interface INetImportRepository : IProviderRepository<NetImportDefinition>
{
}
public class NetImportRepository : ProviderRepository<NetImportDefinition>, INetImportRepository
{
public NetImportRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}
}
}

@ -0,0 +1,21 @@
using NzbDrone.Common.Http;
namespace NzbDrone.Core.NetImport
{
public class NetImportRequest
{
public HttpRequest HttpRequest { get; private set; }
public NetImportRequest(string url, HttpAccept httpAccept)
{
HttpRequest = new HttpRequest(url, httpAccept);
}
public NetImportRequest(HttpRequest httpRequest)
{
HttpRequest = httpRequest;
}
public HttpUri Url => HttpRequest.Url;
}
}

@ -0,0 +1,24 @@
using NzbDrone.Common.Http;
namespace NzbDrone.Core.NetImport
{
public class NetImportResponse
{
private readonly NetImportRequest _netImport;
private readonly HttpResponse _httpResponse;
public NetImportResponse(NetImportRequest netImport, HttpResponse httpResponse)
{
_netImport = netImport;
_httpResponse = httpResponse;
}
public NetImportRequest Request => _netImport;
public HttpRequest HttpRequest => _httpResponse.Request;
public HttpResponse HttpResponse => _httpResponse;
public string Content => _httpResponse.Content;
}
}

@ -122,16 +122,24 @@
<Compile Include="Authentication\User.cs" />
<Compile Include="Authentication\UserRepository.cs" />
<Compile Include="Authentication\UserService.cs" />
<Compile Include="AutoImport.derp\AutoImportBase.cs" />
<Compile Include="AutoImport.derp\IAutoImport.cs" />
<Compile Include="AutoImport.derp\IMDbWatchList\IMDbWatchList.cs" />
<Compile Include="AutoImport.derp\IMDbWatchList\IMDbWatchListSettings.cs" />
<Compile Include="AutoImport.derp\IMDbWatchList\IMDbWatchListProxy.cs" />
<Compile Include="AutoImport.derp\AutoImportRepository.cs" />
<Compile Include="AutoImport.derp\AutoImportDefinition.cs" />
<Compile Include="AutoImporter\AutoImporterBase.cs" />
<Compile Include="AutoImporter\IAutoImporter.cs" />
<Compile Include="AutoImporter\AutoImporterDefinition.cs" />
<Compile Include="NetImport\Exceptions\NetImportException.cs" />
<Compile Include="NetImport\HttpNetImportBase.cs" />
<Compile Include="NetImport\IProcessNetImportResponse.cs" />
<Compile Include="NetImport\NetImportPageableRequest.cs" />
<Compile Include="NetImport\NetImportPageableRequestChain.cs" />
<Compile Include="NetImport\INetImportRequestGenerator.cs" />
<Compile Include="NetImport\IMDbWatchList\IMDbWatchListAPI.cs" />
<Compile Include="NetImport\IMDbWatchList\IMDbWatchListParser.cs" />
<Compile Include="NetImport\IMDbWatchList\IMDbWatchListRequestGenerator.cs" />
<Compile Include="NetImport\NetImportRequest.cs" />
<Compile Include="NetImport\NetImportResponse.cs" />
<Compile Include="NetImport\NetImportBase.cs" />
<Compile Include="NetImport\NetImportRepository.cs" />
<Compile Include="NetImport\INetImport.cs" />
<Compile Include="NetImport\NetImportDefinition.cs" />
<Compile Include="NetImport\IMDbWatchList\IMDbWatchList.cs" />
<Compile Include="NetImport\IMDbWatchList\IMDbWatchListProxy.cs" />
<Compile Include="NetImport\IMDbWatchList\IMDbWatchListSettings.cs" />
<Compile Include="Backup\Backup.cs" />
<Compile Include="Backup\BackupCommand.cs" />
<Compile Include="Backup\BackupService.cs" />

Loading…
Cancel
Save