Add new helper functions

This commit is contained in:
Chigozirim Igweamaka 2024-05-09 20:51:23 +01:00
parent 4e93c857b5
commit a56f6d14f9

View file

@ -8,6 +8,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
"song-recognition/utils"
"strings"
)
@ -46,6 +47,44 @@ func DeleteFile(filePath string) {
}
}
func SongKeyExists(key string) (bool, error) {
db, err := utils.NewDbClient()
if err != nil {
return false, err
}
defer db.Close()
song, err := db.GetSongByKey(key)
if err != nil && !strings.Contains(err.Error(), "song not found") {
return false, err
}
if song.Title == "" {
return false, nil
}
return true, nil
}
func YtIDExists(ytID string) (bool, error) {
db, err := utils.NewDbClient()
if err != nil {
return false, err
}
defer db.Close()
song, err := db.GetSongByYTID(ytID)
if err != nil && !strings.Contains(err.Error(), "song not found") {
return false, err
}
if song.Title == "" {
return false, nil
}
return true, nil
}
/* fixes some invalid file names (windows is the capricious one) */
func correctFilename(title, artist string) (string, string) {
if runtime.GOOS == "windows" {