mirror of
https://github.com/Radarr/Radarr
synced 2025-02-24 23:23:21 +00:00
QOL changes to PTP logic (#1114)
This commit is contained in:
parent
4b1f7da317
commit
3cf5301e46
2 changed files with 22 additions and 17 deletions
|
@ -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 @@ public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
|
|||
|
||||
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");
|
||||
}
|
||||
|
||||
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 jsonResponse = JsonConvert.DeserializeObject<PassThePopcornResponse>(indexerResponse.Content);
|
||||
|
||||
var responseData = jsonResponse.Movies;
|
||||
if (responseData == null)
|
||||
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 @@ private string GetInfoUrl(string groupId, int torrentId)
|
|||
|
||||
return url.FullUri;
|
||||
}
|
||||
|
||||
//public static bool IsPropertyExist(dynamic torrents, string name)
|
||||
//{
|
||||
// return torrents.GetType().GetProperty(name) != null;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ private void Authenticate()
|
|||
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…
Reference in a new issue