Moved checking folder for album art to only be within AlbumArtExtractor.
This commit is contained in:
parent
3fb9dd1fa6
commit
ae0947a570
@ -155,8 +155,6 @@ public class HibernateDatabase implements IDatabase{
|
||||
Optional<Album> albumObj = getOneAlbum(metadata.getAlbum());
|
||||
if (!albumObj.isPresent()) {
|
||||
byte[] art = AlbumArtExtractor.getImageData(new File(metadata.getSongFile()));
|
||||
if(art == null)
|
||||
AlbumArtExtractor.getImageDataFromFolder(metadata.getSongFile());
|
||||
Album album = new Album(metadata.getAlbum(), art);
|
||||
albumObj = Optional.of(album);
|
||||
}
|
||||
|
@ -153,11 +153,7 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt
|
||||
libraryDisplayVariants.get(libraryDisplayType.getSelectedItem().toString()).run();
|
||||
// If we get here and the model hasn't changed, the library must be empty.
|
||||
if (libraryTree.getModel() == model) {
|
||||
DefaultTreeModel failedModel = new DefaultTreeModel(new DefaultMutableTreeNode());
|
||||
DefaultMutableTreeNode failedParentNode = (DefaultMutableTreeNode) failedModel.getRoot();
|
||||
DefaultMutableTreeNode failedNode = new DefaultMutableTreeNode("Library is empty!");
|
||||
addNodeToTreeModel(failedModel, failedParentNode, failedNode);
|
||||
libraryTree.setModel(failedModel);
|
||||
showEmpty();
|
||||
}
|
||||
}, "libraryRefresh");
|
||||
populateThread.start();
|
||||
|
@ -36,22 +36,15 @@ public final class AlbumArtExtractor {
|
||||
try {
|
||||
audioTags = AudioFileIO.read(songFile).getTag();
|
||||
} catch (CannotReadException | IOException | ReadOnlyFileException | TagException | InvalidAudioFrameException e) {
|
||||
return null;
|
||||
return getImageDataFromFolder(songFile);
|
||||
}
|
||||
byte[] tmpArt = null;
|
||||
byte[] tmpArt;
|
||||
try {
|
||||
tmpArt = audioTags.getFirstArtwork().getBinaryData();
|
||||
BufferedImage image = ImageIO.read(new ByteArrayInputStream(tmpArt));
|
||||
tmpArt = convertImageToBytes(image);
|
||||
} catch (IOException | NullPointerException e) {
|
||||
try {
|
||||
Path dir = songFile.toPath().getParent();
|
||||
Optional<Path> imageFile = Files.walk(dir).filter(x -> x.toString().matches(albumArtRegex)).findFirst();
|
||||
if (imageFile.isPresent()) {
|
||||
Image actualImage = ImageIO.read(imageFile.get().toFile());
|
||||
tmpArt = convertImageToBytes(actualImage);
|
||||
}
|
||||
} catch (NullPointerException | IOException ignored) {}
|
||||
} catch (IOException | NullPointerException ignored) {
|
||||
return getImageDataFromFolder(songFile);
|
||||
}
|
||||
return tmpArt;
|
||||
}
|
||||
@ -90,9 +83,9 @@ public final class AlbumArtExtractor {
|
||||
*
|
||||
* @return BufferedImage of album art or Optional.empty()
|
||||
*/
|
||||
public static byte[] getImageDataFromFolder(String songFile) {
|
||||
Path dir = Paths.get(songFile).getParent();
|
||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.{jpg,png}")) {
|
||||
private static byte[] getImageDataFromFolder(File songFile) {
|
||||
Path dir = songFile.getParentFile().toPath();
|
||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, albumArtRegex)) {
|
||||
return convertImageToBytes(ImageIO.read(stream.iterator().next().toFile()));
|
||||
} catch (IOException | NoSuchElementException ignored) {
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user