This commit is contained in:
abs3nt 2023-10-22 12:52:07 -07:00
parent 7f7c77ae9a
commit d71eb6a355
Signed by: abs3nt
GPG Key ID: A7BD96A8BAB04C09

14
main.go
View File

@ -19,7 +19,8 @@ var cli struct {
Query string `arg:"" name:"query" help:"what to search for." type:"string"` Query string `arg:"" name:"query" help:"what to search for." type:"string"`
} `cmd:"" help:"search for wallpaper"` } `cmd:"" help:"search for wallpaper"`
Top struct { Top struct {
Purity string `arg:"" name:"purity" optional:"" help:"purity of results"` Purity string `name:"purity" optional:"" help:"purity of results"`
Range string `name:"range" optional:"" help:"range for toplist"`
} `cmd:"" help:"random toplist wallpaper"` } `cmd:"" help:"random toplist wallpaper"`
Img struct { Img struct {
Path string `arg:"" name:"path" help:"path to image or directory." type:"path"` Path string `arg:"" name:"path" help:"path to image or directory." type:"path"`
@ -34,8 +35,8 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
case "top", "top <purity>": case "top":
err := setTop(cli.Top.Purity) err := setTop(cli.Top.Purity, cli.Top.Range)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -97,7 +98,7 @@ func searchAndSet(query string) error {
return nil return nil
} }
func setTop(purity string) error { func setTop(purity, topRange string) error {
seed := rand.NewSource(time.Now().UnixNano()) seed := rand.NewSource(time.Now().UnixNano())
r := rand.New(seed) r := rand.New(seed)
s := &wallhaven.Search{ s := &wallhaven.Search{
@ -105,7 +106,7 @@ func setTop(purity string) error {
Purities: "110", Purities: "110",
Sorting: wallhaven.Toplist, Sorting: wallhaven.Toplist,
Order: wallhaven.Desc, Order: wallhaven.Desc,
TopRange: "1m", TopRange: "6m",
AtLeast: wallhaven.Resolution{Width: 2560, Height: 1400}, AtLeast: wallhaven.Resolution{Width: 2560, Height: 1400},
Ratios: []wallhaven.Ratio{ Ratios: []wallhaven.Ratio{
{Horizontal: 16, Vertical: 9}, {Horizontal: 16, Vertical: 9},
@ -116,6 +117,9 @@ func setTop(purity string) error {
if purity != "" { if purity != "" {
s.Purities = purity s.Purities = purity
} }
if topRange != "" {
s.TopRange = topRange
}
results, err := wallhaven.SearchWallpapers(s) results, err := wallhaven.SearchWallpapers(s)
if err != nil { if err != nil {
return err return err