|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|