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:
		
							parent
							
								
									68ef09544c
								
							
						
					
					
						commit
						b91120252b
					
				
							
								
								
									
										15
									
								
								render.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								render.go
									
									
									
									
									
								
							@ -1,6 +1,7 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/aditya-K2/goMP/cache"
 | 
			
		||||
	"github.com/spf13/viper"
 | 
			
		||||
	"gitlab.com/diamondburned/ueberzug-go"
 | 
			
		||||
)
 | 
			
		||||
@ -43,18 +44,24 @@ func openImage(path string, c chan string) {
 | 
			
		||||
	fw, fh := getFontWidth()
 | 
			
		||||
	var im *ueberzug.Image
 | 
			
		||||
	if path != "stop" {
 | 
			
		||||
		absPath := viper.GetString("MUSIC_DIRECTORY") + path
 | 
			
		||||
		extractedImage := extractImageFromFile(absPath)
 | 
			
		||||
		if extractedImage == viper.GetString("DEFAULT_IMAGE_PATH") && viper.GetString("GET_COVER_ART_FROM_LAST_FM") == "TRUE" {
 | 
			
		||||
		a, err := CONN.ListInfo(path)
 | 
			
		||||
		var extractedImage string
 | 
			
		||||
		if err == nil && len(a) != 0 {
 | 
			
		||||
				downloadedImage, err := getImageFromLastFM(a[0]["artist"], a[0]["album"])
 | 
			
		||||
			if val, err := cache.GetFromCache(a[0]["artist"], a[0]["album"]); err == nil {
 | 
			
		||||
				extractedImage = val
 | 
			
		||||
			} else {
 | 
			
		||||
				imagePath := cache.AddToCache(a[0]["artist"], a[0]["album"])
 | 
			
		||||
				absPath := viper.GetString("MUSIC_DIRECTORY") + path
 | 
			
		||||
				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
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		img2, _ := getImg(extractedImage)
 | 
			
		||||
		im, _ = ueberzug.NewImage(img2, int(float32(IMG_X)*fw)+viper.GetInt("ADDITIONAL_PADDING_X"), int(float32(IMG_Y)*fh)+viper.GetInt("ADDITIONAL_PADDING_Y"))
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user