improve handling of file updates

This commit is contained in:
Adrian Ulrich 2016-12-18 10:58:15 +01:00
parent da159cace2
commit 4429c50dec
2 changed files with 88 additions and 75 deletions

View File

@ -76,6 +76,14 @@ public class MediaMetadataExtractor extends HashMap<String, ArrayList<String>> {
return result;
}
/**
* Returns true if this file contains any (interesting) tags
* @return true if file is considered to be tagged
*/
public boolean isTagged() {
return (containsKey(TITLE) || containsKey(ALBUM) || containsKey(ARTIST));
}
/**
* Attempts to populate this instance with tags found in given path
*

View File

@ -157,26 +157,28 @@ public class MediaScanner implements Handler.Callback {
if (isBlacklisted(file))
return false;
long dbEntryMtime = mBackend.getSongMtime(songId) * 1000; // this is in unixtime -> convert to 'ms'
long fileMtime = file.lastModified();
boolean needsPurge = false;
boolean needsInsert = true;
boolean needsCleanup = false;
if (dbEntryMtime >= fileMtime) {
Log.v("VanillaMusic", "Skipping already known song with id "+songId);
return false;
return false; // on-disk mtime is older than db mtime -> nothing to do
}
if (dbEntryMtime != 0) {
// file on disk is newer: delete old entry and re-insert it
// fixme: drops play counts :-(
mBackend.delete(MediaLibrary.TABLE_SONGS, MediaLibrary.SongColumns._ID+"="+songId, null);
needsPurge = true;
needsCleanup = true;
}
MediaMetadataExtractor tags = new MediaMetadataExtractor(path);
if (tags.isEmpty())
return false; // file does not contain audio data
if (tags.isTagged() == false) {
needsInsert = false; // does not have any useable metadata: wont insert even if it is a playable file
}
if (needsInsert) {
// Get tags which always must be set
String title = tags.getFirst(MediaMetadataExtractor.TITLE);
if (title == null)
@ -260,11 +262,14 @@ public class MediaScanner implements Handler.Callback {
mBackend.insert(MediaLibrary.TABLE_GENRES_SONGS, null, v);
}
}
if (needsPurge)
} // end if (needsInsert)
if (needsCleanup)
mBackend.cleanOrphanedEntries();
Log.v("VanillaMusic", "MediaScanner: inserted "+path);
return true;
return (needsInsert || needsCleanup);
}
}