ae1b05c203
Renaming goMP to gomp as it feels kind of awkward to have two upper case letters in a name of cli program.
35 lines
696 B
Go
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)
|
|
}
|