2021-11-13 02:07:07 -07:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
2021-11-20 07:51:54 -07:00
|
|
|
"errors"
|
2021-11-13 02:07:07 -07:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
2021-12-12 11:45:16 -07:00
|
|
|
|
2021-12-12 13:05:40 -07:00
|
|
|
"github.com/aditya-K2/goMP/utils"
|
2021-11-13 02:07:07 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-12-08 13:55:46 -07:00
|
|
|
CACHE_DIR string
|
|
|
|
DEFAULT_IMG string
|
2021-11-13 02:07:07 -07:00
|
|
|
)
|
|
|
|
|
2021-11-20 09:08:38 -07:00
|
|
|
func SetCacheDir(path string) {
|
2021-12-12 13:05:40 -07:00
|
|
|
CACHE_DIR = utils.CheckDirectoryFmt(path)
|
2021-11-20 09:08:38 -07:00
|
|
|
}
|
|
|
|
|
2021-12-08 13:55:46 -07:00
|
|
|
func Exists(artist, album string) bool {
|
|
|
|
if _, err := os.Stat(GenerateName(artist, album)); errors.Is(err, os.ErrNotExist) {
|
|
|
|
return false
|
2021-11-20 07:51:54 -07:00
|
|
|
} else {
|
2021-12-08 13:55:46 -07:00
|
|
|
return true
|
2021-11-13 02:07:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-13 02:17:26 -07:00
|
|
|
func GenerateName(artist, album string) string {
|
2021-12-08 13:55:46 -07:00
|
|
|
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)
|
2021-11-13 02:07:07 -07:00
|
|
|
}
|