mirror of
https://github.com/cgzirim/seek-tune.git
synced 2025-12-17 17:04:22 +00:00
Add new helper functions
This commit is contained in:
parent
4e93c857b5
commit
a56f6d14f9
1 changed files with 39 additions and 0 deletions
|
|
@ -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" {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue