@ -12,23 +12,35 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz
public class AvistazRequestGenerator : IIndexerRequestGenerator
{
public AvistazSettings Settings { get ; set ; }
public IIndexerHttpClient HttpClient { get ; set ; }
public IndexerCapabilities Capabilities { get ; set ; }
public int PageSize { get ; set ; }
public IIndexerHttpClient HttpClient { get ; set ; }
public Logger Logger { get ; set ; }
public Func < IDictionary < string , string > > GetCookies { get ; set ; }
public Action < IDictionary < string , string > , DateTime ? > CookiesUpdater { get ; set ; }
protected virtual string SearchUrl = > Settings . BaseUrl + "api/v1/jackett/torrents" ;
// hook to adjust the search category
protected virtual List < KeyValuePair < string , string > > GetBasicSearchParameters ( int [ ] categories , string genre )
protected virtual List < KeyValuePair < string , string > > GetBasicSearchParameters ( SearchCriteriaBase searchCriteria , string genre = null )
{
var categories = searchCriteria . Categories ? ? Array . Empty < int > ( ) ;
var categoryMapping = Capabilities . Categories . MapTorznabCapsToTrackers ( categories ) . Distinct ( ) . ToList ( ) ;
var qc = new List < KeyValuePair < string , string > > // NameValueCollection don't support cat[]=19&cat[]=6
{
{ "in" , "1" } ,
{ "type" , categoryMapping . Any ( ) ? categoryMapping . First ( ) : "0" }
{ "type" , categoryMapping . FirstIfSingleOrDefault ( "0" ) } ,
{ "limit" , Math . Min ( PageSize , searchCriteria . Limit . GetValueOrDefault ( PageSize ) ) . ToString ( ) }
} ;
if ( searchCriteria . Limit is > 0 & & searchCriteria . Offset is > 0 )
{
var page = ( int ) ( searchCriteria . Offset / searchCriteria . Limit ) + 1 ;
qc . Add ( "page" , page . ToString ( ) ) ;
}
if ( Settings . FreeleechOnly )
{
qc . Add ( "discount[]" , "1" ) ;
@ -78,7 +90,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz
public IndexerPageableRequestChain GetSearchRequests ( MovieSearchCriteria searchCriteria )
{
var parameters = GetBasicSearchParameters ( searchCriteria .Categories , searchCriteria . Genre ) ;
var parameters = GetBasicSearchParameters ( searchCriteria , searchCriteria . Genre ) ;
if ( searchCriteria . ImdbId . IsNotNullOrWhiteSpace ( ) )
{
@ -100,7 +112,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz
public IndexerPageableRequestChain GetSearchRequests ( MusicSearchCriteria searchCriteria )
{
var parameters = GetBasicSearchParameters ( searchCriteria .Categories , null );
var parameters = GetBasicSearchParameters ( searchCriteria );
parameters . Add ( "search" , GetSearchTerm ( searchCriteria . SanitizedSearchTerm ) . Trim ( ) ) ;
@ -111,7 +123,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz
public IndexerPageableRequestChain GetSearchRequests ( TvSearchCriteria searchCriteria )
{
var parameters = GetBasicSearchParameters ( searchCriteria .Categories , searchCriteria . Genre ) ;
var parameters = GetBasicSearchParameters ( searchCriteria , searchCriteria . Genre ) ;
if ( searchCriteria . ImdbId . IsNotNullOrWhiteSpace ( ) )
{
@ -135,7 +147,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz
public IndexerPageableRequestChain GetSearchRequests ( BookSearchCriteria searchCriteria )
{
throw new NotImplementedExceptio n( ) ;
return new IndexerPageableRequestChai n( ) ;
}
// hook to adjust the search term
@ -143,7 +155,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz
public IndexerPageableRequestChain GetSearchRequests ( BasicSearchCriteria searchCriteria )
{
var parameters = GetBasicSearchParameters ( searchCriteria .Categories , null );
var parameters = GetBasicSearchParameters ( searchCriteria );
parameters . Add ( "search" , GetSearchTerm ( searchCriteria . SanitizedSearchTerm ) . Trim ( ) ) ;