Fixed: (PassThePopcorn) Disable grouping

pull/9232/head
Bogdan 1 year ago
parent e2f5f2f73a
commit 1762a189d2

@ -6,7 +6,6 @@ using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Http; using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.PassThePopcorn; using NzbDrone.Core.Indexers.PassThePopcorn;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
@ -20,26 +19,22 @@ namespace NzbDrone.Core.Test.IndexerTests.PTPTests
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
Subject.Definition = new IndexerDefinition() Subject.Definition = new IndexerDefinition
{ {
Name = "PTP", Name = "PTP",
Settings = new PassThePopcornSettings() { APIUser = "asdf", APIKey = "sad" } Settings = new PassThePopcornSettings
{
APIUser = "asdf",
APIKey = "sad"
}
}; };
} }
[TestCase("Files/Indexers/PTP/imdbsearch.json")] [TestCase("Files/Indexers/PTP/imdbsearch.json")]
public async Task should_parse_feed_from_PTP(string fileName) public async Task should_parse_feed_from_PTP(string fileName)
{ {
var authResponse = new PassThePopcornAuthResponse { Result = "Ok" };
var authStream = new System.IO.StringWriter();
Json.Serialize(authResponse, authStream);
var responseJson = ReadAllText(fileName); var responseJson = ReadAllText(fileName);
Mocker.GetMock<IHttpClient>()
.Setup(o => o.ExecuteAsync(It.Is<HttpRequest>(v => v.Method == HttpMethod.Post)))
.Returns<HttpRequest>(r => Task.FromResult(new HttpResponse(r, new HttpHeader(), authStream.ToString())));
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(o => o.ExecuteAsync(It.Is<HttpRequest>(v => v.Method == HttpMethod.Get))) .Setup(o => o.ExecuteAsync(It.Is<HttpRequest>(v => v.Method == HttpMethod.Get)))
.Returns<HttpRequest>(r => Task.FromResult(new HttpResponse(r, new HttpHeader { ContentType = HttpAccept.Json.Value }, responseJson))); .Returns<HttpRequest>(r => Task.FromResult(new HttpResponse(r, new HttpHeader { ContentType = HttpAccept.Json.Value }, responseJson)));

@ -1,5 +1,4 @@
using NLog; using NLog;
using NzbDrone.Common.Cache;
using NzbDrone.Common.Http; using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
@ -15,7 +14,6 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
public override int PageSize => 50; public override int PageSize => 50;
public PassThePopcorn(IHttpClient httpClient, public PassThePopcorn(IHttpClient httpClient,
ICacheManager cacheManager,
IIndexerStatusService indexerStatusService, IIndexerStatusService indexerStatusService,
IConfigService configService, IConfigService configService,
IParsingService parsingService, IParsingService parsingService,
@ -26,12 +24,7 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
public override IIndexerRequestGenerator GetRequestGenerator() public override IIndexerRequestGenerator GetRequestGenerator()
{ {
return new PassThePopcornRequestGenerator() return new PassThePopcornRequestGenerator(Settings);
{
Settings = Settings,
HttpClient = _httpClient,
Logger = _logger,
};
} }
public override IParseIndexerResponse GetParser() public override IParseIndexerResponse GetParser()

@ -3,13 +3,27 @@ using System.Collections.Generic;
namespace NzbDrone.Core.Indexers.PassThePopcorn namespace NzbDrone.Core.Indexers.PassThePopcorn
{ {
public class Director public class PassThePopcornResponse
{ {
public string Name { get; set; } public string TotalResults { get; set; }
public string Id { get; set; } public List<PassThePopcornMovie> Movies { get; set; }
public string Page { get; set; }
public string AuthKey { get; set; }
public string PassKey { get; set; }
} }
public class Torrent public class PassThePopcornMovie
{
public string GroupId { get; set; }
public string Title { get; set; }
public string Year { get; set; }
public string Cover { get; set; }
public List<string> Tags { get; set; }
public string ImdbId { get; set; }
public List<PassThePopcornTorrent> Torrents { get; set; }
}
public class PassThePopcornTorrent
{ {
public int Id { get; set; } public int Id { get; set; }
public string Quality { get; set; } public string Quality { get; set; }
@ -29,37 +43,4 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
public bool GoldenPopcorn { get; set; } public bool GoldenPopcorn { get; set; }
public string FreeleechType { get; set; } public string FreeleechType { get; set; }
} }
public class Movie
{
public string GroupId { get; set; }
public string Title { get; set; }
public string Year { get; set; }
public string Cover { get; set; }
public List<string> Tags { get; set; }
public List<Director> Directors { get; set; }
public string ImdbId { get; set; }
public int TotalLeechers { get; set; }
public int TotalSeeders { get; set; }
public int TotalSnatched { get; set; }
public long MaxSize { get; set; }
public string LastUploadTime { get; set; }
public List<Torrent> Torrents { get; set; }
}
public class PassThePopcornResponse
{
public string TotalResults { get; set; }
public List<Movie> Movies { get; set; }
public string Page { get; set; }
public string AuthKey { get; set; }
public string PassKey { get; set; }
}
public class PassThePopcornAuthResponse
{
public string Result { get; set; }
public string Popcron { get; set; }
public string AntiCsrfToken { get; set; }
}
} }

@ -26,26 +26,11 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK) if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
{ {
// Remove cookie cache
if (indexerResponse.HttpResponse.HasHttpRedirect && indexerResponse.HttpResponse.Headers["Location"]
.ContainsIgnoreCase("login.php"))
{
CookiesUpdater(null, null);
throw new IndexerException(indexerResponse, "We are being redirected to the PTP login page. Most likely your session expired or was killed. Try testing the indexer in the settings.");
}
throw new IndexerException(indexerResponse, $"Unexpected response status {indexerResponse.HttpResponse.StatusCode} code from API request"); throw new IndexerException(indexerResponse, $"Unexpected response status {indexerResponse.HttpResponse.StatusCode} code from API request");
} }
if (indexerResponse.HttpResponse.Headers.ContentType != HttpAccept.Json.Value) if (indexerResponse.HttpResponse.Headers.ContentType != HttpAccept.Json.Value)
{ {
if (indexerResponse.HttpResponse.Request.Url.Path.ContainsIgnoreCase("login.php"))
{
CookiesUpdater(null, null);
throw new IndexerException(indexerResponse, "We are currently on the login page. Most likely your session expired or was killed. Try testing the indexer in the settings.");
}
// Remove cookie cache
throw new IndexerException(indexerResponse, $"Unexpected response header {indexerResponse.HttpResponse.Headers.ContentType} from API request, expected {HttpAccept.Json.Value}"); throw new IndexerException(indexerResponse, $"Unexpected response header {indexerResponse.HttpResponse.Headers.ContentType} from API request, expected {HttpAccept.Json.Value}");
} }
@ -62,17 +47,16 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
foreach (var torrent in result.Torrents) foreach (var torrent in result.Torrents)
{ {
var id = torrent.Id; var id = torrent.Id;
var title = torrent.ReleaseName;
IndexerFlags flags = 0; IndexerFlags flags = 0;
if (torrent.GoldenPopcorn) if (torrent.GoldenPopcorn)
{ {
flags |= IndexerFlags.PTP_Golden; // title = $"{title} 🍿"; flags |= IndexerFlags.PTP_Golden;
} }
if (torrent.Checked) if (torrent.Checked)
{ {
flags |= IndexerFlags.PTP_Approved; // title = $"{title} ✔"; flags |= IndexerFlags.PTP_Approved;
} }
if (torrent.FreeleechType == "Freeleech") if (torrent.FreeleechType == "Freeleech")
@ -88,10 +72,10 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
// Only add approved torrents // Only add approved torrents
try try
{ {
torrentInfos.Add(new PassThePopcornInfo() torrentInfos.Add(new PassThePopcornInfo
{ {
Guid = string.Format("PassThePopcorn-{0}", id), Guid = $"PassThePopcorn-{id}",
Title = title, Title = torrent.ReleaseName,
Size = long.Parse(torrent.Size), Size = long.Parse(torrent.Size),
DownloadUrl = GetDownloadUrl(id, jsonResponse.AuthKey, jsonResponse.PassKey), DownloadUrl = GetDownloadUrl(id, jsonResponse.AuthKey, jsonResponse.PassKey),
InfoUrl = GetInfoUrl(result.GroupId, id), InfoUrl = GetInfoUrl(result.GroupId, id),

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using NLog;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http; using NzbDrone.Common.Http;
using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.IndexerSearch.Definitions;
@ -9,12 +8,12 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
{ {
public class PassThePopcornRequestGenerator : IIndexerRequestGenerator public class PassThePopcornRequestGenerator : IIndexerRequestGenerator
{ {
public PassThePopcornSettings Settings { get; set; } private readonly PassThePopcornSettings _settings;
public IDictionary<string, string> Cookies { get; set; } public PassThePopcornRequestGenerator(PassThePopcornSettings settings)
{
public IHttpClient HttpClient { get; set; } _settings = settings;
public Logger Logger { get; set; } }
public virtual IndexerPageableRequestChain GetRecentRequests() public virtual IndexerPageableRequestChain GetRecentRequests()
{ {
@ -37,37 +36,27 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
{ {
foreach (var queryTitle in searchCriteria.CleanSceneTitles) foreach (var queryTitle in searchCriteria.CleanSceneTitles)
{ {
pageableRequests.Add(GetRequest(string.Format("{0}&year={1}", queryTitle, searchCriteria.Movie.Year))); pageableRequests.Add(GetRequest($"{queryTitle}&year={searchCriteria.Movie.Year}"));
} }
} }
return pageableRequests; return pageableRequests;
} }
public Func<IDictionary<string, string>> GetCookies { get; set; }
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
private IEnumerable<IndexerRequest> GetRequest(string searchParameters) private IEnumerable<IndexerRequest> GetRequest(string searchParameters)
{ {
var request = var request =
new IndexerRequest( new IndexerRequest(
$"{Settings.BaseUrl.Trim().TrimEnd('/')}/torrents.php?action=advanced&json=noredirect&searchstr={searchParameters}", $"{_settings.BaseUrl.Trim().TrimEnd('/')}/torrents.php?action=advanced&json=noredirect&grouping=0&searchstr={searchParameters}",
HttpAccept.Json); HttpAccept.Json);
request.HttpRequest.Headers["ApiUser"] = Settings.APIUser; request.HttpRequest.Headers.Add("ApiUser", _settings.APIUser);
request.HttpRequest.Headers["ApiKey"] = Settings.APIKey; request.HttpRequest.Headers.Add("ApiKey", _settings.APIKey);
if (Settings.APIKey.IsNullOrWhiteSpace())
{
foreach (var cookie in Cookies)
{
request.HttpRequest.Cookies[cookie.Key] = cookie.Value;
}
CookiesUpdater(Cookies, DateTime.Now + TimeSpan.FromDays(30));
}
yield return request; yield return request;
} }
public Func<IDictionary<string, string>> GetCookies { get; set; }
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
} }
} }

@ -21,7 +21,7 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
public class PassThePopcornSettings : ITorrentIndexerSettings public class PassThePopcornSettings : ITorrentIndexerSettings
{ {
private static readonly PassThePopcornSettingsValidator Validator = new PassThePopcornSettingsValidator(); private static readonly PassThePopcornSettingsValidator Validator = new ();
public PassThePopcornSettings() public PassThePopcornSettings()
{ {

Loading…
Cancel
Save