From c69cb8cf35203c6db15d3c1bd68a86cb91108b40 Mon Sep 17 00:00:00 2001 From: sentriz Date: Tue, 30 Sep 2025 13:42:27 +0100 Subject: [PATCH] feat(gonic): add `scan-embedded-cover-enabled` flag --- README.md | 51 +++++++++++++++++++++++----------------------- cmd/gonic/gonic.go | 4 +++- mockfs/mockfs.go | 2 +- scanner/scanner.go | 6 ++++-- 4 files changed, 34 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index c03b854..64e6866 100644 --- a/README.md +++ b/README.md @@ -49,31 +49,32 @@ password can then be changed from the web interface ## configuration options -| env var | command line arg | description | -| -------------------------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `GONIC_MUSIC_PATH` | `-music-path` | path to your music collection (see also multi-folder support below) | -| `GONIC_PODCAST_PATH` | `-podcast-path` | path to a podcasts directory | -| `GONIC_PLAYLISTS_PATH` | `-playlists-path` | path to new or existing directory with m3u files for subsonic playlists. items in the directory should be in the format `/.m3u`. for example the admin user could have `1/my-playlist.m3u`. gonic create and make changes to these playlists over the subsonic api. | -| `GONIC_CACHE_PATH` | `-cache-path` | path to store audio transcodes, covers, etc | -| `GONIC_DB_PATH` | `-db-path` | **optional** path to database file | -| `GONIC_HTTP_LOG` | `-http-log` | **optional** http request logging, enabled by default | -| `GONIC_LISTEN_ADDR` | `-listen-addr` | **optional** host and port to listen on (eg. `0.0.0.0:4747`, `127.0.0.1:4747`) (_default_ `0.0.0.0:4747`) | -| `GONIC_TLS_CERT` | `-tls-cert` | **optional** path to a TLS cert (enables HTTPS listening) | -| `GONIC_TLS_KEY` | `-tls-key` | **optional** path to a TLS key (enables HTTPS listening) | -| `GONIC_PROXY_PREFIX` | `-proxy-prefix` | **optional** url path prefix to use if behind reverse proxy. eg `/gonic` (see example configs below) | -| `GONIC_SCAN_INTERVAL` | `-scan-interval` | **optional** interval (in minutes) to check for new music (automatic scanning disabled if omitted) | -| `GONIC_SCAN_AT_START_ENABLED` | `-scan-at-start-enabled` | **optional** whether to perform an initial scan at startup | -| `GONIC_SCAN_WATCHER_ENABLED` | `-scan-watcher-enabled` | **optional** whether to watch file system for new music and rescan | -| `GONIC_JUKEBOX_ENABLED` | `-jukebox-enabled` | **optional** whether the subsonic [jukebox api](https://airsonic.github.io/docs/jukebox/) should be enabled | -| `GONIC_JUKEBOX_MPV_EXTRA_ARGS` | `-jukebox-mpv-extra-args` | **optional** extra command line arguments to pass to the jukebox mpv daemon | -| `GONIC_PODCAST_PURGE_AGE` | `-podcast-purge-age` | **optional** age (in days) to purge podcast episodes if not accessed | -| `GONIC_EXCLUDE_PATTERN` | `-exclude-pattern` | **optional** files matching this regex pattern will not be imported. eg @eaDir\|[aA]rtwork\|[cC]overs\|[sS]cans\|[sS]pectrals | -| `GONIC_MULTI_VALUE_GENRE` | `-multi-value-genre` | **optional** setting for multi-valued genre tags when scanning ([see more](#multi-valued-tags-v016)) | -| `GONIC_MULTI_VALUE_ARTIST` | `-multi-value-artist` | **optional** setting for multi-valued artist tags when scanning ([see more](#multi-valued-tags-v016)) | -| `GONIC_MULTI_VALUE_ALBUM_ARTIST` | `-multi-value-album-artist` | **optional** setting for multi-valued album artist tags when scanning ([see more](#multi-valued-tags-v016)) | -| `GONIC_TRANSCODE_CACHE_SIZE` | `-transcode-cache-size` | **optional** size of the transcode cache in MB (0 = no limit) | -| `GONIC_TRANSCODE_EJECT_INTERVAL` | `-transcode-eject-interval` | **optional** interval (in minutes) to eject transcode cache (0 = never) | -| `GONIC_EXPVAR` | `-expvar` | **optional** enable the /debug/vars endpoint (exposes useful debugging attributes as well as database stats) | +| env var | command line arg | description | +| ----------------------------------- | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `GONIC_MUSIC_PATH` | `-music-path` | path to your music collection (see also multi-folder support below) | +| `GONIC_PODCAST_PATH` | `-podcast-path` | path to a podcasts directory | +| `GONIC_PLAYLISTS_PATH` | `-playlists-path` | path to new or existing directory with m3u files for subsonic playlists. items in the directory should be in the format `/.m3u`. for example the admin user could have `1/my-playlist.m3u`. gonic create and make changes to these playlists over the subsonic api. | +| `GONIC_CACHE_PATH` | `-cache-path` | path to store audio transcodes, covers, etc | +| `GONIC_DB_PATH` | `-db-path` | **optional** path to database file | +| `GONIC_HTTP_LOG` | `-http-log` | **optional** http request logging, enabled by default | +| `GONIC_LISTEN_ADDR` | `-listen-addr` | **optional** host and port to listen on (eg. `0.0.0.0:4747`, `127.0.0.1:4747`) (_default_ `0.0.0.0:4747`) | +| `GONIC_TLS_CERT` | `-tls-cert` | **optional** path to a TLS cert (enables HTTPS listening) | +| `GONIC_TLS_KEY` | `-tls-key` | **optional** path to a TLS key (enables HTTPS listening) | +| `GONIC_PROXY_PREFIX` | `-proxy-prefix` | **optional** url path prefix to use if behind reverse proxy. eg `/gonic` (see example configs below) | +| `GONIC_SCAN_INTERVAL` | `-scan-interval` | **optional** interval (in minutes) to check for new music (automatic scanning disabled if omitted) | +| `GONIC_SCAN_AT_START_ENABLED` | `-scan-at-start-enabled` | **optional** whether to perform an initial scan at startup | +| `GONIC_SCAN_WATCHER_ENABLED` | `-scan-watcher-enabled` | **optional** whether to watch file system for new music and rescan | +| `GONIC_SCAN_EMBEDDED_COVER_ENABLED` | `-scan-embedded-cover-enabled` | **optional** whether to scan for embedded covers in audio files (_default_ `true`) | +| `GONIC_JUKEBOX_ENABLED` | `-jukebox-enabled` | **optional** whether the subsonic [jukebox api](https://airsonic.github.io/docs/jukebox/) should be enabled | +| `GONIC_JUKEBOX_MPV_EXTRA_ARGS` | `-jukebox-mpv-extra-args` | **optional** extra command line arguments to pass to the jukebox mpv daemon | +| `GONIC_PODCAST_PURGE_AGE` | `-podcast-purge-age` | **optional** age (in days) to purge podcast episodes if not accessed | +| `GONIC_EXCLUDE_PATTERN` | `-exclude-pattern` | **optional** files matching this regex pattern will not be imported. eg @eaDir\|[aA]rtwork\|[cC]overs\|[sS]cans\|[sS]pectrals | +| `GONIC_MULTI_VALUE_GENRE` | `-multi-value-genre` | **optional** setting for multi-valued genre tags when scanning ([see more](#multi-valued-tags-v016)) | +| `GONIC_MULTI_VALUE_ARTIST` | `-multi-value-artist` | **optional** setting for multi-valued artist tags when scanning ([see more](#multi-valued-tags-v016)) | +| `GONIC_MULTI_VALUE_ALBUM_ARTIST` | `-multi-value-album-artist` | **optional** setting for multi-valued album artist tags when scanning ([see more](#multi-valued-tags-v016)) | +| `GONIC_TRANSCODE_CACHE_SIZE` | `-transcode-cache-size` | **optional** size of the transcode cache in MB (0 = no limit) | +| `GONIC_TRANSCODE_EJECT_INTERVAL` | `-transcode-eject-interval` | **optional** interval (in minutes) to eject transcode cache (0 = never) | +| `GONIC_EXPVAR` | `-expvar` | **optional** enable the /debug/vars endpoint (exposes useful debugging attributes as well as database stats) | ## multi valued tags (v0.16+) diff --git a/cmd/gonic/gonic.go b/cmd/gonic/gonic.go index 0903067..67f359e 100644 --- a/cmd/gonic/gonic.go +++ b/cmd/gonic/gonic.go @@ -68,6 +68,7 @@ func main() { 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)") + confScanEmbeddedCover := flag.Bool("scan-embedded-cover-enabled", true, "whether to scan for embedded covers in audio files (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)") @@ -177,7 +178,7 @@ func main() { log.Printf("provided config\n") flag.VisitAll(func(f *flag.Flag) { value := strings.ReplaceAll(f.Value.String(), "\n", "") - log.Printf(" %-25s %s\n", f.Name, value) + log.Printf(" %-30s %s\n", f.Name, value) }) scannr := scanner.New( @@ -190,6 +191,7 @@ func main() { }, tagReader, *confExcludePattern, + *confScanEmbeddedCover, ) podcast := podcast.New(dbc, *confPodcastPath, tagReader) transcoder := transcode.NewCachingTranscoder( diff --git a/mockfs/mockfs.go b/mockfs/mockfs.go index 42505dc..6edd4bf 100644 --- a/mockfs/mockfs.go +++ b/mockfs/mockfs.go @@ -68,7 +68,7 @@ func newMockFS(tb testing.TB, dirs []string, excludePattern string) *MockFS { } tagReader := &tagReader{paths: map[string]*TagInfo{}} - scanner := scanner.New(absDirs, dbc, multiValueSettings, tagReader, excludePattern) + scanner := scanner.New(absDirs, dbc, multiValueSettings, tagReader, excludePattern, true) return &MockFS{ t: tb, diff --git a/scanner/scanner.go b/scanner/scanner.go index b9dbbec..2d7c77e 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -41,10 +41,11 @@ type Scanner struct { multiValueSettings map[Tag]MultiValueSetting tagReader tags.Reader excludePattern *regexp.Regexp + scanEmbeddedCover bool scanning *int32 } -func New(musicDirs []string, db *db.DB, multiValueSettings map[Tag]MultiValueSetting, tagReader tags.Reader, excludePattern string) *Scanner { +func New(musicDirs []string, db *db.DB, multiValueSettings map[Tag]MultiValueSetting, tagReader tags.Reader, excludePattern string, scanEmbeddedCover bool) *Scanner { var excludePatternRegExp *regexp.Regexp if excludePattern != "" { excludePatternRegExp = regexp.MustCompile(excludePattern) @@ -56,6 +57,7 @@ func New(musicDirs []string, db *db.DB, multiValueSettings map[Tag]MultiValueSet multiValueSettings: multiValueSettings, tagReader: tagReader, excludePattern: excludePatternRegExp, + scanEmbeddedCover: scanEmbeddedCover, scanning: new(int32), } } @@ -452,7 +454,7 @@ func (s *Scanner) populateTrackAndArtists(tx *db.DB, st *State, i int, album *db } // embedded covers come only from the first track - if i == 0 && album.Cover == "" && track.ID > 0 { + if i == 0 && s.scanEmbeddedCover && album.Cover == "" && track.ID > 0 { if err := populateEmbeddedCover(tx, s.tagReader, album, track, absPath); err != nil { return fmt.Errorf("populate embedded cover: %w", err) }