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 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/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. 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 +" diff --git a/cmd/gonic/gonic.go b/cmd/gonic/gonic.go index f39d59a..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" "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" @@ -50,66 +50,61 @@ 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") + confConfigPath := 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:], - ff.WithConfigFileFlag("config-path"), - ff.WithConfigFileParser(ff.PlainParser), - ff.WithEnvVarPrefix(gonic.NameUpper), - ); err != nil { - log.Fatalf("error parsing args: %v\n", 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") } @@ -179,7 +174,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 48f4def..2ee3053 100644 --- a/go.mod +++ b/go.mod @@ -21,13 +21,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/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 + 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 gopkg.in/gormigrate.v1 v1.6.0 @@ -61,7 +61,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 5ce0534..a276ec4 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,4 @@ cloud.google.com/go v0.33.1/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 h1:mFRzDkZVAjdal+s7s0MwaRv9igoPqLRdzOLzw/8Xvq8= -github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU= -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= @@ -108,7 +105,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= @@ -126,9 +122,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 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/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= @@ -138,8 +131,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= @@ -154,6 +147,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO 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-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= @@ -161,8 +156,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= @@ -218,7 +213,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/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc= +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= @@ -228,7 +224,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.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/lastfm/client.go b/lastfm/client.go index cc38eaa..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 { @@ -299,7 +301,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/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) diff --git a/podcast/podcast.go b/podcast/podcast.go index 45a2257..a8d0bf3 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 } @@ -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) 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