Explorar o código

Add: Album art cache

satoshi yoneda %!s(int64=6) %!d(string=hai) anos
pai
achega
19cd9765af
Modificáronse 1 ficheiros con 7 adicións e 2 borrados
  1. 7 2
      tree/usr/local/bin/superdac.py

+ 7 - 2
tree/usr/local/bin/superdac.py

@@ -30,6 +30,7 @@ from select import select
 from time import sleep
 from urllib.parse import urlparse
 import subprocess
+import hashlib
 
 # ABCMeta
 from abc import ABCMeta, abstractmethod
@@ -717,6 +718,10 @@ class AlbumArt(Worker, threading.Thread):
 	def extractCoverArt(self, config, current):
 		if 'file' in current:
 			song_file = config + '/' + current['file']
+			cache_file = self.TEMP_DIR + '/' + hashlib.sha256(song_file.encode()).hexdigest() + '.jpg'
+			if os.path.exists(cache_file):
+				return cache_file
+			
 			if urlparse(song_file).scheme == 'smb':
 				song_path = config + '/' + os.path.dirname(current['file'])
 				song_ext = os.path.splitext(current['file'])[1]
@@ -738,9 +743,9 @@ class AlbumArt(Worker, threading.Thread):
 				del smb
 			
 			if os.path.exists(song_file):
-				r = subprocess.run([self.EXTRACTCA, song_file, self.TEMP_DIR+'/aa.jpg'])
+				r = subprocess.run([self.EXTRACTCA, song_file, cache_file])
 				if r.returncode == 0:
-					return (self.TEMP_DIR+'/aa.jpg')
+					return cache_file
 				else:
 					return None
 			else: