diff --git a/cmdHandlers.go b/cmdHandlers.go index 3a2dc81..3330450 100644 --- a/cmdHandlers.go +++ b/cmdHandlers.go @@ -296,9 +296,12 @@ func saveSong(filePath string, force bool) error { return fmt.Errorf("failed to get YouTube ID for song: %v", err) } + fileName := strings.TrimSuffix(filepath.Base(filePath), filepath.Ext(filePath)) if track.Title == "" { - return fmt.Errorf("no title found in metadata") + // If title is empty, use the file name + track.Title = fileName } + if track.Artist == "" { return fmt.Errorf("no artist found in metadata") } @@ -309,7 +312,6 @@ func saveSong(filePath string, force bool) error { } // Move song in wav format to songs directory - fileName := strings.TrimSuffix(filepath.Base(filePath), filepath.Ext(filePath)) wavFile := fileName + ".wav" sourcePath := filepath.Join(filepath.Dir(filePath), wavFile) newFilePath := filepath.Join(SONGS_DIR, wavFile) diff --git a/spotify/downloader.go b/spotify/downloader.go index 5601909..1e32841 100644 --- a/spotify/downloader.go +++ b/spotify/downloader.go @@ -307,7 +307,7 @@ func ProcessAndSaveSong(songFilePath, songTitle, songArtist, ytID string) error err = dbclient.StoreFingerprints(fingerprints) if err != nil { dbclient.DeleteSongByID(songID) - return fmt.Errorf("error to storing fingerpring: %v", err) + return fmt.Errorf("error to storing fingerprint: %v", err) } fmt.Printf("Fingerprint for %v by %v saved in DB successfully\n", songTitle, songArtist) diff --git a/wav/wav.go b/wav/wav.go index 99e6539..240b370 100644 --- a/wav/wav.go +++ b/wav/wav.go @@ -2,22 +2,14 @@ package wav import ( "bytes" - "context" - "encoding/base64" "encoding/binary" "encoding/json" "errors" "fmt" "io/ioutil" - "log/slog" "os" "os/exec" - "song-recognition/models" - "song-recognition/utils" "strings" - "time" - - "github.com/mdobak/go-xerrors" ) // WavHeader defines the structure of a WAV header @@ -207,6 +199,14 @@ func GetMetadata(filePath string) (FFmpegMetadata, error) { return metadata, err } + // convert all keys of the Tags map to lowercase + for k, v := range metadata.Format.Tags { + metadata.Format.Tags[strings.ToLower(k)] = v + } + for k, v := range metadata.Streams[0].Tags { + metadata.Streams[0].Tags[strings.ToLower(k)] = v + } + return metadata, nil }