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