mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-23 06:45:19 -07: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.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using NzbDrone.Common.Http;
|
using NzbDrone.Common.Http;
|
||||||
using NzbDrone.Core.Indexers.Exceptions;
|
using NzbDrone.Core.Indexers.Exceptions;
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
using System;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using NzbDrone.Common.Cache;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Indexers.PassThePopcorn
|
namespace NzbDrone.Core.Indexers.PassThePopcorn
|
||||||
{
|
{
|
||||||
public class PassThePopcornParser : IParseIndexerResponse
|
public class PassThePopcornParser : IParseIndexerResponse
|
||||||
{
|
{
|
||||||
private readonly PassThePopcornSettings _settings;
|
private readonly PassThePopcornSettings _settings;
|
||||||
|
public ICached<Dictionary<string, string>> AuthCookieCache { get; set; }
|
||||||
|
|
||||||
public PassThePopcornParser(PassThePopcornSettings settings)
|
public PassThePopcornParser(PassThePopcornSettings settings)
|
||||||
{
|
{
|
||||||
|
@ -25,21 +26,30 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
|
||||||
|
|
||||||
if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
|
if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
|
||||||
{
|
{
|
||||||
throw new IndexerException(indexerResponse,
|
// Remove cookie cache
|
||||||
"Unexpected response status {0} code from API request",
|
AuthCookieCache.Remove(_settings.BaseUrl.Trim().TrimEnd('/'));
|
||||||
indexerResponse.HttpResponse.StatusCode);
|
|
||||||
|
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 jsonResponse = JsonConvert.DeserializeObject<PassThePopcornResponse>(indexerResponse.Content);
|
||||||
|
if (jsonResponse.TotalResults == "0" ||
|
||||||
var responseData = jsonResponse.Movies;
|
jsonResponse.TotalResults.IsNullOrWhiteSpace() ||
|
||||||
if (responseData == null)
|
jsonResponse.Movies == null)
|
||||||
{
|
{
|
||||||
throw new IndexerException(indexerResponse,
|
throw new IndexerException(indexerResponse, "No results were found");
|
||||||
"Indexer API call response missing result data");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var result in responseData)
|
|
||||||
|
foreach (var result in jsonResponse.Movies)
|
||||||
{
|
{
|
||||||
foreach (var torrent in result.Torrents)
|
foreach (var torrent in result.Torrents)
|
||||||
{
|
{
|
||||||
|
@ -155,10 +165,5 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
|
||||||
|
|
||||||
return url.FullUri;
|
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.");
|
Logger.Debug("PassThePopcorn authentication succeeded.");
|
||||||
|
|
||||||
cookies = response.GetCookies();
|
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);
|
requestBuilder.SetCookies(cookies);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue