소스 검색

Add: Album art cache

satoshi yoneda 6 년 전
부모
커밋
19cd9765af
1개의 변경된 파일7개의 추가작업 그리고 2개의 파일을 삭제
  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: