mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-25 10:12:37 +02:00
look up with tags
This commit is contained in:
parent
6a0a58197b
commit
8663573a31
@ -15,11 +15,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ImagesTagCommand struct {
|
type ImagesTagCommand struct {
|
||||||
Id int `short:"i" long:"id" description:"image id to tag" required:"true"`
|
Id int `short:"i" long:"id" description:"image id to tag"`
|
||||||
|
TagId int `short:"t" long:"tag-id" description:"look up for the first image of this tagId"`
|
||||||
|
TagName string `short:"T" long:"tag" description:"look up for the first image of this tagName"`
|
||||||
ExcludeTags string `short:"x" long:"exclude" description:"exclude tag from selection"`
|
ExcludeTags string `short:"x" long:"exclude" description:"exclude tag from selection"`
|
||||||
|
KeepSurveyFilter bool `short:"k" long:"keep" description:"keep survey filter"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ImagesTagCommand) Execute(args []string) error {
|
func (c *ImagesTagCommand) Execute(args []string) error {
|
||||||
|
|
||||||
p := piwigo.Piwigo{}
|
p := piwigo.Piwigo{}
|
||||||
if err := p.LoadConfig(); err != nil {
|
if err := p.LoadConfig(); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -30,6 +34,33 @@ func (c *ImagesTagCommand) Execute(args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.Id == 0 {
|
||||||
|
data := &url.Values{}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case c.TagId > 0:
|
||||||
|
data.Set("tag_id", fmt.Sprint(c.TagId))
|
||||||
|
case c.TagName != "":
|
||||||
|
data.Set("tag_name", c.TagName)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("id or tagId or tagName are required")
|
||||||
|
}
|
||||||
|
|
||||||
|
data.Set("order", "date_creation")
|
||||||
|
data.Set("per_page", "1")
|
||||||
|
var results struct {
|
||||||
|
Images []piwigotools.ImageDetails `json:"images"`
|
||||||
|
}
|
||||||
|
if err := p.Post("pwg.tags.getImages", data, &results); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(results.Images) == 0 {
|
||||||
|
return fmt.Errorf("image not found")
|
||||||
|
}
|
||||||
|
c.Id = results.Images[0].Id
|
||||||
|
}
|
||||||
|
|
||||||
var imgDetails piwigotools.ImageDetails
|
var imgDetails piwigotools.ImageDetails
|
||||||
if err := p.Post("pwg.images.getInfo", &url.Values{
|
if err := p.Post("pwg.images.getInfo", &url.Values{
|
||||||
"image_id": []string{fmt.Sprint(c.Id)},
|
"image_id": []string{fmt.Sprint(c.Id)},
|
||||||
@ -58,6 +89,7 @@ func (c *ImagesTagCommand) Execute(args []string) error {
|
|||||||
|
|
||||||
t := table.NewWriter()
|
t := table.NewWriter()
|
||||||
t.AppendRows([]table.Row{
|
t.AppendRows([]table.Row{
|
||||||
|
{"Id", imgDetails.Id},
|
||||||
{"Name", imgDetails.Name},
|
{"Name", imgDetails.Name},
|
||||||
{"Url", imgDetails.Url},
|
{"Url", imgDetails.Url},
|
||||||
{"CreatedAt", imgDetails.DateCreation},
|
{"CreatedAt", imgDetails.DateCreation},
|
||||||
@ -75,7 +107,7 @@ func (c *ImagesTagCommand) Execute(args []string) error {
|
|||||||
exclude = regexp.MustCompile(c.ExcludeTags)
|
exclude = regexp.MustCompile(c.ExcludeTags)
|
||||||
}
|
}
|
||||||
|
|
||||||
sel := tags.Tags.Select(exclude)
|
sel := tags.Tags.Select(exclude, c.KeepSurveyFilter)
|
||||||
|
|
||||||
fmt.Println("Selection:")
|
fmt.Println("Selection:")
|
||||||
for _, name := range sel.NamesWithAgeAt(&imgDetails.DateCreation) {
|
for _, name := range sel.NamesWithAgeAt(&imgDetails.DateCreation) {
|
||||||
|
@ -52,7 +52,7 @@ func (t Tags) JoinIds(sep string) string {
|
|||||||
return strings.Join(ids, sep)
|
return strings.Join(ids, sep)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Tags) Select(exclude *regexp.Regexp) Tags {
|
func (t Tags) Select(exclude *regexp.Regexp, keepFilter bool) Tags {
|
||||||
options := make([]string, len(t))
|
options := make([]string, len(t))
|
||||||
tags := map[string]*Tag{}
|
tags := map[string]*Tag{}
|
||||||
for i, tag := range t {
|
for i, tag := range t {
|
||||||
@ -66,7 +66,7 @@ func (t Tags) Select(exclude *regexp.Regexp) Tags {
|
|||||||
Options: options,
|
Options: options,
|
||||||
PageSize: 20,
|
PageSize: 20,
|
||||||
}
|
}
|
||||||
survey.AskOne(prompt, &answer, survey.WithKeepFilter(true))
|
survey.AskOne(prompt, &answer, survey.WithKeepFilter(keepFilter))
|
||||||
|
|
||||||
result := make([]*Tag, len(answer))
|
result := make([]*Tag, len(answer))
|
||||||
for i, a := range answer {
|
for i, a := range answer {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user