source

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CategoryBits

func CategoryBits(cats string) string

CategoryBits is the exported wrapper around categoryBits for testing.

func ParseResolution

func ParseResolution(res string) (int, int, bool)

ParseResolution parses a "WxH" resolution string and returns the width, height and whether the parse succeeded.

Types

type Bing

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

Bing is a Source adapter that fetches the Bing daily wallpapers.

func NewBing

func NewBing() *Bing

NewBing creates a Bing adapter.

func NewBingWithBase

func NewBingWithBase(baseURL string) *Bing

NewBingWithBase creates a Bing adapter with a custom base URL for testing.

func (*Bing) Categories

func (b *Bing) Categories() []string

Categories returns the categories supported by Bing. Bing has no categories.

func (*Bing) Name

func (b *Bing) Name() string

Name returns the unique slug for this source.

func (*Bing) NeedsKey

func (b *Bing) NeedsKey() bool

NeedsKey reports whether an API key is required. Bing does not.

func (*Bing) Search

func (b *Bing) Search(opts SearchOpts) ([]WallpaperResult, error)

Search fetches daily wallpapers from Bing. The query in opts is intentionally ignored — Bing always returns its curated daily images.

func (*Bing) SearchTotal

func (b *Bing) SearchTotal(_ SearchOpts) (int, error)

SearchTotal returns 8 — Bing always has up to 8 daily wallpapers.

type Reddit

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

Reddit is a Source adapter that fetches wallpapers from Reddit.

func NewReddit

func NewReddit() *Reddit

NewReddit creates a Reddit adapter.

func NewRedditWithBase

func NewRedditWithBase(baseURL string) *Reddit

NewRedditWithBase creates a Reddit adapter with a custom base URL for testing.

func (*Reddit) Categories

func (r *Reddit) Categories() []string

Categories returns the default subreddits available as categories.

func (*Reddit) Name

func (r *Reddit) Name() string

Name returns the unique slug for this source.

func (*Reddit) NeedsKey

func (r *Reddit) NeedsKey() bool

NeedsKey reports whether an API key is required.

func (*Reddit) Search

func (r *Reddit) Search(opts SearchOpts) ([]WallpaperResult, error)

Search fetches wallpapers from the given subreddit.

func (*Reddit) SearchTotal

func (r *Reddit) SearchTotal(_ SearchOpts) (int, error)

SearchTotal returns -1 since Reddit doesn't expose total counts.

type SearchOpts

type SearchOpts struct {
	Query      string
	Sort       string
	Count      int
	Page       int
	MinRes     string
	Categories []string
	TimeRange  string
	Colors     []string // hex colors e.g. "000000", "ffffff"
	Ratios     string   // "landscape", "portrait", "16x9", etc.
	// Subreddit is only meaningful for the reddit source.
	Subreddit string
}

SearchOpts carries all parameters for a search request.

type Source

type Source interface {
	// Search fetches wallpapers matching opts.
	Search(opts SearchOpts) ([]WallpaperResult, error)
	// SearchTotal returns how many results are available server-side for the
	// given opts without downloading all of them. Returns -1 if unknown.
	SearchTotal(opts SearchOpts) (int, error)
	// Name returns the unique slug for this source (e.g. "wallhaven").
	Name() string
	// NeedsKey reports whether this source requires an API key.
	NeedsKey() bool
	// Categories returns the list of categories supported by this source.
	Categories() []string
}

Source is the interface that all wallpaper sources must implement.

type Wallhaven

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

Wallhaven is a Source adapter for the Wallhaven API.

func NewWallhaven

func NewWallhaven(apiKey string) *Wallhaven

NewWallhaven creates a Wallhaven adapter. apiKey may be empty for SFW-only searches.

func NewWallhavenWithBase

func NewWallhavenWithBase(baseURL, apiKey string) *Wallhaven

NewWallhavenWithBase creates a Wallhaven adapter with a custom base URL and HTTP client, intended for testing with httptest servers.

func (*Wallhaven) Categories

func (w *Wallhaven) Categories() []string

Categories returns the categories supported by Wallhaven.

func (*Wallhaven) Name

func (w *Wallhaven) Name() string

Name returns the unique slug for this source.

func (*Wallhaven) NeedsKey

func (w *Wallhaven) NeedsKey() bool

NeedsKey reports whether an API key is required. Wallhaven does not require one for SFW searches.

func (*Wallhaven) Search

func (w *Wallhaven) Search(opts SearchOpts) ([]WallpaperResult, error)

Search fetches wallpapers from Wallhaven matching opts.

func (*Wallhaven) SearchTotal

func (w *Wallhaven) SearchTotal(opts SearchOpts) (int, error)

SearchTotal returns the total number of matching wallpapers on the server.

type WallpaperResult

type WallpaperResult struct {
	ID         string
	Source     string
	PreviewURL string
	FullURL    string
	Resolution string
	Views      int
	Favorites  int
	Tags       []string
}

WallpaperResult is a single wallpaper returned by a Source.

func (WallpaperResult) Filename

func (r WallpaperResult) Filename() string

Filename returns a deterministic local filename for the wallpaper in the form "{source}-{id}.{ext}". Query parameters are stripped from the extension so that URLs like "…/image.png?s=abc" produce ".png".

func (WallpaperResult) MeetsMinResolution

func (r WallpaperResult) MeetsMinResolution(minRes string) bool

MeetsMinResolution reports whether the wallpaper's resolution is at least minRes. If the wallpaper's own resolution is unknown (empty / unparseable), or if minRes is empty / unparseable, the function returns true so that the wallpaper is not filtered out.

Jump to

Keyboard shortcuts

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