From 6d4b8c1ebd5d78825b7b27fe1c33ebe2ba4722ef Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 27 Aug 2023 10:49:37 -0500 Subject: [PATCH 01/10] =?UTF-8?q?=E2=9C=A8=20Stickers=20=E2=9C=B4=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/current.go | 4 ++++ mpd/stickers.go | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 mpd/stickers.go diff --git a/cmd/current.go b/cmd/current.go index 5af596c..0eb3e5f 100644 --- a/cmd/current.go +++ b/cmd/current.go @@ -26,6 +26,10 @@ to quickly create a Cobra application.`, for k, v := range curr { fmt.Println(k, ":", v) } + sticks, _ := mpd.StickersGetFor(curr["file"]) + for _, v := range sticks { + fmt.Println(v.Name, "*:", v.Value) + } }, } diff --git a/mpd/stickers.go b/mpd/stickers.go new file mode 100644 index 0000000..30058b8 --- /dev/null +++ b/mpd/stickers.go @@ -0,0 +1,11 @@ +package mpd + +import "github.com/fhs/gompd/v2/mpd" + +func StickersGetFor(file string) ([]mpd.Sticker, error) { + if connerror != nil { + return nil, connerror + } + + return conn.StickerList(file) +} From eae30a85fdd4f064039a1b6445e51809d0d347bf Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 27 Aug 2023 10:52:03 -0500 Subject: [PATCH 02/10] =?UTF-8?q?=E2=9C=A8=20=F0=9F=94=8E=F0=9F=8E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/find.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 cmd/find.go diff --git a/cmd/find.go b/cmd/find.go new file mode 100644 index 0000000..5bd67ec --- /dev/null +++ b/cmd/find.go @@ -0,0 +1,47 @@ +/* +Copyright © 2023 NAME HERE +*/ +package cmd + +import ( + "fmt" + + "codeberg.org/danjones000/mpc-plus/mpd" + "github.com/spf13/cobra" +) + +// findCmd represents the find command +var findCmd = &cobra.Command{ + Use: "find", + Short: "A brief description of your command", + Long: `A longer description that spans multiple lines and likely contains examples +and usage of using your command. For example: + +Cobra is a CLI library for Go that empowers applications. +This application is a tool to generate the needed files +to quickly create a Cobra application.`, + Run: func(cmd *cobra.Command, args []string) { + conn, _ := mpd.GetConn() + ret, _ := conn.Search(args...) + for _, attr := range ret { + for k, v := range attr { + fmt.Println(k, ":", v) + } + fmt.Println("-------") + } + }, +} + +func init() { + rootCmd.AddCommand(findCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // findCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // findCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} From c845d08293e073ea03804adb2ea60c0a867d6f72 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 27 Aug 2023 12:10:18 -0500 Subject: [PATCH 03/10] =?UTF-8?q?=F0=9F=9A=9A=20Rename=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/current.go | 2 +- cmd/find.go | 2 +- cmd/root.go | 4 ++-- go.mod | 2 +- main.go | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/current.go b/cmd/current.go index 0eb3e5f..aa0af66 100644 --- a/cmd/current.go +++ b/cmd/current.go @@ -6,7 +6,7 @@ package cmd import ( "fmt" - "codeberg.org/danjones000/mpc-plus/mpd" + "codeberg.org/danjones000/mpc-extra/mpd" "github.com/spf13/cobra" ) diff --git a/cmd/find.go b/cmd/find.go index 5bd67ec..44cce00 100644 --- a/cmd/find.go +++ b/cmd/find.go @@ -6,7 +6,7 @@ package cmd import ( "fmt" - "codeberg.org/danjones000/mpc-plus/mpd" + "codeberg.org/danjones000/mpc-extra/mpd" "github.com/spf13/cobra" ) diff --git a/cmd/root.go b/cmd/root.go index 371cda9..a569232 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -14,7 +14,7 @@ import ( // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ - Use: "mpc-plus", + Use: "mpc-extra", Short: "A brief description of your application", Long: `A longer description that spans multiple lines and likely contains examples and usage of using your application. For example: @@ -41,7 +41,7 @@ func init() { // Cobra supports persistent flags, which, if defined here, // will be global for your application. - // rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.mpc-plus.yaml)") + // rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.mpc-extra.yaml)") // Cobra also supports local flags, which will only run // when this action is called directly. diff --git a/go.mod b/go.mod index 18f7c1a..95ff5db 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module codeberg.org/danjones000/mpc-plus +module codeberg.org/danjones000/mpc-extra go 1.20 diff --git a/main.go b/main.go index afc80a2..7f885b5 100644 --- a/main.go +++ b/main.go @@ -4,8 +4,8 @@ Copyright © 2023 NAME HERE package main import ( - "codeberg.org/danjones000/mpc-plus/cmd" - "codeberg.org/danjones000/mpc-plus/mpd" + "codeberg.org/danjones000/mpc-extra/cmd" + "codeberg.org/danjones000/mpc-extra/mpd" ) func main() { From 16933ce0faa0486f0db3c9d071fdc1dca5d07e74 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 27 Aug 2023 13:16:53 -0500 Subject: [PATCH 04/10] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Song=20struct=20to?= =?UTF-8?q?=20hold=20song=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/current.go | 7 +++---- mpd/conn.go | 4 +--- mpd/current.go | 13 +++++++++++++ mpd/song.go | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 mpd/current.go create mode 100644 mpd/song.go diff --git a/cmd/current.go b/cmd/current.go index aa0af66..3b0dd2b 100644 --- a/cmd/current.go +++ b/cmd/current.go @@ -21,12 +21,11 @@ Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { - conn, _ := mpd.GetConn() - curr, _ := conn.CurrentSong() - for k, v := range curr { + curr, _ := mpd.GetCurrent() + for k, v := range curr.Attrs { fmt.Println(k, ":", v) } - sticks, _ := mpd.StickersGetFor(curr["file"]) + sticks, _ := curr.GetStickers() for _, v := range sticks { fmt.Println(v.Name, "*:", v.Value) } diff --git a/mpd/conn.go b/mpd/conn.go index 6b46242..a112656 100644 --- a/mpd/conn.go +++ b/mpd/conn.go @@ -1,8 +1,6 @@ package mpd -import ( - "github.com/fhs/gompd/v2/mpd" -) +import "github.com/fhs/gompd/v2/mpd" var conn *mpd.Client var connerror error diff --git a/mpd/current.go b/mpd/current.go new file mode 100644 index 0000000..d6f7237 --- /dev/null +++ b/mpd/current.go @@ -0,0 +1,13 @@ +package mpd + +func GetCurrent() (*Song, error) { + if connerror != nil { + return nil, connerror + } + curr, err := conn.CurrentSong() + if err != nil { + return nil, err + } + + return newSong(curr), nil +} diff --git a/mpd/song.go b/mpd/song.go new file mode 100644 index 0000000..64111f5 --- /dev/null +++ b/mpd/song.go @@ -0,0 +1,33 @@ +package mpd + +import "github.com/fhs/gompd/v2/mpd" + +type Song struct { + Path string + Attrs mpd.Attrs + stickers []mpd.Sticker +} + +func newSong(attrs mpd.Attrs) *Song { + return &Song{ + Path: attrs["file"], + Attrs: attrs, + } +} + +func (s *Song) GetStickers() ([]mpd.Sticker, error) { + if s.stickers != nil { + return s.stickers, nil + } + + if connerror != nil { + return nil, connerror + } + + sticks, err := StickersGetFor(s.Path) + s.stickers = sticks + + return s.stickers, err +} + +// github.com/akrennmair/slice From 942d419bf67355a997aae0ce8d307d34dabaf99e Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 27 Aug 2023 13:52:18 -0500 Subject: [PATCH 05/10] =?UTF-8?q?=E2=9C=A8=20Find=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/find.go | 7 +++---- go.mod | 1 + go.sum | 6 ++++++ mpd/find.go | 16 ++++++++++++++++ mpd/song.go | 2 -- 5 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 mpd/find.go diff --git a/cmd/find.go b/cmd/find.go index 44cce00..73a53f5 100644 --- a/cmd/find.go +++ b/cmd/find.go @@ -21,10 +21,9 @@ Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { - conn, _ := mpd.GetConn() - ret, _ := conn.Search(args...) - for _, attr := range ret { - for k, v := range attr { + ret, _ := mpd.Find(args...) + for _, song := range ret { + for k, v := range song.Attrs { fmt.Println(k, ":", v) } fmt.Println("-------") diff --git a/go.mod b/go.mod index 95ff5db..f94f952 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module codeberg.org/danjones000/mpc-extra go 1.20 require ( + github.com/akrennmair/slice v0.0.0-20220105203817-49445747ab81 github.com/fhs/gompd/v2 v2.3.0 github.com/spf13/cobra v1.7.0 ) diff --git a/go.sum b/go.sum index b6552d2..543371f 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,18 @@ +github.com/akrennmair/slice v0.0.0-20220105203817-49445747ab81 h1:HnuAxArB0uUxqjRvZdjhBxE3uPXNeJvNNbuaV4QhHMU= +github.com/akrennmair/slice v0.0.0-20220105203817-49445747ab81/go.mod h1:jk5mJ+KFznfxbCEsOPgmJkozvBfVGeaqIMs31NhXlv0= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/fhs/gompd/v2 v2.3.0 h1:wuruUjmOODRlJhrYx73rJnzS7vTSXSU7pWmZtM3VPE0= github.com/fhs/gompd/v2 v2.3.0/go.mod h1:nNdZtcpD5VpmzZbRl5rV6RhxeMmAWTxEsSIMBkmMIy4= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/mpd/find.go b/mpd/find.go new file mode 100644 index 0000000..9729bc1 --- /dev/null +++ b/mpd/find.go @@ -0,0 +1,16 @@ +package mpd + +import "github.com/akrennmair/slice" + +func Find(args ...string) ([]*Song, error) { + if connerror != nil { + return nil, connerror + } + + songs, err := conn.Search(args...) + if err != nil { + return nil, err + } + + return slice.Map(songs, newSong), nil +} diff --git a/mpd/song.go b/mpd/song.go index 64111f5..aa3c0f8 100644 --- a/mpd/song.go +++ b/mpd/song.go @@ -29,5 +29,3 @@ func (s *Song) GetStickers() ([]mpd.Sticker, error) { return s.stickers, err } - -// github.com/akrennmair/slice From 440b927141523c77702294844139883c0becb2c2 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 27 Aug 2023 14:48:09 -0500 Subject: [PATCH 06/10] =?UTF-8?q?=E2=9C=A8=20PrintAll=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/current.go | 10 +--------- cmd/find.go | 4 +--- mpd/song.go | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/cmd/current.go b/cmd/current.go index 3b0dd2b..4a1ad07 100644 --- a/cmd/current.go +++ b/cmd/current.go @@ -4,8 +4,6 @@ Copyright © 2023 NAME HERE package cmd import ( - "fmt" - "codeberg.org/danjones000/mpc-extra/mpd" "github.com/spf13/cobra" ) @@ -22,13 +20,7 @@ This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { curr, _ := mpd.GetCurrent() - for k, v := range curr.Attrs { - fmt.Println(k, ":", v) - } - sticks, _ := curr.GetStickers() - for _, v := range sticks { - fmt.Println(v.Name, "*:", v.Value) - } + curr.PrintAll(true) }, } diff --git a/cmd/find.go b/cmd/find.go index 73a53f5..98ac884 100644 --- a/cmd/find.go +++ b/cmd/find.go @@ -23,9 +23,7 @@ to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { ret, _ := mpd.Find(args...) for _, song := range ret { - for k, v := range song.Attrs { - fmt.Println(k, ":", v) - } + song.PrintAll(false) fmt.Println("-------") } }, diff --git a/mpd/song.go b/mpd/song.go index aa3c0f8..36e589c 100644 --- a/mpd/song.go +++ b/mpd/song.go @@ -1,6 +1,9 @@ package mpd -import "github.com/fhs/gompd/v2/mpd" +import ( + "fmt" + "github.com/fhs/gompd/v2/mpd" +) type Song struct { Path string @@ -29,3 +32,16 @@ func (s *Song) GetStickers() ([]mpd.Sticker, error) { return s.stickers, err } + +func (s *Song) PrintAll(withStickers bool) { + for k, v := range s.Attrs { + fmt.Println(k, ":", v) + } + if withStickers { + sticks, _ := s.GetStickers() + for _, v := range sticks { + fmt.Println(v.Name, "*:", v.Value) + } + } + +} From f0b04b7c05aa94d9112c4ec0c3d464509bd90c7c Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 27 Aug 2023 15:47:46 -0500 Subject: [PATCH 07/10] =?UTF-8?q?=E2=9C=A8=20find-sticker=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/find-sticker.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ mpd/song.go | 27 ++++++++++++++++++++++++++- mpd/stickers.go | 19 +++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 cmd/find-sticker.go diff --git a/cmd/find-sticker.go b/cmd/find-sticker.go new file mode 100644 index 0000000..d81a74b --- /dev/null +++ b/cmd/find-sticker.go @@ -0,0 +1,44 @@ +/* +Copyright © 2023 NAME HERE +*/ +package cmd + +import ( + "fmt" + + "codeberg.org/danjones000/mpc-extra/mpd" + "github.com/spf13/cobra" +) + +// stickerCmd represents the sticker command +var stickerCmd = &cobra.Command{ + Use: "sticker", + Short: "A brief description of your command", + Long: `A longer description that spans multiple lines and likely contains examples +and usage of using your command. For example: + +Cobra is a CLI library for Go that empowers applications. +This application is a tool to generate the needed files +to quickly create a Cobra application.`, + Run: func(cmd *cobra.Command, args []string) { + name := args[0] + songs, _ := mpd.StickerFind(name) + for _, song := range songs { + fmt.Println(song.Path, name, ":", song.GetSticker(name)) + } + }, +} + +func init() { + findCmd.AddCommand(stickerCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // stickerCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // stickerCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/mpd/song.go b/mpd/song.go index 36e589c..351aa75 100644 --- a/mpd/song.go +++ b/mpd/song.go @@ -2,6 +2,7 @@ package mpd import ( "fmt" + "github.com/akrennmair/slice" "github.com/fhs/gompd/v2/mpd" ) @@ -43,5 +44,29 @@ func (s *Song) PrintAll(withStickers bool) { fmt.Println(v.Name, "*:", v.Value) } } - +} + +func (s *Song) GetSticker(name string) string { + if s.stickers != nil { + ret := slice.Filter(s.stickers, func(sticker mpd.Sticker) bool { + return sticker.Name == name + }) + if ret != nil && len(ret) > 0 { + first := ret[0] + return first.Value + } + } + + if connerror != nil { + return "" + } + + found, err := conn.StickerGet(s.Path, name) + if err != nil { + return "" + } + + s.stickers = append(s.stickers, *found) + + return found.Value } diff --git a/mpd/stickers.go b/mpd/stickers.go index 30058b8..16b487d 100644 --- a/mpd/stickers.go +++ b/mpd/stickers.go @@ -9,3 +9,22 @@ func StickersGetFor(file string) ([]mpd.Sticker, error) { return conn.StickerList(file) } + +func StickerFind(name string) ([]*Song, error) { + if connerror != nil { + return nil, connerror + } + + paths, sticks, err := conn.StickerFind("", name) + if err != nil { + return nil, err + } + + ret := make([]*Song, len(paths)) + for i := 0; i < len(paths); i++ { + ret[i] = newSong(mpd.Attrs{"file": paths[i]}) + ret[i].stickers = []mpd.Sticker{sticks[i]} + } + + return ret, nil +} From 83dc41cb8ea3bd6ccdfe5010e98fc231ea50b670 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 27 Aug 2023 20:07:00 -0500 Subject: [PATCH 08/10] =?UTF-8?q?=E2=9C=A8=20Rate=20current=20track?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/current-rate.go | 58 +++++++++++++++++++++++++++++++++++++++++++++ cmd/current.go | 14 ++++++----- cmd/find-sticker.go | 3 ++- mpd/song.go | 17 +++++++++++-- 4 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 cmd/current-rate.go diff --git a/cmd/current-rate.go b/cmd/current-rate.go new file mode 100644 index 0000000..5e2cbfa --- /dev/null +++ b/cmd/current-rate.go @@ -0,0 +1,58 @@ +/* +Copyright © 2023 NAME HERE +*/ +package cmd + +import ( + "errors" + "strconv" + + "codeberg.org/danjones000/mpc-extra/mpd" + "github.com/spf13/cobra" +) + +// rateCmd represents the rate command +var rateCmd = &cobra.Command{ + Use: "rate [rating]", + Short: "Rates the current playing song: 0-10", + /* + Long: `A longer description that spans multiple lines and likely contains examples + and usage of using your command. For example: + + Cobra is a CLI library for Go that empowers applications. + This application is a tool to generate the needed files + to quickly create a Cobra application.`, + */ + Args: func(cmd *cobra.Command, args []string) error { + if len(args) < 1 { + return errors.New("Missing rating") + } + num, err := strconv.Atoi(args[0]) + if err != nil { + return err + } + if num < 0 || num > 10 { + return errors.New("Rating must be between zero and ten") + } + return nil + }, + Run: func(cmd *cobra.Command, args []string) { + curr, _ := mpd.GetCurrent() + curr.AddSticker("rating", args[0]) + curr.PrintAll(true) + }, +} + +func init() { + currentCmd.AddCommand(rateCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // rateCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // rateCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/cmd/current.go b/cmd/current.go index 4a1ad07..2b218ca 100644 --- a/cmd/current.go +++ b/cmd/current.go @@ -11,13 +11,15 @@ import ( // currentCmd represents the current command var currentCmd = &cobra.Command{ Use: "current", - Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: + Short: "Shows information about the currently playing song", + /* + Long: `A longer description that spans multiple lines and likely contains examples + and usage of using your command. For example: -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Cobra is a CLI library for Go that empowers applications. + This application is a tool to generate the needed files + to quickly create a Cobra application.`, + */ Run: func(cmd *cobra.Command, args []string) { curr, _ := mpd.GetCurrent() curr.PrintAll(true) diff --git a/cmd/find-sticker.go b/cmd/find-sticker.go index d81a74b..f143a0e 100644 --- a/cmd/find-sticker.go +++ b/cmd/find-sticker.go @@ -12,7 +12,8 @@ import ( // stickerCmd represents the sticker command var stickerCmd = &cobra.Command{ - Use: "sticker", + Use: "sticker [sticker-name]", + Args: cobra.MinimumNArgs(1), Short: "A brief description of your command", Long: `A longer description that spans multiple lines and likely contains examples and usage of using your command. For example: diff --git a/mpd/song.go b/mpd/song.go index 351aa75..0e4cf5c 100644 --- a/mpd/song.go +++ b/mpd/song.go @@ -10,6 +10,7 @@ type Song struct { Path string Attrs mpd.Attrs stickers []mpd.Sticker + // @todo refactor as a map so there's no dupes } func newSong(attrs mpd.Attrs) *Song { @@ -52,8 +53,8 @@ func (s *Song) GetSticker(name string) string { return sticker.Name == name }) if ret != nil && len(ret) > 0 { - first := ret[0] - return first.Value + last := ret[len(ret)-1] + return last.Value } } @@ -70,3 +71,15 @@ func (s *Song) GetSticker(name string) string { return found.Value } + +func (s *Song) AddSticker(name, value string) error { + ret := conn.StickerSet(s.Path, name, value) + if ret == nil { + if s.stickers == nil || len(s.stickers) == 0 { + s.GetStickers() + } else { + s.stickers = append(s.stickers, mpd.Sticker{Name: name, Value: value}) + } + } + return ret +} From b2dd7b321aa5bd7f37f1c734ca7ebc2c0b0b9ddc Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 27 Aug 2023 23:43:48 -0500 Subject: [PATCH 09/10] =?UTF-8?q?=E2=9C=A8=20Add=20current=20sticker=20com?= =?UTF-8?q?mand?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/current-sticker.go | 51 ++++++++++++++++++++++++++++++++++++++++++ cmd/find-sticker.go | 12 +++++----- cmd/find.go | 13 ++++++----- 3 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 cmd/current-sticker.go diff --git a/cmd/current-sticker.go b/cmd/current-sticker.go new file mode 100644 index 0000000..fa08623 --- /dev/null +++ b/cmd/current-sticker.go @@ -0,0 +1,51 @@ +/* +Copyright © 2023 NAME HERE +*/ +package cmd + +import ( + "codeberg.org/danjones000/mpc-extra/mpd" + "github.com/spf13/cobra" +) + +// stickerCmd represents the sticker command +var currStickerCmd = &cobra.Command{ + Use: "sticker name value", + Args: cobra.MinimumNArgs(2), + Short: "Adds a sticker to the current song", + /* + Long: `A longer description that spans multiple lines and likely contains examples + and usage of using your command. For example: + + Cobra is a CLI library for Go that empowers applications. + This application is a tool to generate the needed files + to quickly create a Cobra application.`, + */ + RunE: func(cmd *cobra.Command, args []string) error { + name := args[0] + if name == "rating" { + root := cmd.Root() + root.SetArgs([]string{"current", "rate", "--", args[1]}) + root.TraverseChildren = false + return root.Execute() + } + curr, _ := mpd.GetCurrent() + curr.AddSticker(name, args[1]) + curr.PrintAll(true) + return nil + }, +} + +func init() { + currentCmd.AddCommand(currStickerCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // stickerCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // stickerCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/cmd/find-sticker.go b/cmd/find-sticker.go index f143a0e..b9bb984 100644 --- a/cmd/find-sticker.go +++ b/cmd/find-sticker.go @@ -15,12 +15,14 @@ var stickerCmd = &cobra.Command{ Use: "sticker [sticker-name]", Args: cobra.MinimumNArgs(1), Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: + /* + Long: `A longer description that spans multiple lines and likely contains examples + and usage of using your command. For example: -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Cobra is a CLI library for Go that empowers applications. + This application is a tool to generate the needed files + to quickly create a Cobra application.`, + */ Run: func(cmd *cobra.Command, args []string) { name := args[0] songs, _ := mpd.StickerFind(name) diff --git a/cmd/find.go b/cmd/find.go index 98ac884..90d8500 100644 --- a/cmd/find.go +++ b/cmd/find.go @@ -14,12 +14,15 @@ import ( var findCmd = &cobra.Command{ Use: "find", Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: + /* + Long: `A longer description that spans multiple lines and likely contains examples + and usage of using your command. For example: -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Cobra is a CLI library for Go that empowers applications. + + This application is a tool to generate the needed files + to quickly create a Cobra application.`, + */ Run: func(cmd *cobra.Command, args []string) { ret, _ := mpd.Find(args...) for _, song := range ret { From cb655d29f55f72d52762a3d45a0edd8f8c909771 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Tue, 17 Oct 2023 16:56:24 -0500 Subject: [PATCH 10/10] =?UTF-8?q?=E2=9C=A8=20Add=20rate-skip=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + cmd/rate-skip.go | 31 +++++++++++++++++++++++++++++++ mpd/conn.go | 14 ++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 .gitignore create mode 100644 cmd/rate-skip.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3884b73 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +mpc-extra diff --git a/cmd/rate-skip.go b/cmd/rate-skip.go new file mode 100644 index 0000000..097d946 --- /dev/null +++ b/cmd/rate-skip.go @@ -0,0 +1,31 @@ +/* +Copyright © 2023 Dan Jones +*/ +package cmd + +import ( + "codeberg.org/danjones000/mpc-extra/mpd" + "github.com/spf13/cobra" +) + +// rateSkipCmd represents the rate-skip command +var rateSkipCmd = &cobra.Command{ + Use: "rate-skip [rating]", + Args: cobra.MinimumNArgs(1), + Short: "Rate the current song, and skip to the next", + RunE: func(cmd *cobra.Command, args []string) error { + root := cmd.Root() + root.SetArgs([]string{"current", "rate", "--", args[0]}) + root.TraverseChildren = false + err := root.Execute() + if err != nil { + return err + } + + return mpd.Next() + }, +} + +func init() { + rootCmd.AddCommand(rateSkipCmd) +} diff --git a/mpd/conn.go b/mpd/conn.go index a112656..bb60faa 100644 --- a/mpd/conn.go +++ b/mpd/conn.go @@ -20,3 +20,17 @@ func CloseConn() error { } return conn.Close() } + +func Next() error { + if connerror != nil { + return connerror + } + return conn.Next() +} + +func Previous() error { + if connerror != nil { + return connerror + } + return conn.Previous() +}