diff --git a/src/main/java/musicplayer/db/HibernateDatabase.java b/src/main/java/musicplayer/db/HibernateDatabase.java index cdb2f70..919a483 100644 --- a/src/main/java/musicplayer/db/HibernateDatabase.java +++ b/src/main/java/musicplayer/db/HibernateDatabase.java @@ -155,8 +155,6 @@ public class HibernateDatabase implements IDatabase{ Optional 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); } diff --git a/src/main/java/musicplayer/library/JTreeLibrary.java b/src/main/java/musicplayer/library/JTreeLibrary.java index cdbe2fa..a5fbb5d 100644 --- a/src/main/java/musicplayer/library/JTreeLibrary.java +++ b/src/main/java/musicplayer/library/JTreeLibrary.java @@ -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(); diff --git a/src/main/java/musicplayer/util/AlbumArtExtractor.java b/src/main/java/musicplayer/util/AlbumArtExtractor.java index 378ea7d..a917088 100644 --- a/src/main/java/musicplayer/util/AlbumArtExtractor.java +++ b/src/main/java/musicplayer/util/AlbumArtExtractor.java @@ -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 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 stream = Files.newDirectoryStream(dir, "*.{jpg,png}")) { + private static byte[] getImageDataFromFolder(File songFile) { + Path dir = songFile.getParentFile().toPath(); + try (DirectoryStream stream = Files.newDirectoryStream(dir, albumArtRegex)) { return convertImageToBytes(ImageIO.read(stream.iterator().next().toFile())); } catch (IOException | NoSuchElementException ignored) { return null;