From b6766d39c5d06b25d5452fd194d3c5345a32bef6 Mon Sep 17 00:00:00 2001 From: Senan Kelly Date: Fri, 16 Feb 2024 15:49:42 +0000 Subject: [PATCH 1/9] Update README.md closes #471 --- README.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f6ae7f0..4f7967d 100644 --- a/README.md +++ b/README.md @@ -97,23 +97,37 @@ the available modes are: gonic supports multiple music folders. this can be handy if you have your music separated by albums, compilations, singles. or maybe 70s, 80s, 90s. whatever. +on top of that - if you don't decide your folder names, or simply do not want the same name in your subsonic client, +gonic can parse aliases for the folder names with the optional `ALIAS->PATH` syntax + if you're running gonic with the command line, stack the `-music-path` arg ```shell -$ gonic -music-path /path/to/albums -music-path /path/to/compilations +$ gonic -music-path "/path/to/albums" -music-path "/path/to/compilations" # without aliases +# or +$ gonic -music-path "my albums->/path/to/albums" -music-path "my compilations->/path/to/compilations" # with aliases ``` if you're running gonic with ENV_VARS, or docker, try separate with a comma ```shell -GONIC_MUSIC_PATH=/path/to/albums,/path/to/compilations +export GONIC_MUSIC_PATH="/path/to/albums,/path/to/compilations" # without aliases +# or +export GONIC_MUSIC_PATH="my albums->/path/to/albums,my compilations->/path/to/compilations" # with aliases ``` if you're running gonic with the config file, you can repeat the `music-path` option -```shell +``` +# without aliases music-path /path/to/albums music-path /path/to/compilations + +# or + +# with aliases +music-path my albums->/path/to/albums +music-path my compilations->/path/to/compilations ``` after that, most subsonic clients should allow you to select which music folder to use. From 70ff70cdfa6a19fd6fec853a0489b5be1ec5fce8 Mon Sep 17 00:00:00 2001 From: sentriz Date: Tue, 20 Feb 2024 13:14:07 +0000 Subject: [PATCH 2/9] delete revive --- .golangci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 51bccad..63200b1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -54,7 +54,6 @@ linters: - predeclared - promlinter - reassign - - revive - rowserrcheck - sqlclosecheck - staticcheck From c6cec8307ac4bbfdabba4e18b39ba479856b174b Mon Sep 17 00:00:00 2001 From: sentriz Date: Tue, 20 Feb 2024 13:14:13 +0000 Subject: [PATCH 3/9] declare new errs inline if --- lastfm/client.go | 2 +- podcast/podcast.go | 2 +- server/ctrlsubsonic/handlers_raw.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lastfm/client.go b/lastfm/client.go index cc38eaa..23d28a4 100644 --- a/lastfm/client.go +++ b/lastfm/client.go @@ -299,7 +299,7 @@ func (c *Client) makeRequest(method string, params url.Values) (LastFM, error) { defer resp.Body.Close() var lastfm LastFM - if err = xml.NewDecoder(resp.Body).Decode(&lastfm); err != nil { + if err := xml.NewDecoder(resp.Body).Decode(&lastfm); err != nil { return LastFM{}, fmt.Errorf("decoding: %w", err) } diff --git a/podcast/podcast.go b/podcast/podcast.go index 45a2257..c77dee8 100644 --- a/podcast/podcast.go +++ b/podcast/podcast.go @@ -253,7 +253,7 @@ func (p *Podcasts) RefreshPodcasts() error { errs = append(errs, fmt.Errorf("refreshing podcast with url %q: %w", podcast.URL, err)) continue } - if err = p.RefreshPodcast(podcast, feed.Items); err != nil { + if err := p.RefreshPodcast(podcast, feed.Items); err != nil { errs = append(errs, fmt.Errorf("adding episodes: %w", err)) continue } diff --git a/server/ctrlsubsonic/handlers_raw.go b/server/ctrlsubsonic/handlers_raw.go index 6d2ec72..de3f16a 100644 --- a/server/ctrlsubsonic/handlers_raw.go +++ b/server/ctrlsubsonic/handlers_raw.go @@ -160,7 +160,7 @@ func coverScaleAndSave(reader io.Reader, cachePath string, size int) error { // don't upscale images width = src.Bounds().Dx() } - if err = imaging.Save(imaging.Resize(src, width, 0, imaging.Lanczos), cachePath); err != nil { + if err := imaging.Save(imaging.Resize(src, width, 0, imaging.Lanczos), cachePath); err != nil { return fmt.Errorf("caching %q: %w", cachePath, err) } return nil From b31f9d37646b13774a0080b2610e5cf35db6081f Mon Sep 17 00:00:00 2001 From: sentriz Date: Tue, 20 Feb 2024 13:15:48 +0000 Subject: [PATCH 4/9] podcast: make sure destination directory exists --- podcast/podcast.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/podcast/podcast.go b/podcast/podcast.go index c77dee8..a8d0bf3 100644 --- a/podcast/podcast.go +++ b/podcast/podcast.go @@ -484,6 +484,9 @@ func (p *Podcasts) doPodcastDownload(podcast *db.Podcast, podcastEpisode *db.Pod if err := p.db.Save(&podcastEpisode).Error; err != nil { return fmt.Errorf("save podcast episode: %w", err) } + if err := os.MkdirAll(filepath.Dir(podcastEpisode.Filename), os.ModePerm); err != nil { + return fmt.Errorf("make podcast root dir: %w", err) + } file, err := os.Create(filepath.Join(podcast.RootDir, podcastEpisode.Filename)) if err != nil { return fmt.Errorf("create audio file: %w", err) From 4600ee1cbb380bb7a9d255cbd51bd746e021eb63 Mon Sep 17 00:00:00 2001 From: sentriz Date: Tue, 20 Feb 2024 15:52:05 +0000 Subject: [PATCH 5/9] feat: upgrade to ff v4 allows escaping delimiters fixes #473 --- cmd/gonic/gonic.go | 66 ++++++++++++++++++++++++---------------------- go.mod | 4 +-- go.sum | 15 +++++------ 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/cmd/gonic/gonic.go b/cmd/gonic/gonic.go index f39d59a..565ee51 100644 --- a/cmd/gonic/gonic.go +++ b/cmd/gonic/gonic.go @@ -26,7 +26,7 @@ import ( "github.com/google/shlex" "github.com/gorilla/securecookie" _ "github.com/jinzhu/gorm/dialects/sqlite" - "github.com/peterbourgon/ff" + "github.com/peterbourgon/ff/v4" "github.com/sentriz/gormstore" "golang.org/x/sync/errgroup" @@ -50,59 +50,63 @@ import ( ) func main() { - set := flag.NewFlagSet(gonic.Name, flag.ExitOnError) - confListenAddr := set.String("listen-addr", "0.0.0.0:4747", "listen address (optional)") + confListenAddr := flag.String("listen-addr", "0.0.0.0:4747", "listen address (optional)") - confTLSCert := set.String("tls-cert", "", "path to TLS certificate (optional)") - confTLSKey := set.String("tls-key", "", "path to TLS private key (optional)") + confTLSCert := flag.String("tls-cert", "", "path to TLS certificate (optional)") + confTLSKey := flag.String("tls-key", "", "path to TLS private key (optional)") - confPodcastPurgeAgeDays := set.Uint("podcast-purge-age", 0, "age (in days) to purge podcast episodes if not accessed (optional)") - confPodcastPath := set.String("podcast-path", "", "path to podcasts") + confPodcastPurgeAgeDays := flag.Uint("podcast-purge-age", 0, "age (in days) to purge podcast episodes if not accessed (optional)") + confPodcastPath := flag.String("podcast-path", "", "path to podcasts") - confCachePath := set.String("cache-path", "", "path to cache") + confCachePath := flag.String("cache-path", "", "path to cache") var confMusicPaths pathAliases - set.Var(&confMusicPaths, "music-path", "path to music") + flag.Var(&confMusicPaths, "music-path", "path to music") - confPlaylistsPath := set.String("playlists-path", "", "path to your list of new or existing m3u playlists that gonic can manage") + confPlaylistsPath := flag.String("playlists-path", "", "path to your list of new or existing m3u playlists that gonic can manage") - confDBPath := set.String("db-path", "gonic.db", "path to database (optional)") + confDBPath := flag.String("db-path", "gonic.db", "path to database (optional)") - confScanIntervalMins := set.Uint("scan-interval", 0, "interval (in minutes) to automatically scan music (optional)") - confScanAtStart := set.Bool("scan-at-start-enabled", false, "whether to perform an initial scan at startup (optional)") - confScanWatcher := set.Bool("scan-watcher-enabled", false, "whether to watch file system for new music and rescan (optional)") + confScanIntervalMins := flag.Uint("scan-interval", 0, "interval (in minutes) to automatically scan music (optional)") + confScanAtStart := flag.Bool("scan-at-start-enabled", false, "whether to perform an initial scan at startup (optional)") + confScanWatcher := flag.Bool("scan-watcher-enabled", false, "whether to watch file system for new music and rescan (optional)") - confJukeboxEnabled := set.Bool("jukebox-enabled", false, "whether the subsonic jukebox api should be enabled (optional)") - confJukeboxMPVExtraArgs := set.String("jukebox-mpv-extra-args", "", "extra command line arguments to pass to the jukebox mpv daemon (optional)") + confJukeboxEnabled := flag.Bool("jukebox-enabled", false, "whether the subsonic jukebox api should be enabled (optional)") + confJukeboxMPVExtraArgs := flag.String("jukebox-mpv-extra-args", "", "extra command line arguments to pass to the jukebox mpv daemon (optional)") - confProxyPrefix := set.String("proxy-prefix", "", "url path prefix to use if behind proxy. eg '/gonic' (optional)") - confHTTPLog := set.Bool("http-log", true, "http request logging (optional)") + confProxyPrefix := flag.String("proxy-prefix", "", "url path prefix to use if behind proxy. eg '/gonic' (optional)") + confHTTPLog := flag.Bool("http-log", true, "http request logging (optional)") - confShowVersion := set.Bool("version", false, "show gonic version") - _ = set.String("config-path", "", "path to config (optional)") + confShowVersion := flag.Bool("version", false, "show gonic version") + _ = flag.String("config-path", "", "path to config (optional)") - confExcludePattern := set.String("exclude-pattern", "", "regex pattern to exclude files from scan (optional)") + confExcludePattern := flag.String("exclude-pattern", "", "regex pattern to exclude files from scan (optional)") var confMultiValueGenre, confMultiValueArtist, confMultiValueAlbumArtist multiValueSetting - set.Var(&confMultiValueGenre, "multi-value-genre", "setting for mutli-valued genre scanning (optional)") - set.Var(&confMultiValueArtist, "multi-value-artist", "setting for mutli-valued track artist scanning (optional)") - set.Var(&confMultiValueAlbumArtist, "multi-value-album-artist", "setting for mutli-valued album artist scanning (optional)") + flag.Var(&confMultiValueGenre, "multi-value-genre", "setting for mutli-valued genre scanning (optional)") + flag.Var(&confMultiValueArtist, "multi-value-artist", "setting for mutli-valued track artist scanning (optional)") + flag.Var(&confMultiValueAlbumArtist, "multi-value-album-artist", "setting for mutli-valued album artist scanning (optional)") - confPprof := set.Bool("pprof", false, "enable the /debug/pprof endpoint (optional)") - confExpvar := set.Bool("expvar", false, "enable the /debug/vars endpoint (optional)") + confPprof := flag.Bool("pprof", false, "enable the /debug/pprof endpoint (optional)") + confExpvar := flag.Bool("expvar", false, "enable the /debug/vars endpoint (optional)") - deprecatedConfGenreSplit := set.String("genre-split", "", "(deprecated, see multi-value settings)") + deprecatedConfGenreSplit := flag.String("genre-split", "", "(deprecated, see multi-value settings)") if _, err := regexp.Compile(*confExcludePattern); err != nil { log.Fatalf("invalid exclude pattern: %v\n", err) } - if err := ff.Parse(set, os.Args[1:], + switch err := ff.Parse(flag.CommandLine, os.Args[1:], ff.WithConfigFileFlag("config-path"), ff.WithConfigFileParser(ff.PlainParser), ff.WithEnvVarPrefix(gonic.NameUpper), - ); err != nil { - log.Fatalf("error parsing args: %v\n", err) + ff.WithEnvVarSplit(","), + ); { + case errors.Is(err, ff.ErrHelp): + flag.Usage() + os.Exit(0) + case err != nil: + log.Fatalf("error parsing flags: %v", err) } if *confShowVersion { @@ -179,7 +183,7 @@ func main() { log.Printf("starting gonic v%s\n", gonic.Version) log.Printf("provided config\n") - set.VisitAll(func(f *flag.Flag) { + flag.VisitAll(func(f *flag.Flag) { value := strings.ReplaceAll(f.Value.String(), "\n", "") log.Printf(" %-25s %s\n", f.Name, value) }) diff --git a/go.mod b/go.mod index 87c36ec..7452e8d 100644 --- a/go.mod +++ b/go.mod @@ -20,13 +20,13 @@ require ( github.com/mitchellh/mapstructure v1.5.0 github.com/mmcdole/gofeed v1.2.1 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 - github.com/peterbourgon/ff v1.7.1 + github.com/peterbourgon/ff/v4 v4.0.0-alpha.4.0.20240216105926-21ddd055d8e4 github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4 github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be github.com/sentriz/audiotags v0.0.0-20240202193907-618ae39d7743 github.com/sentriz/gormstore v0.0.0-20220105134332-64e31f7f6981 github.com/stretchr/testify v1.8.4 - golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 + golang.org/x/exp v0.0.0-20240213143201-ec583247a57a golang.org/x/net v0.21.0 golang.org/x/sync v0.6.0 gopkg.in/gormigrate.v1 v1.6.0 diff --git a/go.sum b/go.sum index 83a28a0..ef0a978 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,4 @@ cloud.google.com/go v0.33.1/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= @@ -100,7 +99,6 @@ github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= -github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= @@ -118,9 +116,10 @@ github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= -github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys= -github.com/peterbourgon/ff v1.7.1 h1:xt1lxTG+Nr2+tFtysY7abFgPoH3Lug8CwYJMOmJRXhk= -github.com/peterbourgon/ff v1.7.1/go.mod h1:fYI5YA+3RDqQRExmFbHnBjEeWzh9TrS8rnRpEq7XIg0= +github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0= +github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/peterbourgon/ff/v4 v4.0.0-alpha.4.0.20240216105926-21ddd055d8e4 h1:aq3I2fGN1Yr5SMYybLYnw49T+xckxkVgSfBU2xk1KTs= +github.com/peterbourgon/ff/v4 v4.0.0-alpha.4.0.20240216105926-21ddd055d8e4/go.mod h1:H/13DK46DKXy7EaIxPhk2Y0EC8aubKm35nBjBe8AAGc= github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4 h1:SvVjZyjXBOjqjCdMiC9ndyWb709aP5qU4Qbun40GCxA= github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4/go.mod h1:Mpa6Hci7lO3vybfdYlWXmH5gEq2vyOmYYjhrlwCTW3w= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -150,8 +149,8 @@ golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= -golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 h1:/RIbNt/Zr7rVhIkQhooTxCxFcdWLGIKnZA4IXNFSrvo= -golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08= +golang.org/x/exp v0.0.0-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE= +golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8= golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= @@ -204,7 +203,6 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -214,7 +212,6 @@ gopkg.in/gormigrate.v1 v1.6.0 h1:XpYM6RHQPmzwY7Uyu+t+xxMXc86JYFJn4nEc9HzQjsI= gopkg.in/gormigrate.v1 v1.6.0/go.mod h1:Lf00lQrHqfSYWiTtPcyQabsDdM6ejZaMgV0OU6JMSlw= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= From 51fa0baac39577b335a3f5c064be81cf9293e9f0 Mon Sep 17 00:00:00 2001 From: sentriz Date: Tue, 20 Feb 2024 17:28:30 +0000 Subject: [PATCH 6/9] fix(ci): manually add taglib v2 APKBUILD --- Dockerfile | 16 ++++++++++-- alpine/taglib/APKBUILD | 55 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 alpine/taglib/APKBUILD diff --git a/Dockerfile b/Dockerfile index aeb3728..158c9dc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,24 @@ +FROM alpine:3.18 AS builder-taglib +WORKDIR /tmp +COPY alpine/taglib/APKBUILD . +RUN apk update && \ + apk add --no-cache abuild && \ + abuild-keygen -a -n && \ + REPODEST=/pkgs abuild -F -r + FROM golang:1.21-alpine AS builder RUN apk add -U --no-cache \ build-base \ ca-certificates \ git \ sqlite \ - taglib-dev \ zlib-dev \ go + +# TODO: delete this block when taglib v2 is on alpine packages +COPY --from=builder-taglib /pkgs/*/*.apk /pkgs/ +RUN apk add --no-cache --allow-untrusted /pkgs/* + WORKDIR /src COPY go.mod . COPY go.sum . @@ -27,7 +39,7 @@ RUN apk add -U --no-cache \ COPY --from=builder \ /usr/lib/libgcc_s.so.1 \ /usr/lib/libstdc++.so.6 \ - /usr/lib/libtag.so.1 \ + /usr/lib/libtag.so.2 \ /usr/lib/ COPY --from=builder \ /src/gonic \ diff --git a/alpine/taglib/APKBUILD b/alpine/taglib/APKBUILD new file mode 100644 index 0000000..c3ebfd6 --- /dev/null +++ b/alpine/taglib/APKBUILD @@ -0,0 +1,55 @@ +# Contributor: Leo +# Maintainer: Natanael Copa +pkgname=taglib2 +pkgver=2.0 +pkgrel=0 +pkgdesc="Library for reading and editing metadata of several popular audio formats" +url="https://taglib.github.io/" +arch="all" +license="LGPL-2.1-only OR MPL-1.1" +makedepends="zlib-dev utfcpp cmake samurai" +checkdepends="cppunit-dev" +subpackages=" + $pkgname-dev + libtag:_lib + libtag_c:_lib + " +source="https://taglib.github.io/releases/taglib-$pkgver.tar.gz" +builddir="$srcdir/taglib-$pkgver" + +# secfixes: +# 1.11.1-r2: +# - CVE-2017-12678 +# - CVE-2018-11439 + +build() { + CFLAGS="$CFLAGS -flto=auto" \ + CXXFLAGS="$CXXFLAGS -flto=auto" \ + cmake -B build -G Ninja \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DCMAKE_BUILD_TYPE=MinSizeRel \ + -DWITH_ZLIB=ON \ + -DBUILD_SHARED_LIBS=ON \ + -DBUILD_EXAMPLES=ON \ + -DBUILD_TESTING="$(want_check && echo ON || echo OFF)" \ + -DVISIBILITY_HIDDEN=ON + cmake --build build +} + +check() { + ctest --test-dir build --output-on-failure +} + +package() { + DESTDIR="$pkgdir" cmake --install build +} + +_lib() { + pkgdesc="$pkgdesc ($subpkgname lib)" + + amove usr/lib/$subpkgname.so.* +} + +sha512sums=" +099d02b2eab033f5702a8cb03e70752d7523c6f8c2f3eebdd0bcd939eafbdca3f2a6c82452983904b5822cfa45f2707ed866c3419508df9d43bf5c0b3a476f6c taglib-2.0.tar.gz +" From 2878b88aeee8bdf7a2e45520298422b883d8ab24 Mon Sep 17 00:00:00 2001 From: sentriz Date: Tue, 20 Feb 2024 18:31:44 +0000 Subject: [PATCH 7/9] feat(lastfm): autocorrect artist and album name misspellings when fetching info closes #472 --- lastfm/client.go | 2 ++ lastfm/client_test.go | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lastfm/client.go b/lastfm/client.go index 23d28a4..b718726 100644 --- a/lastfm/client.go +++ b/lastfm/client.go @@ -52,6 +52,7 @@ func (c *Client) ArtistGetInfo(artistName string) (Artist, error) { params.Add("method", "artist.getInfo") params.Add("api_key", apiKey) params.Add("artist", artistName) + params.Add("autocorrect", "1") resp, err := c.makeRequest(http.MethodGet, params) if err != nil { @@ -72,6 +73,7 @@ func (c *Client) AlbumGetInfo(artistName, albumName string) (Album, error) { params.Add("api_key", apiKey) params.Add("artist", artistName) params.Add("album", albumName) + params.Add("autocorrect", "1") resp, err := c.makeRequest(http.MethodGet, params) if err != nil { diff --git a/lastfm/client_test.go b/lastfm/client_test.go index 6525676..ee23ef7 100644 --- a/lastfm/client_test.go +++ b/lastfm/client_test.go @@ -23,7 +23,7 @@ func TestArtistGetInfo(t *testing.T) { client := lastfm.NewClientCustom( mockclient.New(t, func(w http.ResponseWriter, r *http.Request) { require.Equal(t, http.MethodGet, r.Method) - require.Equal(t, url.Values{"method": []string{"artist.getInfo"}, "api_key": []string{"apiKey1"}, "artist": []string{"Artist 1"}}, r.URL.Query()) + require.Equal(t, url.Values{"method": []string{"artist.getInfo"}, "api_key": []string{"apiKey1"}, "artist": []string{"Artist 1"}, "autocorrect": []string{"1"}}, r.URL.Query()) require.Equal(t, "/2.0/", r.URL.Path) require.Equal(t, lastfm.BaseURL, "https://"+r.Host+r.URL.Path) @@ -103,9 +103,10 @@ func TestArtistGetInfoClientRequestFails(t *testing.T) { mockclient.New(t, func(w http.ResponseWriter, r *http.Request) { require.Equal(t, http.MethodGet, r.Method) require.Equal(t, url.Values{ - "method": []string{"artist.getInfo"}, - "api_key": []string{"apiKey1"}, - "artist": []string{"Artist 1"}, + "method": []string{"artist.getInfo"}, + "api_key": []string{"apiKey1"}, + "artist": []string{"Artist 1"}, + "autocorrect": []string{"1"}, }, r.URL.Query()) require.Equal(t, "/2.0/", r.URL.Path) From 3ada74c4db61c90ba428a071282fdacfd038cfc0 Mon Sep 17 00:00:00 2001 From: sentriz Date: Wed, 21 Feb 2024 13:52:22 +0000 Subject: [PATCH 8/9] feat: replace ff with with flagconf --- cmd/gonic/gonic.go | 29 ++++++++++------------------- go.mod | 3 +-- go.sum | 12 ++++++------ 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/cmd/gonic/gonic.go b/cmd/gonic/gonic.go index 565ee51..b3bc283 100644 --- a/cmd/gonic/gonic.go +++ b/cmd/gonic/gonic.go @@ -1,4 +1,4 @@ -//nolint:lll,gocyclo,forbidigo,nilerr +//nolint:lll,gocyclo,forbidigo,nilerr,errcheck package main import ( @@ -26,10 +26,10 @@ import ( "github.com/google/shlex" "github.com/gorilla/securecookie" _ "github.com/jinzhu/gorm/dialects/sqlite" - "github.com/peterbourgon/ff/v4" "github.com/sentriz/gormstore" "golang.org/x/sync/errgroup" + "go.senan.xyz/flagconf" "go.senan.xyz/gonic" "go.senan.xyz/gonic/db" "go.senan.xyz/gonic/handlerutil" @@ -78,7 +78,7 @@ func main() { confHTTPLog := flag.Bool("http-log", true, "http request logging (optional)") confShowVersion := flag.Bool("version", false, "show gonic version") - _ = flag.String("config-path", "", "path to config (optional)") + confConfigPath := flag.String("config-path", "", "path to config (optional)") confExcludePattern := flag.String("exclude-pattern", "", "regex pattern to exclude files from scan (optional)") @@ -92,28 +92,19 @@ func main() { deprecatedConfGenreSplit := flag.String("genre-split", "", "(deprecated, see multi-value settings)") - if _, err := regexp.Compile(*confExcludePattern); err != nil { - log.Fatalf("invalid exclude pattern: %v\n", err) - } - - switch err := ff.Parse(flag.CommandLine, os.Args[1:], - ff.WithConfigFileFlag("config-path"), - ff.WithConfigFileParser(ff.PlainParser), - ff.WithEnvVarPrefix(gonic.NameUpper), - ff.WithEnvVarSplit(","), - ); { - case errors.Is(err, ff.ErrHelp): - flag.Usage() - os.Exit(0) - case err != nil: - log.Fatalf("error parsing flags: %v", err) - } + flag.Parse() + flagconf.ParseEnv() + flagconf.ParseConfig(*confConfigPath) if *confShowVersion { fmt.Printf("v%s\n", gonic.Version) os.Exit(0) } + if _, err := regexp.Compile(*confExcludePattern); err != nil { + log.Fatalf("invalid exclude pattern: %v\n", err) + } + if len(confMusicPaths) == 0 { log.Fatalf("please provide a music directory") } diff --git a/go.mod b/go.mod index 7452e8d..3c9a01a 100644 --- a/go.mod +++ b/go.mod @@ -20,12 +20,12 @@ require ( github.com/mitchellh/mapstructure v1.5.0 github.com/mmcdole/gofeed v1.2.1 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 - github.com/peterbourgon/ff/v4 v4.0.0-alpha.4.0.20240216105926-21ddd055d8e4 github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4 github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be github.com/sentriz/audiotags v0.0.0-20240202193907-618ae39d7743 github.com/sentriz/gormstore v0.0.0-20220105134332-64e31f7f6981 github.com/stretchr/testify v1.8.4 + go.senan.xyz/flagconf v0.0.0-20240221142506-c693ad2c2dc1 golang.org/x/exp v0.0.0-20240213143201-ec583247a57a golang.org/x/net v0.21.0 golang.org/x/sync v0.6.0 @@ -58,7 +58,6 @@ require ( github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect - github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect golang.org/x/crypto v0.19.0 // indirect golang.org/x/image v0.15.0 // indirect diff --git a/go.sum b/go.sum index ef0a978..7a37adc 100644 --- a/go.sum +++ b/go.sum @@ -116,10 +116,6 @@ github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= -github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0= -github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= -github.com/peterbourgon/ff/v4 v4.0.0-alpha.4.0.20240216105926-21ddd055d8e4 h1:aq3I2fGN1Yr5SMYybLYnw49T+xckxkVgSfBU2xk1KTs= -github.com/peterbourgon/ff/v4 v4.0.0-alpha.4.0.20240216105926-21ddd055d8e4/go.mod h1:H/13DK46DKXy7EaIxPhk2Y0EC8aubKm35nBjBe8AAGc= github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4 h1:SvVjZyjXBOjqjCdMiC9ndyWb709aP5qU4Qbun40GCxA= github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4/go.mod h1:Mpa6Hci7lO3vybfdYlWXmH5gEq2vyOmYYjhrlwCTW3w= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -129,8 +125,8 @@ github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be/go.mod h1:MIDF github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= -github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/sentriz/audiotags v0.0.0-20240202193907-618ae39d7743 h1:aecPwcrY8mYmZmd9XgQcG8aILRuhRxeQMSunnr6DQ3U= github.com/sentriz/audiotags v0.0.0-20240202193907-618ae39d7743/go.mod h1:Zoo4UP5t2ySbPwScJfoydAlLLBonoqntv4ovA1T91Z8= github.com/sentriz/gormstore v0.0.0-20220105134332-64e31f7f6981 h1:sLILANWN76ja66/K4k/mBqJuCjDZaM67w+Ru6rEB0s0= @@ -142,6 +138,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.senan.xyz/flagconf v0.0.0-20240221142506-c693ad2c2dc1 h1:O3uSiZbK2TmPUCsw5Kz0pGeTKlJltoSxgxX+0M7I/9I= +go.senan.xyz/flagconf v0.0.0-20240221142506-c693ad2c2dc1/go.mod h1:B285qDMTH54V1G1OApPj0JhnQGpJXuFsN7XEFHGMQ1U= golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -203,6 +201,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= +golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From bf5e4d4811eefc35d8f9b5caa6bf9af1770d183c Mon Sep 17 00:00:00 2001 From: sentriz Date: Wed, 21 Feb 2024 16:20:35 +0000 Subject: [PATCH 9/9] bump flagconf --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3c9a01a..b1f1418 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/sentriz/audiotags v0.0.0-20240202193907-618ae39d7743 github.com/sentriz/gormstore v0.0.0-20220105134332-64e31f7f6981 github.com/stretchr/testify v1.8.4 - go.senan.xyz/flagconf v0.0.0-20240221142506-c693ad2c2dc1 + go.senan.xyz/flagconf v0.0.0-20240221161927-6640ce2e42fd golang.org/x/exp v0.0.0-20240213143201-ec583247a57a golang.org/x/net v0.21.0 golang.org/x/sync v0.6.0 diff --git a/go.sum b/go.sum index 7a37adc..a7f7b64 100644 --- a/go.sum +++ b/go.sum @@ -138,8 +138,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.senan.xyz/flagconf v0.0.0-20240221142506-c693ad2c2dc1 h1:O3uSiZbK2TmPUCsw5Kz0pGeTKlJltoSxgxX+0M7I/9I= -go.senan.xyz/flagconf v0.0.0-20240221142506-c693ad2c2dc1/go.mod h1:B285qDMTH54V1G1OApPj0JhnQGpJXuFsN7XEFHGMQ1U= +go.senan.xyz/flagconf v0.0.0-20240221161927-6640ce2e42fd h1:kS0FsCtqcVeTcUE8qSzM11qheuZYGX1kImHLuBIa0IE= +go.senan.xyz/flagconf v0.0.0-20240221161927-6640ce2e42fd/go.mod h1:B285qDMTH54V1G1OApPj0JhnQGpJXuFsN7XEFHGMQ1U= golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=