Remove unsupported pagination for Nyaa

(cherry picked from commit fef525ddb8b5f91bb36b3c9e652663fccb098a00)

Closes #9582
This commit is contained in:
ilike2burnthing 2024-01-12 00:37:31 +00:00 committed by Bogdan
parent 0e7874aacf
commit 2c3ad380ef
2 changed files with 20 additions and 42 deletions

View File

@ -10,7 +10,6 @@ namespace NzbDrone.Core.Indexers.Nyaa
public override string Name => "Nyaa";
public override DownloadProtocol Protocol => DownloadProtocol.Torrent;
public override int PageSize => 100;
public Nyaa(IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger)
: base(httpClient, indexerStatusService, configService, parsingService, logger)
@ -19,7 +18,7 @@ namespace NzbDrone.Core.Indexers.Nyaa
public override IIndexerRequestGenerator GetRequestGenerator()
{
return new NyaaRequestGenerator() { Settings = Settings, PageSize = PageSize };
return new NyaaRequestGenerator() { Settings = Settings };
}
public override IParseIndexerResponse GetParser()

View File

@ -9,65 +9,44 @@ namespace NzbDrone.Core.Indexers.Nyaa
{
public NyaaSettings Settings { get; set; }
public int MaxPages { get; set; }
public int PageSize { get; set; }
public NyaaRequestGenerator()
{
MaxPages = 30;
PageSize = 100;
}
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests(MaxPages, null));
pageableRequests.Add(GetPagedRequests(null));
return pageableRequests;
}
private IEnumerable<IndexerRequest> GetPagedRequests(int maxPages, string term)
{
var baseUrl = string.Format("{0}/?page=rss{1}", Settings.BaseUrl.TrimEnd('/'), Settings.AdditionalParameters);
if (term != null)
{
baseUrl += "&term=" + term;
}
if (PageSize == 0)
{
yield return new IndexerRequest(baseUrl, HttpAccept.Rss);
}
else
{
yield return new IndexerRequest(baseUrl, HttpAccept.Rss);
for (var page = 1; page < maxPages; page++)
{
yield return new IndexerRequest($"{baseUrl}&offset={page + 1}", HttpAccept.Rss);
}
}
}
private string PrepareQuery(string query)
{
return query.Replace(' ', '+');
}
public IndexerPageableRequestChain GetSearchRequests(MovieSearchCriteria searchCriteria)
{
var pageableRequests = new IndexerPageableRequestChain();
foreach (var queryTitle in searchCriteria.SceneTitles)
{
pageableRequests.Add(GetPagedRequests(MaxPages, PrepareQuery(string.Format("{0} {1}", queryTitle, searchCriteria.Movie.Year))));
pageableRequests.Add(GetPagedRequests(PrepareQuery($"{queryTitle} {searchCriteria.Movie.Year}")));
}
return pageableRequests;
}
private IEnumerable<IndexerRequest> GetPagedRequests(string term)
{
var baseUrl = $"{Settings.BaseUrl.TrimEnd('/')}/?page=rss{Settings.AdditionalParameters}";
if (term != null)
{
baseUrl += "&term=" + term;
}
yield return new IndexerRequest(baseUrl, HttpAccept.Rss);
}
private string PrepareQuery(string query)
{
return query.Replace(' ', '+');
}
public Func<IDictionary<string, string>> GetCookies { get; set; }
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
}