Merge pull request #30 from JChris246/fix/no-title

[Fix] convert tags keys to lowercase
This commit is contained in:
Chigozirim Igweamaka 2025-03-15 14:23:46 +01:00 committed by GitHub
commit b6fc65eb73
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 11 deletions

View file

@ -296,9 +296,12 @@ func saveSong(filePath string, force bool) error {
return fmt.Errorf("failed to get YouTube ID for song: %v", err) return fmt.Errorf("failed to get YouTube ID for song: %v", err)
} }
fileName := strings.TrimSuffix(filepath.Base(filePath), filepath.Ext(filePath))
if track.Title == "" { 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 == "" { if track.Artist == "" {
return fmt.Errorf("no artist found in metadata") 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 // Move song in wav format to songs directory
fileName := strings.TrimSuffix(filepath.Base(filePath), filepath.Ext(filePath))
wavFile := fileName + ".wav" wavFile := fileName + ".wav"
sourcePath := filepath.Join(filepath.Dir(filePath), wavFile) sourcePath := filepath.Join(filepath.Dir(filePath), wavFile)
newFilePath := filepath.Join(SONGS_DIR, wavFile) newFilePath := filepath.Join(SONGS_DIR, wavFile)

View file

@ -307,7 +307,7 @@ func ProcessAndSaveSong(songFilePath, songTitle, songArtist, ytID string) error
err = dbclient.StoreFingerprints(fingerprints) err = dbclient.StoreFingerprints(fingerprints)
if err != nil { if err != nil {
dbclient.DeleteSongByID(songID) 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) fmt.Printf("Fingerprint for %v by %v saved in DB successfully\n", songTitle, songArtist)

View file

@ -2,22 +2,14 @@ package wav
import ( import (
"bytes" "bytes"
"context"
"encoding/base64"
"encoding/binary" "encoding/binary"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log/slog"
"os" "os"
"os/exec" "os/exec"
"song-recognition/models"
"song-recognition/utils"
"strings" "strings"
"time"
"github.com/mdobak/go-xerrors"
) )
// WavHeader defines the structure of a WAV header // WavHeader defines the structure of a WAV header
@ -207,6 +199,14 @@ func GetMetadata(filePath string) (FFmpegMetadata, error) {
return metadata, err 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 return metadata, nil
} }