From 1762a189d2ef7e3e383b1a8b7d2dd059cea36ed8 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Mon, 2 Oct 2023 03:38:24 +0300 Subject: [PATCH] Fixed: (PassThePopcorn) Disable grouping --- .../IndexerTests/PTPTests/PTPFixture.cs | 17 ++---- .../Indexers/PassThePopcorn/PassThePopcorn.cs | 9 +-- .../PassThePopcorn/PassThePopcornApi.cs | 55 ++++++------------- .../PassThePopcorn/PassThePopcornParser.cs | 26 ++------- .../PassThePopcornRequestGenerator.cs | 35 ++++-------- .../PassThePopcorn/PassThePopcornSettings.cs | 2 +- 6 files changed, 43 insertions(+), 101 deletions(-) diff --git a/src/NzbDrone.Core.Test/IndexerTests/PTPTests/PTPFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/PTPTests/PTPFixture.cs index cc9864f06..5f01a1886 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/PTPTests/PTPFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/PTPTests/PTPFixture.cs @@ -6,7 +6,6 @@ using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common.Http; -using NzbDrone.Common.Serializer; using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers.PassThePopcorn; using NzbDrone.Core.Parser.Model; @@ -20,26 +19,22 @@ namespace NzbDrone.Core.Test.IndexerTests.PTPTests [SetUp] public void Setup() { - Subject.Definition = new IndexerDefinition() + Subject.Definition = new IndexerDefinition { Name = "PTP", - Settings = new PassThePopcornSettings() { APIUser = "asdf", APIKey = "sad" } + Settings = new PassThePopcornSettings + { + APIUser = "asdf", + APIKey = "sad" + } }; } [TestCase("Files/Indexers/PTP/imdbsearch.json")] 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); - Mocker.GetMock() - .Setup(o => o.ExecuteAsync(It.Is(v => v.Method == HttpMethod.Post))) - .Returns(r => Task.FromResult(new HttpResponse(r, new HttpHeader(), authStream.ToString()))); - Mocker.GetMock() .Setup(o => o.ExecuteAsync(It.Is(v => v.Method == HttpMethod.Get))) .Returns(r => Task.FromResult(new HttpResponse(r, new HttpHeader { ContentType = HttpAccept.Json.Value }, responseJson))); diff --git a/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcorn.cs b/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcorn.cs index 786747f63..e81991eb4 100644 --- a/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcorn.cs +++ b/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcorn.cs @@ -1,5 +1,4 @@ using NLog; -using NzbDrone.Common.Cache; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.Parser; @@ -15,7 +14,6 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn public override int PageSize => 50; public PassThePopcorn(IHttpClient httpClient, - ICacheManager cacheManager, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, @@ -26,12 +24,7 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn public override IIndexerRequestGenerator GetRequestGenerator() { - return new PassThePopcornRequestGenerator() - { - Settings = Settings, - HttpClient = _httpClient, - Logger = _logger, - }; + return new PassThePopcornRequestGenerator(Settings); } public override IParseIndexerResponse GetParser() diff --git a/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornApi.cs b/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornApi.cs index 4ff21e026..c9a591be1 100644 --- a/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornApi.cs +++ b/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornApi.cs @@ -3,13 +3,27 @@ using System.Collections.Generic; namespace NzbDrone.Core.Indexers.PassThePopcorn { - public class Director + public class PassThePopcornResponse { - public string Name { get; set; } - public string Id { get; set; } + public string TotalResults { get; set; } + public List 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 Tags { get; set; } + public string ImdbId { get; set; } + public List Torrents { get; set; } + } + + public class PassThePopcornTorrent { public int Id { get; set; } public string Quality { get; set; } @@ -29,37 +43,4 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn public bool GoldenPopcorn { 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 Tags { get; set; } - public List 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 Torrents { get; set; } - } - - public class PassThePopcornResponse - { - public string TotalResults { get; set; } - public List 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; } - } } diff --git a/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornParser.cs b/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornParser.cs index 8040f8cbe..a304b11b0 100644 --- a/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornParser.cs +++ b/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornParser.cs @@ -26,26 +26,11 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn 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"); } 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}"); } @@ -62,17 +47,16 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn foreach (var torrent in result.Torrents) { var id = torrent.Id; - var title = torrent.ReleaseName; IndexerFlags flags = 0; if (torrent.GoldenPopcorn) { - flags |= IndexerFlags.PTP_Golden; // title = $"{title} 🍿"; + flags |= IndexerFlags.PTP_Golden; } if (torrent.Checked) { - flags |= IndexerFlags.PTP_Approved; // title = $"{title} ✔"; + flags |= IndexerFlags.PTP_Approved; } if (torrent.FreeleechType == "Freeleech") @@ -88,10 +72,10 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn // Only add approved torrents try { - torrentInfos.Add(new PassThePopcornInfo() + torrentInfos.Add(new PassThePopcornInfo { - Guid = string.Format("PassThePopcorn-{0}", id), - Title = title, + Guid = $"PassThePopcorn-{id}", + Title = torrent.ReleaseName, Size = long.Parse(torrent.Size), DownloadUrl = GetDownloadUrl(id, jsonResponse.AuthKey, jsonResponse.PassKey), InfoUrl = GetInfoUrl(result.GroupId, id), diff --git a/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornRequestGenerator.cs b/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornRequestGenerator.cs index aa3f59327..a8a053c75 100644 --- a/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornRequestGenerator.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using NLog; using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.IndexerSearch.Definitions; @@ -9,12 +8,12 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn { public class PassThePopcornRequestGenerator : IIndexerRequestGenerator { - public PassThePopcornSettings Settings { get; set; } + private readonly PassThePopcornSettings _settings; - public IDictionary Cookies { get; set; } - - public IHttpClient HttpClient { get; set; } - public Logger Logger { get; set; } + public PassThePopcornRequestGenerator(PassThePopcornSettings settings) + { + _settings = settings; + } public virtual IndexerPageableRequestChain GetRecentRequests() { @@ -37,37 +36,27 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn { 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; } - public Func> GetCookies { get; set; } - public Action, DateTime?> CookiesUpdater { get; set; } - private IEnumerable GetRequest(string searchParameters) { var request = 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); - request.HttpRequest.Headers["ApiUser"] = Settings.APIUser; - request.HttpRequest.Headers["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)); - } + request.HttpRequest.Headers.Add("ApiUser", _settings.APIUser); + request.HttpRequest.Headers.Add("ApiKey", _settings.APIKey); yield return request; } + + public Func> GetCookies { get; set; } + public Action, DateTime?> CookiesUpdater { get; set; } } } diff --git a/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornSettings.cs b/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornSettings.cs index 96a8000b5..c969eb9b4 100644 --- a/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornSettings.cs +++ b/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornSettings.cs @@ -21,7 +21,7 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn public class PassThePopcornSettings : ITorrentIndexerSettings { - private static readonly PassThePopcornSettingsValidator Validator = new PassThePopcornSettingsValidator(); + private static readonly PassThePopcornSettingsValidator Validator = new (); public PassThePopcornSettings() {