1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-20 18:02:44 +01:00

Fixed: (PassThePopcorn) Disable grouping

This commit is contained in:
Bogdan 2023-10-02 03:38:24 +03:00
parent e2f5f2f73a
commit 1762a189d2
6 changed files with 43 additions and 101 deletions

View File

@ -6,7 +6,6 @@
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 @@ public class PTPFixture : CoreTest<PassThePopcorn>
[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<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>()
.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)));

View File

@ -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 @@ public class PassThePopcorn : HttpIndexerBase<PassThePopcornSettings>
public override int PageSize => 50;
public PassThePopcorn(IHttpClient httpClient,
ICacheManager cacheManager,
IIndexerStatusService indexerStatusService,
IConfigService configService,
IParsingService parsingService,
@ -26,12 +24,7 @@ public PassThePopcorn(IHttpClient httpClient,
public override IIndexerRequestGenerator GetRequestGenerator()
{
return new PassThePopcornRequestGenerator()
{
Settings = Settings,
HttpClient = _httpClient,
Logger = _logger,
};
return new PassThePopcornRequestGenerator(Settings);
}
public override IParseIndexerResponse GetParser()

View File

@ -3,13 +3,27 @@
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<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 string Quality { get; set; }
@ -29,37 +43,4 @@ public class Torrent
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<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; }
}
}

View File

@ -26,26 +26,11 @@ public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
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 @@ public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
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 @@ public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
// 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),

View File

@ -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<string, string> 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 @@ public IndexerPageableRequestChain GetSearchRequests(MovieSearchCriteria searchC
{
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<IDictionary<string, string>> GetCookies { get; set; }
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
private IEnumerable<IndexerRequest> 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<IDictionary<string, string>> GetCookies { get; set; }
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
}
}

View File

@ -21,7 +21,7 @@ public PassThePopcornSettingsValidator()
public class PassThePopcornSettings : ITorrentIndexerSettings
{
private static readonly PassThePopcornSettingsValidator Validator = new PassThePopcornSettingsValidator();
private static readonly PassThePopcornSettingsValidator Validator = new ();
public PassThePopcornSettings()
{