From fab95e291f9dbc705d7151dfde33d313bcaae45f Mon Sep 17 00:00:00 2001 From: RXWatcher <14085001+RXWatcher@users.noreply.github.com> Date: Sun, 24 May 2026 13:50:46 +0200 Subject: [PATCH] feat(audiobooks): library-type recognizers for scanner dispatch isAudiobookLibraryType and isPodcastLibraryType match singular and plural forms case-insensitively, mirroring isMovieLibraryType. Used by upcoming scanner walk branches (Task 4) that filter audio files into audiobook and podcast libraries. Co-Authored-By: Claude Opus 4.7 (1M context) --- internal/scanner/scanner.go | 16 +++++++++++++ internal/scanner/scanner_test.go | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/internal/scanner/scanner.go b/internal/scanner/scanner.go index b08de2be..6da29586 100644 --- a/internal/scanner/scanner.go +++ b/internal/scanner/scanner.go @@ -215,6 +215,22 @@ func isMovieLibraryType(libraryType string) bool { return false } } +func isAudiobookLibraryType(libraryType string) bool { + switch strings.ToLower(strings.TrimSpace(libraryType)) { + case "audiobook", "audiobooks": + return true + default: + return false + } +} +func isPodcastLibraryType(libraryType string) bool { + switch strings.ToLower(strings.TrimSpace(libraryType)) { + case "podcast", "podcasts": + return true + default: + return false + } +} func canonicalWalkPath(path string) (string, error) { resolved, err := filepath.EvalSymlinks(path) diff --git a/internal/scanner/scanner_test.go b/internal/scanner/scanner_test.go index 36c24e19..b59ffe0e 100644 --- a/internal/scanner/scanner_test.go +++ b/internal/scanner/scanner_test.go @@ -129,3 +129,43 @@ func testStringSliceContains(values []string, target string) bool { } return false } + +func TestIsAudiobookLibraryType(t *testing.T) { + cases := []struct { + in string + want bool + }{ + {"audiobooks", true}, + {"audiobook", true}, + {"Audiobook", true}, + {" AUDIOBOOKS ", true}, + {"movies", false}, + {"series", false}, + {"", false}, + } + for _, tc := range cases { + if got := isAudiobookLibraryType(tc.in); got != tc.want { + t.Errorf("isAudiobookLibraryType(%q) = %v, want %v", tc.in, got, tc.want) + } + } +} + +func TestIsPodcastLibraryType(t *testing.T) { + cases := []struct { + in string + want bool + }{ + {"podcasts", true}, + {"podcast", true}, + {"Podcast", true}, + {" PODCASTS ", true}, + {"series", false}, + {"audiobooks", false}, + {"", false}, + } + for _, tc := range cases { + if got := isPodcastLibraryType(tc.in); got != tc.want { + t.Errorf("isPodcastLibraryType(%q) = %v, want %v", tc.in, got, tc.want) + } + } +}