From b3f6f54e6eccdd89d53ea0dda16b26c3c64a7f36 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 5 Nov 2023 20:53:21 +0200 Subject: [PATCH] Fixed: (PTP) Add support for TV searches --- .../PassThePopcorn/PassThePopcorn.cs | 15 ++----- .../PassThePopcornRequestGenerator.cs | 40 ++++++++++++++----- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Definitions/PassThePopcorn/PassThePopcorn.cs b/src/NzbDrone.Core/Indexers/Definitions/PassThePopcorn/PassThePopcorn.cs index 046e0e250..63b3cd5b2 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/PassThePopcorn/PassThePopcorn.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/PassThePopcorn/PassThePopcorn.cs @@ -29,7 +29,7 @@ namespace NzbDrone.Core.Indexers.Definitions.PassThePopcorn public override IIndexerRequestGenerator GetRequestGenerator() { - return new PassThePopcornRequestGenerator(Settings); + return new PassThePopcornRequestGenerator(Settings, Capabilities); } public override IParseIndexerResponse GetParser() @@ -56,18 +56,11 @@ namespace NzbDrone.Core.Indexers.Definitions.PassThePopcorn }; caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.Movies, "Feature Film"); - caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.MoviesForeign); - caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.MoviesOther); - caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD); - caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.MoviesHD); - caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.Movies3D); - caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.MoviesBluRay); - caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.MoviesDVD); - caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.MoviesWEBDL); caps.Categories.AddCategoryMapping(2, NewznabStandardCategory.Movies, "Short Film"); caps.Categories.AddCategoryMapping(3, NewznabStandardCategory.TV, "Miniseries"); - caps.Categories.AddCategoryMapping(4, NewznabStandardCategory.TV, "Stand-up Comedy"); - caps.Categories.AddCategoryMapping(5, NewznabStandardCategory.TV, "Live Performance"); + caps.Categories.AddCategoryMapping(4, NewznabStandardCategory.Movies, "Stand-up Comedy"); + caps.Categories.AddCategoryMapping(5, NewznabStandardCategory.Movies, "Live Performance"); + caps.Categories.AddCategoryMapping(6, NewznabStandardCategory.Movies, "Movie Collection"); return caps; } diff --git a/src/NzbDrone.Core/Indexers/Definitions/PassThePopcorn/PassThePopcornRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Definitions/PassThePopcorn/PassThePopcornRequestGenerator.cs index 116737e44..b88b793b2 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/PassThePopcorn/PassThePopcornRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/PassThePopcorn/PassThePopcornRequestGenerator.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.Specialized; +using System.Linq; using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.IndexerSearch.Definitions; @@ -11,10 +12,12 @@ namespace NzbDrone.Core.Indexers.Definitions.PassThePopcorn public class PassThePopcornRequestGenerator : IIndexerRequestGenerator { private readonly PassThePopcornSettings _settings; + private readonly IndexerCapabilities _capabilities; - public PassThePopcornRequestGenerator(PassThePopcornSettings settings) + public PassThePopcornRequestGenerator(PassThePopcornSettings settings, IndexerCapabilities capabilities) { _settings = settings; + _capabilities = capabilities; } public IndexerPageableRequestChain GetSearchRequests(MovieSearchCriteria searchCriteria) @@ -27,7 +30,7 @@ namespace NzbDrone.Core.Indexers.Definitions.PassThePopcorn } else { - pageableRequests.Add(GetRequest($"{searchCriteria.SearchTerm}", searchCriteria)); + pageableRequests.Add(GetRequest($"{searchCriteria.SanitizedSearchTerm}", searchCriteria)); } return pageableRequests; @@ -40,7 +43,11 @@ namespace NzbDrone.Core.Indexers.Definitions.PassThePopcorn public IndexerPageableRequestChain GetSearchRequests(TvSearchCriteria searchCriteria) { - return new IndexerPageableRequestChain(); + var pageableRequests = new IndexerPageableRequestChain(); + + pageableRequests.Add(GetRequest($"{searchCriteria.SanitizedTvSearchString}", searchCriteria)); + + return pageableRequests; } public IndexerPageableRequestChain GetSearchRequests(BookSearchCriteria searchCriteria) @@ -52,30 +59,41 @@ namespace NzbDrone.Core.Indexers.Definitions.PassThePopcorn { var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.Add(GetRequest($"{searchCriteria.SearchTerm}", searchCriteria)); + pageableRequests.Add(GetRequest($"{searchCriteria.SanitizedSearchTerm}", searchCriteria)); return pageableRequests; } - private IEnumerable GetRequest(string searchParameters, SearchCriteriaBase searchCriteria) + private IEnumerable GetRequest(string searchTerm, SearchCriteriaBase searchCriteria) { var parameters = new NameValueCollection { { "action", "advanced" }, { "json", "noredirect" }, { "grouping", "0" }, - { "searchstr", searchParameters } + { "searchstr", searchTerm } }; - if (searchCriteria.Limit is > 0 && searchCriteria.Offset is > 0) + if (_settings.FreeleechOnly) { - var page = (int)(searchCriteria.Offset / searchCriteria.Limit) + 1; - parameters.Set("page", page.ToString()); + parameters.Set("freetorrent", "1"); } - if (_settings.FreeleechOnly) + var queryCats = _capabilities.Categories + .MapTorznabCapsToTrackers(searchCriteria.Categories) + .Select(int.Parse) + .Distinct() + .ToList(); + + if (searchCriteria.IsRssSearch && queryCats.Any()) { - parameters.Set("freetorrent", "1"); + queryCats.ForEach(cat => parameters.Set($"filter_cat[{cat}]", "1")); + } + + if (searchCriteria.Limit is > 0 && searchCriteria.Offset is > 0) + { + var page = (int)(searchCriteria.Offset / searchCriteria.Limit) + 1; + parameters.Set("page", page.ToString()); } var searchUrl = $"{_settings.BaseUrl.Trim().TrimEnd('/')}/torrents.php?{parameters.GetQueryString()}";