diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-01-21 14:32:19 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-01-21 14:32:19 -0800 |
commit | 4e04a4f0ed6298cf5fd69fd87abba5c2fa7dd6cb (patch) | |
tree | c6d279e71aff583cf0223484348c15bfebf96b57 /subsonic-android/src/github | |
parent | 411e408140025f433f0c92f0eca6ca0961ead8ea (diff) | |
download | dsub-4e04a4f0ed6298cf5fd69fd87abba5c2fa7dd6cb.tar.gz dsub-4e04a4f0ed6298cf5fd69fd87abba5c2fa7dd6cb.tar.bz2 dsub-4e04a4f0ed6298cf5fd69fd87abba5c2fa7dd6cb.zip |
Closes #62 Keep the cached album art in the same dir as the music
Diffstat (limited to 'subsonic-android/src/github')
4 files changed, 15 insertions, 22 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java index c7413b54..9d77026c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -583,10 +583,11 @@ public class RESTMusicService implements MusicService { byte[] bytes = Util.toByteArray(in); - if (saveToFile) { + File albumDir = FileUtil.getAlbumDirectory(context, entry); + if (saveToFile && albumDir.exists()) { OutputStream out = null; try { - out = new FileOutputStream(FileUtil.getAlbumArtFile(context, entry)); + out = new FileOutputStream(FileUtil.getAlbumArtFile(albumDir)); out.write(bytes); } finally { Util.close(out); diff --git a/subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java b/subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java index 83c2c415..3b88f00e 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java @@ -51,11 +51,16 @@ public class CacheCleaner { } File[] children = dir.listFiles(); + + // No songs left in the folder + if(children.length == 1 && children[0].getPath().equals(FileUtil.getAlbumArtFile(dir).getPath())) { + Util.delete(FileUtil.getAlbumArtFile(dir)); + children = dir.listFiles(); + } - // Delete empty directory and associated album artwork. + // Delete empty directory if (children.length == 0) { Util.delete(dir); - Util.delete(FileUtil.getAlbumArtFile(dir)); } } } @@ -96,12 +101,8 @@ public class CacheCleaner { for (File file : files) { if(!deletePartials && bytesDeleted > bytesToDelete) break; - if (file.getName().equals(Constants.ALBUM_ART_FILE)) { - // Move artwork to new folder. - file.renameTo(FileUtil.getAlbumArtFile(file.getParentFile())); - - } else if (bytesToDelete > bytesDeleted || (deletePartials && (file.getName().endsWith(".partial") || file.getName().contains(".partial.")))) { - if (!undeletable.contains(file)) { + if (bytesToDelete > bytesDeleted || (deletePartials && (file.getName().endsWith(".partial") || file.getName().contains(".partial.")))) { + if (!undeletable.contains(file) && !file.getName().equals(Constants.ALBUM_ART_FILE)) { long size = file.length(); if (Util.delete(file)) { bytesDeleted += size; @@ -117,8 +118,7 @@ public class CacheCleaner { if (file.isFile()) { String name = file.getName(); boolean isCacheFile = name.endsWith(".partial") || name.contains(".partial.") || name.endsWith(".complete") || name.contains(".complete."); - boolean isAlbumArtFile = name.equals(Constants.ALBUM_ART_FILE); - if (isCacheFile || isAlbumArtFile) { + if (isCacheFile) { files.add(file); } } else { diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java index 4dac8d4c..0490b3d3 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java @@ -97,7 +97,7 @@ public final class Constants { // URL for project donations. public static final String DONATION_URL = "http://subsonic.org/pages/android-donation.jsp"; - public static final String ALBUM_ART_FILE = "folder.jpeg"; + public static final String ALBUM_ART_FILE = "cover.jpeg"; private Constants() { } diff --git a/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java b/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java index 43eccdf8..bb89a4d3 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java @@ -94,8 +94,7 @@ public class FileUtil { } public static File getAlbumArtFile(File albumDir) { - File albumArtDir = getAlbumArtDirectory(); - return new File(albumArtDir, Util.md5Hex(albumDir.getPath()) + ".jpeg"); + return new File(albumDir, Constants.ALBUM_ART_FILE); } public static Bitmap getAlbumArtBitmap(Context context, MusicDirectory.Entry entry, int size) { @@ -106,13 +105,6 @@ public class FileUtil { } 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())); |