Commits

Eduardo Ferreira committed 0b41145

Fixed major bug involving album covers.

Comments (0)

Files changed (2)

 	p3 = Popen(sed, stdin=p2.stdout, stdout=PIPE)
 	cover = p3.communicate()[0].rstrip("\n")
 
-	# Prepares the 'metaflac' program arguments:
-	# --export-picture-to => Export PICTURE block to a file
-	metaflac = ["metaflac", "--export-picture-to=" + cover, filename]
+	# Checks if the audio file has a cover
+	if cover is not None and len(cover) > 0:
+
+		# Prepares the 'metaflac' program arguments:
+		# --export-picture-to => Export PICTURE block to a file
+		metaflac = ["metaflac", "--export-picture-to=" + cover, filename]
 
-	# Invokes the 'metaflac' program to retrieve the cover file
-	call(metaflac)
+		# Invokes the 'metaflac' program to retrieve the cover file
+		call(metaflac)
 
 	return cover
 
 	# Prepares the ID3 tags to be passed as parameters of the 'lame' program
 	id3_flags = ["--tt", tag_values[0], "--ta", tag_values[1], "--tl", tag_values[2],
 				"--ty", tag_values[3], "--tn", tag_values[4] + "/" + tag_values[5],
-				"--tg", tag_values[6], "--ti", cover]
+				"--tg", tag_values[6]]
+
+	# Checks if the audio file has a cover
+	if cover is not None and len(cover) > 0:
+		id3_flags.extend(["--ti", cover])
 
 	# Prepares the 'lame' program arguments:
 	# -b 320          => Set the bitrate to 320 kbps
 	result = []
 
 	# Goes through the list of files in the folder
-	for root, dirs, files in os.walk(folder, topdown=False):
+	for root, dirs, files in os.walk(folder[0], topdown=False):
 		for name in files:
 			filename = os.path.join(root, name)
 
 			# Checks if the file has the desired extension (.flac)
-			if not name.endswith(extension):
+			if not name.endswith(audiolib.EXT_FLAC):
 				print ERROR_WRONG_FILE_TYPE.format(name, audiolib.EXT_FLAC)
 				continue
 
 		print ERROR_NO_FILES_GIVEN
 		return None
 
+	for stuff in result:
+		print "<", stuff, ">"
+
 	return result
 
 
 			cover = audiolib.get_cover(item)
 
 		tags = audiolib.decode_flac(item)
-		#audiolib.encode_wav_flac(item, tags)
+		audiolib.encode_wav_flac(item, tags)
 		audiolib.encode_wav_mp3(item, tags, cover, destination)
 		audiolib.cleanup(item)