Simple Implementation of caching

Now before rendering the image the image is checked in the cache if it
exists then the image is rendered else it is added to the cache and then
rendered.
This commit is contained in:
aditya-K2 2021-11-20 21:47:43 +05:30
parent 68ef09544c
commit b91120252b

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"github.com/aditya-K2/goMP/cache"
"github.com/spf13/viper" "github.com/spf13/viper"
"gitlab.com/diamondburned/ueberzug-go" "gitlab.com/diamondburned/ueberzug-go"
) )
@ -43,15 +44,21 @@ func openImage(path string, c chan string) {
fw, fh := getFontWidth() fw, fh := getFontWidth()
var im *ueberzug.Image var im *ueberzug.Image
if path != "stop" { if path != "stop" {
absPath := viper.GetString("MUSIC_DIRECTORY") + path a, err := CONN.ListInfo(path)
extractedImage := extractImageFromFile(absPath) var extractedImage string
if extractedImage == viper.GetString("DEFAULT_IMAGE_PATH") && viper.GetString("GET_COVER_ART_FROM_LAST_FM") == "TRUE" { if err == nil && len(a) != 0 {
a, err := CONN.ListInfo(path) if val, err := cache.GetFromCache(a[0]["artist"], a[0]["album"]); err == nil {
if err == nil && len(a) != 0 { extractedImage = val
downloadedImage, err := getImageFromLastFM(a[0]["artist"], a[0]["album"]) } else {
if err == nil { imagePath := cache.AddToCache(a[0]["artist"], a[0]["album"])
NOTIFICATION_SERVER.Send("Image From LastFM") absPath := viper.GetString("MUSIC_DIRECTORY") + path
extractedImage = downloadedImage extractedImage = extractImageFromFile(absPath, imagePath)
if extractedImage == viper.GetString("DEFAULT_IMAGE_PATH") && viper.GetString("GET_COVER_ART_FROM_LAST_FM") == "TRUE" {
downloadedImage, err := getImageFromLastFM(a[0]["artist"], a[0]["album"], imagePath)
if err == nil {
NOTIFICATION_SERVER.Send("Image From LastFM")
extractedImage = downloadedImage
}
} }
} }
} }