sengoku

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2021 License: MIT Imports: 11 Imported by: 2

README

sengoku

FOSSA Status PkgGoDev

A simple SauceNAO Go wrapper.
Inspired by Sagiri, a SauceNAO wrapper for NodeJS.

Installation

Add sengoku to your go.mod file

module github.com/x/y

go 1.15

require(
    github.com/VTGare/sengoku latest
)

or go get -u github.com/VTGare/sengoku

Examples

func main() {
    sen := sengoku.NewSengoku(os.Getenv("SAUCENAO_APITOKEN"))
    uri := "https://imgur.com/someimage.png"
    
    //Search using an image URL with a default query.
    sauce := sen.Search(uri)

    //Search with a different query.
    sauce := sen.SearchWithConfig(uri, &sengoku.Config{DB: sengoku.Pixiv, Results: 1})
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrLongLimitReached is an error returned by SauceNAO when daily limit has been reached.
	ErrLongLimitReached = errors.New("24 hours rate limit reached")
	//ErrShortLimitReached is an error returned by SauceNAO when 30 seconds limit has been reached.
	ErrShortLimitReached = errors.New("30 seconds rate limit reached")
	//ErrRateLimitReached is a genenal rate limit error if unable to decide which limit has been reached.
	ErrRateLimitReached = errors.New("Rate limit reached")
	//ErrInvalidAPIKey is an error thrown when provided API key is incorrect. Either when status code is 403 or user_id header equals 0
	ErrInvalidAPIKey = errors.New("Invalid API key")
	//ErrFileTooLarge is an error thrown when SauceNAO returns 413
	ErrFileTooLarge = errors.New("File is too large")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	APIKey   string
	DB       DB
	TestMode bool
	Results  int
}

Config is a SauceNAO API call configuration structure.

APIKEy is an API token used on requests.

DB searches a specific database index without having to generate a mask.

TestMode causes each index that has a match for the given image to output at most 1 result. Useful for testing some things.

Results controls how many results are returned from SauceNAO.

IncludeMask is an array of the only database indices you want returned from SauceNAO. A mask of [5] would only return results from Pixiv.

ExcludeMask is an opposite of IncludeMask, a mask of [5] would return results from anywhere but Pixiv.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default Config configuration.

type DB

type DB int
const (
	HMagazines        DB = 0
	HGameCG           DB = 2
	DoujinshiDB       DB = 3
	Pixiv             DB = 5
	PixivHistorical   DB = 6
	NicoNicoSeiga     DB = 8
	Danbooru          DB = 9
	Drawr             DB = 10
	Nijie             DB = 11
	Yandere           DB = 12
	Openingsmoe       DB = 13
	Shutterstock      DB = 15
	FAKKU             DB = 16
	HMisc             DB = 18
	TwoDMarket        DB = 19
	MediBang          DB = 20
	Anime             DB = 21
	HAnime            DB = 22
	Movies            DB = 23
	Shows             DB = 24
	Gelbooru          DB = 25
	Konachan          DB = 26
	SankakuChannel    DB = 27
	AnimePicturesnet  DB = 28
	E621net           DB = 29
	IdolComplex       DB = 30
	BcynetIllust      DB = 31
	BcynetCosplay     DB = 32
	PortalGraphicsnet DB = 33
	DeviantArt        DB = 34
	Pawoonet          DB = 35
	Madokami          DB = 36
	MangaDex          DB = 37
	HMiscEHentai      DB = 38
	Artstation        DB = 39
	FurAffinity       DB = 40
	All               DB = 999
)

type Result

type Result struct {
	Data   *ResultData   `json:"data,omitempty"`
	Header *ResultHeader `json:"header,omitempty"`
}

type ResultData

type ResultData struct {
	ExternalURLs []string    `json:"ext_urls,omitempty"`
	Title        string      `json:"title,omitempty"`
	DaID         interface{} `json:"da_id,omitempty"`
	Author       string      `json:"author,omitempty"`
	AuthorName   string      `json:"author_name,omitempty"`
	AuthorURL    string      `json:"author_url,omitempty"`
	AnidbAid     interface{} `json:"anidb_aid,omitempty"`
	Artist       string      `json:"artist,omitempty"`
	BcyID        interface{} `json:"bcy_id,omitempty"`
	BcyType      string      `json:"bcy_type,omitempty"`
	DanbooruID   interface{} `json:"danbooru_id,omitempty"`
	DdbID        interface{} `json:"ddb_id,omitempty"`
	DrawrID      interface{} `json:"drawr_id,omitempty"`
	Creator      interface{} `json:"creator,omitempty"`
	EngName      string      `json:"eng_name,omitempty"`
	E621ID       interface{} `json:"e621_id,omitempty"`
	File         string      `json:"file,omitempty"`
	GelbooruID   interface{} `json:"gelbooru_id,omitempty"`
	IdolID       interface{} `json:"idol_id,omitempty"`
	ImdbID       interface{} `json:"imdb_id,omitempty"`
	JpName       string      `json:"jp_name,omitempty"`
	KonachanID   interface{} `json:"konachan_id,omitempty"`
	Material     string      `json:"material,omitempty"`
	MemberLinkID interface{} `json:"member_link_id,omitempty"`
	MuID         interface{} `json:"mu_id,omitempty"`
	NijieID      interface{} `json:"nijie_id,omitempty"`
	Part         string      `json:"part,omitempty"`
	PawooID      interface{} `json:"pawoo_id,omitempty"`
	PgID         interface{} `json:"pg_id,omitempty"`
	PixivID      interface{} `json:"pixiv_id,omitempty"`
	SankakuID    interface{} `json:"sankaku_id,omitempty"`
	SeigaID      interface{} `json:"seiga_id,omitempty"`
	Source       string      `json:"source,omitempty"`
	URL          string      `json:"url,omitempty"`
	UserAcct     string      `json:"user_acct,omitempty"`
	YandereID    interface{} `json:"yandere_id,omitempty"`
	MemberID     interface{} `json:"member_id,omitempty"`
	MemberName   string      `json:"member_name,omitempty"`
}

type ResultHeader

type ResultHeader struct {
	IndexID    int    `json:"index_id,omitempty"`
	IndexName  string `json:"index_name,omitempty"`
	Similarity string `json:"similarity,omitempty"`
	Thumbnail  string `json:"thumbnail,omitempty"`
}

type Sauce

type Sauce struct {
	Title      string
	Thumbnail  string
	Similarity float64
	Author     *SauceAuthor
	URLs       *SauceURLs
	Pretty     bool
	Raw        *Result
}

Sauce is an abstaction over SauceNAO response. If Pretty is false, then all fields except Raw are default.

type SauceAuthor

type SauceAuthor struct {
	Name string
	URL  string
}

SauceAuthor contains information about art's author

type SauceURLs

type SauceURLs struct {
	Source       string
	ExternalURLs []string
}

SauceURLs contains all possible URLs from a response.

type Sengoku

type Sengoku struct {
	DefaultConfig *Config
	// contains filtered or unexported fields
}

Sengoku is a SauceNAO API wrapper.

func NewSengoku

func NewSengoku(apikey string, config ...Config) *Sengoku

NewSengoku creates a new Sengoku application instance.

func (*Sengoku) Search

func (s *Sengoku) Search(imageURL string) ([]*Sauce, error)

Search performs a SauceNAO API call with a given image URL.

func (*Sengoku) SearchWithConfig

func (s *Sengoku) SearchWithConfig(imageURL string, config *Config) ([]*Sauce, error)

SearchWithConfig performs a SauceNAO API call with a given URL and custom configuration. If API key is empty in given configuration it will try to use default API key.

Jump to

Keyboard shortcuts

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