image

package
v0.0.0-...-c5d5a31 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EXIF

type EXIF struct {
	Copyright string `json:"copyright,omitempty"`
}

EXIF is the metadata of an image What other fields do we need???

type ElasticSearch

type ElasticSearch struct {
	Client        *elastic.Client
	Index         string
	Type          string
	Bulk          *elastic.BulkProcessor
	NSFWThreshold float64
}

ElasticSearch hold connection and index settings

func (*ElasticSearch) Fetch

func (e *ElasticSearch) Fetch(q string, safe bool, number int, offset int) (*Results, error)

Fetch returns image results for a search query

func (*ElasticSearch) Setup

func (e *ElasticSearch) Setup() error

Setup will create our image index

func (*ElasticSearch) Uncrawled

func (e *ElasticSearch) Uncrawled(number int, since time.Time) ([]*Image, error)

Uncrawled finds images that haven't been crawled recently/yet We also aggregate by domain, which is equivalent to selecting unique domains so that we don't overload a domain. The subaggregation will then return 1 result for each domain.

func (*ElasticSearch) Upsert

func (e *ElasticSearch) Upsert(img *Image) error

Upsert updates an image link or inserts it if it doesn't exist NOTE: Elasticsearch has a 512-byte limit on an insert operation. Upsert does not have that limit.

type Fetcher

type Fetcher interface {
	Fetch(q string, safe bool, number int, offset int) (*Results, error)
}

Fetcher outlines the methods used to retrieve the image results

type Image

type Image struct {
	ID     string  `json:"id"`
	Domain string  `json:"domain"`
	Alt    string  `json:"alt,omitempty"`
	NSFW   float64 `json:"nsfw_score,omitempty"`
	Width  int     `json:"width,omitempty"`
	Height int     `json:"height,omitempty"`
	EXIF
	Classification map[string]float64 `json:"classification,omitempty"`
	MIME           string             `json:"mime,omitempty"`
	Crawled        string             `json:"crawled,omitempty"`
	Base64         string             `json:"base64,omitempty"`
}

Image is a link to an image

func New

func New(src string) (*Image, error)

New creates a new *Image and validates the url

func (*Image) SimplifyMIME

func (i *Image) SimplifyMIME() *Image

SimplifyMIME strips unnecessary info from MIME image/jpg -> jpg

type Pixabay

type Pixabay struct {
	Key        string
	HTTPClient *http.Client
}

Pixabay holds settings for the Pixabay image search API

func (*Pixabay) Fetch

func (p *Pixabay) Fetch(query string, safe bool, number int, offset int) (*Results, error)

Fetch returns image results for a search query

type PixabayResponse

type PixabayResponse struct {
	TotalHits int64 `json:"totalHits"`
	Hits      []struct {
		LargeImageURL   string `json:"largeImageURL"`
		WebformatHeight int    `json:"webformatHeight"`
		WebformatWidth  int    `json:"webformatWidth"`
		Likes           int    `json:"likes"`
		ImageWidth      int    `json:"imageWidth"`
		ID              int    `json:"id"`
		UserID          int    `json:"user_id"`
		Views           int    `json:"views"`
		Comments        int    `json:"comments"`
		PageURL         string `json:"pageURL"`
		ImageHeight     int    `json:"imageHeight"`
		WebformatURL    string `json:"webformatURL"`
		Type            string `json:"type"`
		PreviewHeight   int    `json:"previewHeight"`
		Tags            string `json:"tags"`
		Downloads       int64  `json:"downloads"`
		User            string `json:"user"`
		Favorites       int    `json:"favorites"`
		ImageSize       int64  `json:"imageSize"`
		PreviewWidth    int    `json:"previewWidth"`
		UserImageURL    string `json:"userImageURL"`
		PreviewURL      string `json:"previewURL"`
	} `json:"hits"`
	Total int64 `json:"total"`
}

PixabayResponse is the raw API response from Pixabay

type Provider

type Provider string

Provider is an image source

const PixabayProvider Provider = "Pixabay"

PixabayProvider is an image provider

type Results

type Results struct {
	Provider   Provider
	Count      int64    `json:"count"`
	Page       string   `json:"page"`
	Previous   string   `json:"previous"`
	Next       string   `json:"next"`
	Last       string   `json:"last"`
	Pagination []string `json:"pagination"`
	Images     []*Image `json:"images"`
}

Results are the image results from a query

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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