salsa

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2022 License: MIT Imports: 18 Imported by: 0

README

salsa

A modern and powerful client for Saucenao written in go.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrOptions represents an error that occurs when the options provided by
	// the user contains invalid values.
	ErrOptions = errors.New("provided options are not valid")
	// ErrIteratorFinished specifies that the iterator arrived at the end of
	// its internal list and thus could not retrieve any more results.
	ErrIteratorFinished = errors.New("iterator has finished")
	// ErrUknownIndex is returned when the provided or returned index is not
	// known or supported.
	ErrUknownIndex = errors.New("unknown or unsupported index")
	// ErrServerSide is returned when the request for source was successfully
	// sent but could not complete because of a server side error.
	ErrServerSide = errors.New("server side error")
	// ErrClientSide is returned when the request for source was successfully
	// sent but could not complete because of an error on user's request.
	ErrClientSide = errors.New("client side error")
)

Functions

This section is empty.

Types

type AccountType

type AccountType int

AccountType defines the type of the account of the Saucenao user making the request.

const (
	// Unknown account type.
	Unknown AccountType = iota - 1
	// AnonymousAccount defines that the user is not logged.
	AnonymousAccount
	// NormalAccount specifies that the user is logged.
	NormalAccount
	// PremiumAccount specifies that the user is logged and has a premium
	// subscription.
	PremiumAccount
)

type Client

type Client interface {
	// GetSauceForFile tries to get source for a local file.
	//
	// The response from Saucenao is returned *only* if the provided request
	// options are valid. Otherwise the response is always present.
	// Users should *always* check for errors before accessing the response.
	// See examples for this.
	GetSauceForFile(context.Context, string, ...RequestOption) (*Response, error)
	// GetSauceForURL tries to get source for a remote picture.
	//
	// The response from Saucenao is returned *only* if the provided request
	// options are valid. Otherwise the response is always present.
	// Users should *always* check for errors before accessing the response.
	// See examples for this.
	GetSauceForURL(context.Context, string, ...RequestOption) (*Response, error)
}

Client is an interface for communicating with Saucenao and querying for source for a local or remote image .

type RequestOption

type RequestOption func(*RequestOptions)

RequestOption adds an option to the request.

func WithHTTPClient

func WithHTTPClient(client *http.Client) RequestOption

WithHTTPClient sets a custom HTTP Client instead of the new one.

func WithIndex

func WithIndex(index indexes.Index) RequestOption

WithIndex modifies the index to look for.

func WithMinimumSimilarity

func WithMinimumSimilarity(minimum int) RequestOption

WithMinimumSimilarity tells Saucenao to filter results that have a similarity lower than the one provided.

func WithResultsNumber

func WithResultsNumber(num int) RequestOption

WithResultsNumber sets the maximum number of the results.

func WithSafetyLevel

func WithSafetyLevel(mode SafetyLevel) RequestOption

WithSafetyLevel sets the safety level for this request.

func WithTestMode

func WithTestMode() RequestOption

WithTestMode sets test mode to true. Use this only when testing.

type RequestOptions

type RequestOptions struct {

	// ResultsNumber specifies the maximum number of results to return.
	// Default is 6.
	ResultsNumber int
	// Test mode specifies whether to enable test mode. Read Saucenao
	// documentation to learn more about this. Default is false.
	TestMode bool
	// DB specifies the index where to search for. Default is ALL.
	DB indexes.Index
	// HttpClient to use. Use this in case you want to have custom http
	// options.
	HttpClient *http.Client
	// MinimumSimilarity specifies the minimum similarity for the results.
	// Default is 55.
	MinimumSimilarity int
	// SafetyLevel specifies whether to filter explicit or suspected explicit
	// results. Default level is ShowAll.
	SafetyLevel SafetyLevel
	// contains filtered or unexported fields
}

RequestOptions contains options to include with the request.

type Response

type Response struct {
	// UserID is the ID of the user logged to Saucenao.
	UserID int
	// AccountType defines the type of the account of the logged user.
	AccountType AccountType
	// ShortLimit defines the limit of requests that the user can perform
	// every 30 seconds. (This may change in future: refer to Saucenao account)
	// section.
	ShortLimit int
	// LongLimit defines the limit of requests that the user can perform
	// every 24 hours. (This may change in future: refer to Saucenao account)
	// section.
	LongLimit int
	// ShortRemaining defines how many requests the user can perform before
	// stopping for -- at least -- 30 seconds. Check this before performing any
	// other requests.
	ShortRemaining int
	// LongRemaining defines how many requests the user can perform before
	// stopping for -- at least -- 24 hours.
	LongRemaining int
	// ResultsRequested defines how many results were requested by the user.
	ResultsRequested int
	// ResultsReturned defines the number of results returned by the request.
	ResultsReturned int
	// SearchDepth...
	// TODO
	SearchDepth float64
	// MinimumSimilarity defines the minimum similarity found.
	// TODO: or is it the one requested?
	MinimumSimilarity float64
	// QueryImage is a thumbnail for the requested image.
	QueryImage string
	// QueryImageDisplay...
	// TODO
	QueryImageDisplay string
	// Results is an iterator with all the results returned by Saucenao.
	Results *ResultsIterator
	// contains filtered or unexported fields
}

Response is the response sent by Saucenao and parsed and cleaned by salsa.

func (*Response) CanPerformMoreCalls

func (r *Response) CanPerformMoreCalls() bool

type ResultsIterator

type ResultsIterator struct {
	// contains filtered or unexported fields
}

ResultsIterator is an iterator with all the results returned by Saucenao.

func (*ResultsIterator) Next

func (r *ResultsIterator) Next() (sauces.Sauce, error)

Next returns the next result from the list of results returned by Saucenao. You should always check the error before checking the item.

Cast the source to the appropriate structure by checking the second returned parameter. TODO: make examples.

type SafetyLevel

type SafetyLevel int

SafetyLevel is the level of the

const (
	// ShowAll specifies the all results should be returned.
	ShowAll SafetyLevel = iota
	// HideExpectedExplicit tells Saucenao to hide results that are expected
	// to be explicit.
	HideExpectedExplicit
	// HideExpectedAndSuspectedExplicit is exactly like HideExpectedExplicit
	// but it also hides results that are suspected to be explicit.
	HideExpectedAndSuspectedExplicit
	// Safest only shows safe results.
	Safest
)

type SauceClient

type SauceClient struct {
	// contains filtered or unexported fields
}

SauceClient is an implementation of the Client interface for connecting to Saucenao and query for source to a picture.

func NewSauceClient

func NewSauceClient(apiKey string, defaultOptions ...RequestOption) (*SauceClient, error)

NewSauceClient returns an instance for the Client.

An API key *must* be provided in order to have a valid client, otherwise an error will be returned and the client returned will be nil. Optionally a list of options can be provided which will be included with each call. An error will be returned if provided options are not valid and a nil client will be returned.

func (*SauceClient) GetSauceForFile

func (c *SauceClient) GetSauceForFile(ctx context.Context, imagepath string, opts ...RequestOption) (*Response, error)

GetSauceForFile tries to get source for a local file.

The response from Saucenao is returned *only* if the provided request options are valid. Otherwise the response is always present. Users should *always* check for errors before accessing the response. See examples for this.

func (*SauceClient) GetSauceForURL

func (c *SauceClient) GetSauceForURL(ctx context.Context, url string, opts ...RequestOption) (*Response, error)

NewSauceClient returns an instance for the Client.

An API key *must* be provided in order to have a valid client, otherwise an error will be returned and the client returned will be nil. Optionally a list of options can be provided which will be included with each call. An error will be returned if provided options are not valid and a nil client will be returned.

Directories

Path Synopsis
Package indexes contains definitions of the indexes to be used with Saucenao.
Package indexes contains definitions of the indexes to be used with Saucenao.
Package sauces contains definitions for the source of an image found by Saucenao.
Package sauces contains definitions for the source of an image found by Saucenao.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL