Parcourir la source

extractCoverArt supported

satoshi yoneda il y a 6 ans
Parent
commit
6d9af70d68
1 fichiers modifiés avec 91 ajouts et 72 suppressions
  1. 91 72
      tree/usr/local/bin/superdac.py

+ 91 - 72
tree/usr/local/bin/superdac.py

@@ -29,6 +29,7 @@ import platform
 from select import select
 from time import sleep
 from urllib.parse import urlparse
+import subprocess
 
 # ABCMeta
 from abc import ABCMeta, abstractmethod
@@ -697,99 +698,117 @@ class MPD(Worker, threading.Thread):
 # Album art worker
 class AlbumArt(Worker, threading.Thread):
 	TEMP_DIR = '/var/tmp/.superdac.aa'
-
+	EXTRACTCA = '/usr/local/bin/extractCoverArt'
+	
 	term = False
 	refresh = False
 	prev_path = 'foobar'
 	term = False
+	use_folderjpg = True
 	
 	def __init__(self, pm):
 		threading.Thread.__init__(self)
 		Worker.__init__(self,pm)
 		self.messageq = queue.Queue()
-	
-	def getAlbumArt(self, config, current):
-		param = config.split('/')
-		if param[0] == 'smb:':
-			# SMB
-			musicfile = (current['file']).split('/')
-			remote_host = param[2]
-			share_name  = param[3]
-			
-			remote_path = '/'
-			for r in param[4:]:
-				remote_path = remote_path + r + '/'
-			for r in musicfile[0:len(musicfile)-1]:
-				remote_path = remote_path + r + '/'
+		
+		if os.path.exists(self.EXTRACTCA):
+			self.use_folderjpg = False
 			
-			try:
-				nmb = NetBIOS()
-				remote_ip = nmb.queryName(remote_host)[0]
-				if remote_ip is None: # 名前が引けない
+	def extractCoverArt(self, config, current):
+		if 'file' in current:
+			song_file = config + '/' + current['file']
+			if urlparse(song_file).scheme == 'smb':
+				song_path = config + '/' + os.path.dirname(current['file'])
+				song_ext = os.path.splitext(current['file'])[1]
+				remote_song = os.path.basename(current['file'])
+				smb = simpleSMB(song_path)
+				if smb.isEnable():
+					if smb.exists(remote_song):
+						if not os.path.exists(self.TEMP_DIR):
+							os.mkdir(self.TEMP_DIR)
+						if smb.copyTo(remote_song, self.TEMP_DIR+'/t'+ song_ext) == False:
+							return None
+						song_file = self.TEMP_DIR + '/t'+ song_ext
+					else:
+						del smb
+						return None
+				else:
+					del smb
 					return None
-				
-				con = SMBConnection('','',platform.uname().node, remote_host)
-				con.connect(remote_ip)
-				items = con.listPath(share_name, remote_path)
-				files = [item.filename for item in items]
-				aafile = ''
-				if 'Folder.jpg' in files:
-					aafile = remote_path + 'Folder.jpg'
-				elif 'folder.jpg' in files:
-					aafile = remote_Path + 'folder.jpg'
-				elif 'AlbumArt.jpg' in files:
-					aafile = remote_path + 'AlbumArt.jpg'
-				elif 'AlbumArtSmall.jpg' in files:
-					aafile = remote_path + 'AlbumArtSmall.jpg'
+				del smb
+			
+			if os.path.exists(song_file):
+				r = subprocess.run([self.EXTRACTCA, song_file, self.TEMP_DIR+'/aa.jpg'])
+				if r.returncode == 0:
+					return (self.TEMP_DIR+'/aa.jpg')
 				else:
-					con.close()
 					return None
-				
-				if not os.path.exists(self.TEMP_DIR):
-					os.mkdir(self.TEMP_DIR)
-				
-				with open( self.TEMP_DIR+'/aa.jpg', 'wb') as f:
-					con.retrieveFile(share_name, aafile, f)
-				
-				con.close()
-			except Exception as e:
-				print(e, file=self.playermain.out)
+			else:
 				return None
-			return self.TEMP_DIR+'/aa.jpg'
-		else:
-			path = config + '/' + os.path.dirname(current['file'])
-			imgfile = None
-			if os.path.exists( path+'/Folder.jpg'):
-				imgfile = path + '/Folder.jpg'
-			elif os.path.exists(path + '/folder.jpg'):
-				imgfile = path + '/folder.jpg'
-			elif  os.path.exists(path + '/AlbumArt.jpg'):
-				imgfile = path + '/AlbumArt.jpg'
-			elif  os.path.exists(path + '/AlbumArtSmall.jpg'):
-				imgfile = path + '/AlbumArtSmall.jpg'
-			return imgfile
 		return None
 	
+	def getFolderjpg(self, config, current):
+		if 'file' in current:
+			song_path = config + '/' + os.path.dirname(current['file'])
+			if urlparse(song_path).scheme == 'smb':
+				smb = simpleSMB(song_path)
+				if smb.isEnable():
+					aafile = None
+					if smb.exists('Folder.jpg'):
+						aafile = 'Folder.jpg'
+					elif smb.exists('folder.jpg'):
+						aafile = 'folder.jpg'
+						
+					elif smb.exists('AlbumArt.jpg'):
+						aafile = 'AlbumArt.jpg'
+					elif smb.exists('AlbumArtSmall.jpg'):
+						aafile = 'AlbumArtSmall.jpg'
+					
+					if aafile is None:
+						return None
+					if not os.path.exists(self.TEMP_DIR):
+						os.mkdir(self.TEMP_DIR)
+					if smb.copyTo(aafile, self.TEMP_DIR+'/aa.jpg') == False:
+						del smb
+						return None
+					else:
+						del smb
+						return (self.TEMP_DIR+'/aa.jpg')
+				else:
+					return None
+			else:
+				imgfile = None
+				if os.path.exists( song_path+'/Folder.jpg'):
+					imgfile = song_path + '/Folder.jpg'
+				elif os.path.exists(song_path + '/folder.jpg'):
+					imgfile = song_path + '/folder.jpg'
+				elif  os.path.exists(song_path + '/AlbumArt.jpg'):
+					imgfile = song_path + '/AlbumArt.jpg'
+				elif  os.path.exists(song_path + '/AlbumArtSmall.jpg'):
+					imgfile = song_path + '/AlbumArtSmall.jpg'
+				return imgfile
+			return None
+		return None
+		
 	def draw(self, param):
 		status  = param['status']
 		current = param['current']
 		config  = param['config']
-			
+		
 		imgfile = None
-		if 'file' in current:
-			path = config + '/' + os.path.dirname(current['file'])
-			# Album change
-			if path != self.prev_path:
-				self.prev_path = path
-				imgfile = self.getAlbumArt(config, current)
-				# アルバムアートがなければロゴ
-				if imgfile is None:
-					if os.path.exists(LOGO_FILE):
-						imgfile = LOGO_FILE
-		else: # 停止中かなにか
-			if imgfile is None:
-				if os.path.exists(LOGO_FILE):
-					imgfile = LOGO_FILE
+		if self.use_folderjpg:
+			if 'file' in current:
+				path = config + '/' + os.path.dirname(current['file'])
+				# Album change
+				if path != self.prev_path:
+					self.prev_path = path
+					imgfile = self.getFolderjpg(config, current)
+		else:
+			imgfile = self.extractCoverArt(config, current)
+		
+		if imgfile is None:
+			if os.path.exists( LOGO_FILE ):
+				imgfile = LOGO_FILE
 		
 		# Display AlbumArt
 		if imgfile is not None: