gomp/cache/cache.go
aditya-K2 ae1b05c203 RENAME : goMP -> gomp
Renaming goMP to gomp as it feels kind of awkward to have two upper case
letters in a name of cli program.
2021-12-17 01:06:18 +05:30

35 lines
696 B
Go

package cache
import (
"errors"
"fmt"
"os"
"strings"
"github.com/aditya-K2/gomp/utils"
)
var (
CACHE_DIR string
DEFAULT_IMG string
)
func SetCacheDir(path string) {
CACHE_DIR = utils.CheckDirectoryFmt(path)
}
func Exists(artist, album string) bool {
if _, err := os.Stat(GenerateName(artist, album)); errors.Is(err, os.ErrNotExist) {
return false
} else {
return true
}
}
func GenerateName(artist, album string) string {
if (artist == "" && album == "") || (artist == " " && album == " ") {
return CACHE_DIR + "UnknownArtist-UnknownAlbum.jpg"
}
return CACHE_DIR + strings.Replace(strings.Replace(fmt.Sprintf("%s-%s.jpg", artist, album), " ", "_", -1), "/", "_", -1)
}