Add Paging to Waffles Requests (#39)

* Add Paging to Waffles Requests
* Make pages dynamic variable to match others
This commit is contained in:
Qstick 2017-08-17 20:30:44 -04:00 committed by GitHub
parent 337f74a184
commit 4f61354dc5
1 changed files with 15 additions and 6 deletions

View File

@ -10,12 +10,18 @@ namespace NzbDrone.Core.Indexers.Waffles
public class WafflesRequestGenerator : IIndexerRequestGenerator
{
public WafflesSettings Settings { get; set; }
public int MaxPages { get; set; }
public WafflesRequestGenerator()
{
MaxPages = 5;
}
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests(null));
pageableRequests.Add(GetPagedRequests(MaxPages, null));
return pageableRequests;
}
@ -54,7 +60,7 @@ namespace NzbDrone.Core.Indexers.Waffles
{
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests(string.Format("&q=artist:{0} album:{1}",searchCriteria.Artist.Name,searchCriteria.AlbumTitle)));
pageableRequests.Add(GetPagedRequests(MaxPages, string.Format("&q=artist:{0} album:{1}",searchCriteria.Artist.Name,searchCriteria.AlbumTitle)));
return pageableRequests;
}
@ -63,12 +69,12 @@ namespace NzbDrone.Core.Indexers.Waffles
{
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests(string.Format("&q=artist:{0}", searchCriteria.Artist.Name)));
pageableRequests.Add(GetPagedRequests(MaxPages, string.Format("&q=artist:{0}", searchCriteria.Artist.Name)));
return pageableRequests;
}
private IEnumerable<IndexerRequest> GetPagedRequests(string query)
private IEnumerable<IndexerRequest> GetPagedRequests(int maxPages, string query)
{
var url = new StringBuilder();
@ -80,7 +86,10 @@ namespace NzbDrone.Core.Indexers.Waffles
url.AppendFormat(query);
}
yield return new IndexerRequest(url.ToString(), HttpAccept.Rss);
for (var page = 0; page < maxPages; page++)
{
yield return new IndexerRequest(string.Format("{0}&p={1}", url, page), HttpAccept.Rss);
}
}
}
}