You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.1 KiB
69 lines
2.1 KiB
using Newtonsoft.Json;
|
|
using NzbDrone.Core.NetImport.Exceptions;
|
|
using System.Collections.Generic;
|
|
using System.Net;
|
|
using NLog;
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
namespace NzbDrone.Core.NetImport.StevenLu
|
|
{
|
|
public class StevenLuParser : IParseNetImportResponse
|
|
{
|
|
private readonly StevenLuSettings _settings;
|
|
private NetImportResponse _importResponse;
|
|
|
|
public StevenLuParser(StevenLuSettings settings)
|
|
{
|
|
_settings = settings;
|
|
}
|
|
|
|
public IList<Movies.Movie> ParseResponse(NetImportResponse importResponse)
|
|
{
|
|
_importResponse = importResponse;
|
|
|
|
var movies = new List<Movies.Movie>();
|
|
|
|
if (!PreProcess(_importResponse))
|
|
{
|
|
return movies;
|
|
}
|
|
|
|
var jsonResponse = JsonConvert.DeserializeObject<List<StevenLuResponse>>(_importResponse.Content);
|
|
|
|
// no movies were return
|
|
if (jsonResponse == null)
|
|
{
|
|
return movies;
|
|
}
|
|
|
|
foreach (var item in jsonResponse)
|
|
{
|
|
movies.AddIfNotNull(new Movies.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;
|
|
}
|
|
|
|
}
|
|
}
|