summaryrefslogtreecommitdiff
path: root/internal/gui/audio_paths.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-02 07:27:48 +0300
committerPaul Buetow <paul@buetow.org>2026-04-02 07:27:48 +0300
commitc1a2a5a1df54611437d36e1b2f448f78b32e8eb1 (patch)
tree504407e236c5192f0e2fb8eb3045669eccc6add0 /internal/gui/audio_paths.go
parente96cc2578595a0ec22a07819cd0eb1b0b0c711f7 (diff)
Fix GUI voice-suffixed audio discovery
Diffstat (limited to 'internal/gui/audio_paths.go')
-rw-r--r--internal/gui/audio_paths.go59
1 files changed, 3 insertions, 56 deletions
diff --git a/internal/gui/audio_paths.go b/internal/gui/audio_paths.go
index baee232..42402da 100644
--- a/internal/gui/audio_paths.go
+++ b/internal/gui/audio_paths.go
@@ -1,26 +1,13 @@
package gui
-import (
- "os"
- "path/filepath"
- "strings"
- "time"
-)
-
-var supportedAudioExtensions = map[string]struct{}{
- ".aac": {},
- ".flac": {},
- ".mp3": {},
- ".opus": {},
- ".wav": {},
-}
+import "codeberg.org/snonux/totalrecall/internal/anki"
func (a *Application) resolveSingleAudioFile(wordDir string) string {
- return resolveAudioFileByBaseName(wordDir, "audio")
+ return anki.ResolveAudioFile(wordDir, "audio", "")
}
func (a *Application) resolveBgBgAudioFiles(wordDir string) (string, string) {
- return resolveAudioFileByBaseName(wordDir, "audio_front"), resolveAudioFileByBaseName(wordDir, "audio_back")
+ return anki.ResolveAudioFile(wordDir, "audio_front", ""), anki.ResolveAudioFile(wordDir, "audio_back", "")
}
func (a *Application) hasAnyAudioFile(wordDir string) bool {
@@ -32,43 +19,3 @@ func (a *Application) hasAnyAudioFile(wordDir string) bool {
front, back := a.resolveBgBgAudioFiles(wordDir)
return front != "" || back != ""
}
-
-func resolveAudioFileByBaseName(wordDir, baseName string) string {
- entries, err := os.ReadDir(wordDir)
- if err != nil {
- return ""
- }
-
- prefix := baseName + "."
- var resolved string
- var resolvedModTime time.Time
-
- for _, entry := range entries {
- if entry.IsDir() {
- continue
- }
-
- name := entry.Name()
- if !strings.HasPrefix(name, prefix) {
- continue
- }
-
- ext := strings.ToLower(filepath.Ext(name))
- if _, ok := supportedAudioExtensions[ext]; !ok {
- continue
- }
-
- info, err := entry.Info()
- if err != nil {
- continue
- }
-
- candidate := filepath.Join(wordDir, name)
- if resolved == "" || info.ModTime().After(resolvedModTime) || (info.ModTime().Equal(resolvedModTime) && candidate < resolved) {
- resolved = candidate
- resolvedModTime = info.ModTime()
- }
- }
-
- return resolved
-}