From 8d05089c9fb6381db70d6d8c2b124c0a90af4b10 Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Sat, 26 Nov 2016 19:47:27 +0100 Subject: [PATCH] brush up scanner --- .../android/medialibrary/MediaScanner.java | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/src/ch/blinkenlights/android/medialibrary/MediaScanner.java b/src/ch/blinkenlights/android/medialibrary/MediaScanner.java index 4be2d4dd..7af0d298 100644 --- a/src/ch/blinkenlights/android/medialibrary/MediaScanner.java +++ b/src/ch/blinkenlights/android/medialibrary/MediaScanner.java @@ -52,6 +52,11 @@ public class MediaScanner implements Handler.Callback { mHandler = new Handler(handlerThread.getLooper(), this); } + /** + * Initiates a scan at given directory + * + * @param dir the directory to scan + */ public void startScan(File dir) { mHandler.sendMessage(mHandler.obtainMessage(MSG_SCAN_DIRECTORY, 1, 0, dir)); } @@ -78,33 +83,54 @@ public class MediaScanner implements Handler.Callback { return true; } - + /** + * Scans a directory for indexable files + * + * @param dir the directory to scan + * @param recursive scan subdirs if true + */ private void scanDirectory(File dir, boolean recursive) { if (dir.isDirectory() == false) return; + if (new File(dir, ".nomedia").exists()) + return; + File[] dirents = dir.listFiles(); if (dirents == null) return; for (File file : dirents) { if (file.isFile()) { - Log.v("VanillaMusic", "MediaScanner: inspecting file "+file); - //scanFile(file); mHandler.sendMessage(mHandler.obtainMessage(MSG_SCAN_FILE, 0, 0, file)); - } - else if (file.isDirectory() && recursive) { - Log.v("VanillaMusic", "MediaScanner: scanning subdir "+file); - //scanDirectory(file, recursive); + } else if (file.isDirectory() && recursive) { mHandler.sendMessage(mHandler.obtainMessage(MSG_SCAN_DIRECTORY, 1, 0, file)); } } } + /** + * Returns true if the file should be scanned + * + * @param file the file to inspect + * @return boolean + */ + private boolean isWhitelisted(File file) { + return true; + } + + /** + * Scans a single file and adds it to the database + * + * @param file the file to scan + */ private void scanFile(File file) { String path = file.getAbsolutePath(); long songId = MediaLibrary.hash63(path); + if (isWhitelisted(file) == false) + return; + if (mBackend.isSongExisting(songId)) { Log.v("VanillaMusic", "Skipping already known song with id "+songId); return;