Devin Buhl 8 years ago
parent 8b3b46b724
commit 87da542758

@ -0,0 +1,18 @@
using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml.Serialization;
namespace NzbDrone.Core.NetImport.StevenLu
{
public class StevenLuResponse
{
public Movie[] Movie { get; set; }
}
public class Movie
{
public string title { get; set; }
public string imdb_id { get; set; }
public string poster_url { get; set; }
}
}

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
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.ThingiProvider;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.NetImport.StevenLu
{
public class StevenLuImport : HttpNetImportBase<StevenLuSettings>
{
public override string Name => "Popular movies from StevenLu";
public override bool Enabled => true;
public override bool EnableAuto => true;
public StevenLuImport(IHttpClient httpClient, IConfigService configService, IParsingService parsingService, Logger logger)
: base(httpClient, configService, parsingService, logger)
{ }
public override INetImportRequestGenerator GetRequestGenerator()
{
return new StevenLuRequestGenerator() { Settings = Settings };
}
public override IParseNetImportResponse GetParser()
{
return new StevenLuParser(Settings);
}
}
}

@ -0,0 +1,82 @@
using Newtonsoft.Json;
using NzbDrone.Core.NetImport.Exceptions;
using NzbDrone.Core.Tv;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Exceptions;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.NetImport.StevenLu
{
public class StevenLuParser : IParseNetImportResponse
{
private readonly StevenLuSettings _settings;
private NetImportResponse _importResponse;
private readonly Logger _logger;
public StevenLuParser(StevenLuSettings settings)
{
_settings = settings;
}
public IList<Tv.Movie> ParseResponse(NetImportResponse importResponse)
{
_importResponse = importResponse;
var movies = new List<Tv.Movie>();
if (!PreProcess(_importResponse))
{
return movies;
}
var jsonResponse = JsonConvert.DeserializeObject<StevenLuResponse>(_importResponse.Content);
// no movies were return
if (jsonResponse == null)
{
return movies;
}
foreach (var item in jsonResponse.Movie)
{
movies.AddIfNotNull(new Tv.Movie()
{
Title = item.title,
ImdbId = item.imdb_id
});
}
return movies;
}
protected virtual bool PreProcess(NetImportResponse indexerResponse)
{
if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
{
throw new NetImportException(indexerResponse, "Indexer API call resulted in an unexpected StatusCode [{0}]", indexerResponse.HttpResponse.StatusCode);
}
if (indexerResponse.HttpResponse.Headers.ContentType != null && indexerResponse.HttpResponse.Headers.ContentType.Contains("text/json") &&
indexerResponse.HttpRequest.Headers.Accept != null && !indexerResponse.HttpRequest.Headers.Accept.Contains("text/json"))
{
throw new NetImportException(indexerResponse, "Indexer responded with html content. Site is likely blocked or unavailable.");
}
return true;
}
}
}

@ -0,0 +1,28 @@
using NzbDrone.Common.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.NetImport.StevenLu
{
public class StevenLuRequestGenerator : INetImportRequestGenerator
{
public StevenLuSettings Settings { get; set; }
public virtual NetImportPageableRequestChain GetMovies()
{
var pageableRequests = new NetImportPageableRequestChain();
pageableRequests.Add(GetMovies(null));
return pageableRequests;
}
private IEnumerable<NetImportRequest> GetMovies(string searchParameters)
{
var request = new NetImportRequest($"{Settings.Link.Trim()}", HttpAccept.Json);
yield return request;
}
}
}

@ -0,0 +1,22 @@
using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.NetImport.StevenLu
{
public class StevenLuSettings : NetImportBaseSettings
{
public StevenLuSettings()
{
Link = "https://s3.amazonaws.com/popular-movies/movies.json";
}
[FieldDefinition(0, Label = "URL", HelpText = "Don't change this unless you know what you are doing.")]
public new string Link { get; set; }
}
}
Loading…
Cancel
Save