QOL changes to PTP logic (#1114)

pull/1117/head
Devin Buhl 8 years ago committed by GitHub
parent 4b1f7da317
commit 3cf5301e46

@ -1,18 +1,19 @@
using System.Collections.Generic;
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NzbDrone.Common.Http;
using NzbDrone.Core.Indexers.Exceptions;
using NzbDrone.Core.Parser.Model;
using System;
using System.Linq;
using NzbDrone.Common.Cache;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.Indexers.PassThePopcorn
{
public class PassThePopcornParser : IParseIndexerResponse
{
private readonly PassThePopcornSettings _settings;
public ICached<Dictionary<string, string>> AuthCookieCache { get; set; }
public PassThePopcornParser(PassThePopcornSettings settings)
{
@ -25,21 +26,30 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
{
throw new IndexerException(indexerResponse,
"Unexpected response status {0} code from API request",
indexerResponse.HttpResponse.StatusCode);
// Remove cookie cache
AuthCookieCache.Remove(_settings.BaseUrl.Trim().TrimEnd('/'));
throw new IndexerException(indexerResponse, $"Unexpected response status {indexerResponse.HttpResponse.StatusCode} code from API request");
}
var jsonResponse = JsonConvert.DeserializeObject<PassThePopcornResponse>(indexerResponse.Content);
if (indexerResponse.HttpResponse.Headers.ContentType != HttpAccept.Json.Value)
{
// Remove cookie cache
AuthCookieCache.Remove(_settings.BaseUrl.Trim().TrimEnd('/'));
throw new IndexerException(indexerResponse, $"Unexpected response header {indexerResponse.HttpResponse.Headers.ContentType} from API request, expected {HttpAccept.Json.Value}");
}
var responseData = jsonResponse.Movies;
if (responseData == null)
var jsonResponse = JsonConvert.DeserializeObject<PassThePopcornResponse>(indexerResponse.Content);
if (jsonResponse.TotalResults == "0" ||
jsonResponse.TotalResults.IsNullOrWhiteSpace() ||
jsonResponse.Movies == null)
{
throw new IndexerException(indexerResponse,
"Indexer API call response missing result data");
throw new IndexerException(indexerResponse, "No results were found");
}
foreach (var result in responseData)
foreach (var result in jsonResponse.Movies)
{
foreach (var torrent in result.Torrents)
{
@ -155,10 +165,5 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
return url.FullUri;
}
//public static bool IsPropertyExist(dynamic torrents, string name)
//{
// return torrents.GetType().GetProperty(name) != null;
//}
}
}

@ -99,7 +99,7 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
Logger.Debug("PassThePopcorn authentication succeeded.");
cookies = response.GetCookies();
AuthCookieCache.Set(authKey, cookies);
AuthCookieCache.Set(authKey, cookies, new TimeSpan(7, 0, 0, 0, 0)); // re-auth every 7 days
requestBuilder.SetCookies(cookies);
}
else

Loading…
Cancel
Save