diff options
-rw-r--r-- | src/github/daneren2005/dsub/service/RESTMusicService.java | 18 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/util/FileUtil.java | 24 |
2 files changed, 30 insertions, 12 deletions
diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java index 951a182d..c5438267 100644 --- a/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -654,17 +654,13 @@ public class RESTMusicService implements MusicService { } byte[] bytes = Util.toByteArray(in); - - File albumDir = FileUtil.getAlbumDirectory(context, entry); - if (albumDir.exists()) { - OutputStream out = null; - try { - out = new FileOutputStream(FileUtil.getAlbumArtFile(albumDir)); - out.write(bytes); - } finally { - Util.close(out); - } - } + OutputStream out = null; + try { + out = new FileOutputStream(FileUtil.getAlbumArtFile(context, entry)); + out.write(bytes); + } finally { + Util.close(out); + } bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); if(size != saveSize) { diff --git a/src/github/daneren2005/dsub/util/FileUtil.java b/src/github/daneren2005/dsub/util/FileUtil.java index 87ec571b..524cfe70 100644 --- a/src/github/daneren2005/dsub/util/FileUtil.java +++ b/src/github/daneren2005/dsub/util/FileUtil.java @@ -139,21 +139,43 @@ public class FileUtil { public static File getAlbumArtFile(Context context, MusicDirectory.Entry entry) { File albumDir = getAlbumDirectory(context, entry); - return getAlbumArtFile(albumDir); + File artFile; + File albumFile = getAlbumArtFile(albumDir); + File hexFile = getHexAlbumArtFile(albumDir); + if(albumDir.exists()) { + if(hexFile.exists()) { + hexFile.renameTo(albumFile); + } + artFile = albumFile; + } else { + artFile = hexFile; + } + return artFile; } public static File getAlbumArtFile(File albumDir) { return new File(albumDir, Constants.ALBUM_ART_FILE); } + public static File getHexAlbumArtFile(File albumDir) { + return new File(getAlbumArtDirectory(), Util.md5Hex(albumDir.getPath()) + ".jpeg"); + } public static Bitmap getAlbumArtBitmap(Context context, MusicDirectory.Entry entry, int size) { File albumArtFile = getAlbumArtFile(context, entry); + Log.d(TAG, albumArtFile.toString()); if (albumArtFile.exists()) { Bitmap bitmap = BitmapFactory.decodeFile(albumArtFile.getPath()); return (bitmap == null) ? null : Bitmap.createScaledBitmap(bitmap, size, size, true); } return null; } + + public static File getAlbumArtDirectory() { + File albumArtDir = new File(getSubsonicDirectory(), "artwork"); + ensureDirectoryExistsAndIsReadWritable(albumArtDir); + ensureDirectoryExistsAndIsReadWritable(new File(albumArtDir, ".nomedia")); + return albumArtDir; + } public static File getArtistDirectory(Context context, Artist artist) { File dir = new File(getMusicDirectory(context).getPath() + "/" + fileSystemSafe(artist.getName())); |