gomp/cache/cache.go

35 lines
696 B
Go
Raw Normal View History

package cache
import (
"errors"
"fmt"
"os"
"strings"
2021-12-12 11:45:16 -07:00
"github.com/aditya-K2/gomp/utils"
)
var (
CACHE_DIR string
DEFAULT_IMG string
)
func SetCacheDir(path string) {
2021-12-12 13:05:40 -07:00
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
}
}
2021-11-13 02:17:26 -07:00
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)
}