From 1e0306340053da0c3ce121e97e12ceb88b0051f2 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Thu, 10 Mar 2016 10:46:01 -0600 Subject: [PATCH] MediaLibrary scan now reports file counts for its scan. --- .../wdiwtlt/cli/CommandLineInterface.groovy | 5 +++-- .../com/jdbernard/wdiwtlt/MediaLibrary.groovy | 21 +++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy b/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy index 499082d..0967387 100644 --- a/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy +++ b/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy @@ -290,8 +290,9 @@ Configuration: public MediaLibrary scanMediaLibrary() { status.text = "Scanning media library..." - library.rescanLibrary() - status.text = "Scanned ? files." + def counts = library.rescanLibrary() + status.text = "Scanned ${counts.total} files. " + + "Added ${counts.new} and ignored ${counts.ignored} files." dismissMsgDate = new Date(new Date().time + msgTimeout) return library } diff --git a/core/src/main/groovy/com/jdbernard/wdiwtlt/MediaLibrary.groovy b/core/src/main/groovy/com/jdbernard/wdiwtlt/MediaLibrary.groovy index 7fbcd45..6c064b3 100644 --- a/core/src/main/groovy/com/jdbernard/wdiwtlt/MediaLibrary.groovy +++ b/core/src/main/groovy/com/jdbernard/wdiwtlt/MediaLibrary.groovy @@ -35,7 +35,20 @@ public class MediaLibrary { orm.removeEmptyPlaylists() } - public void rescanLibrary() { libraryRoot.eachFileRecurse { addFile(it) } } + public def rescanLibrary() { + def results = [ total: 0, ignored: 0, new: 0] + + Date startDate = new Date() + libraryRoot.eachFileRecurse { file -> + + if (!file.isFile()) return + def mf = addFile(file) + + results.total++ + if (!mf) results.ignored++ + else if (mf.dateAdded > startDate) results.new++ } + + return results } public MediaFile addFile(File f) { if (!f.exists() || !f.isFile()) { @@ -56,9 +69,9 @@ public class MediaLibrary { try { af = AudioFileIO.read(f) } catch (Exception e) { - logger.info("Ignoring a file because I can't" + - "read the media tag info:\n\t{}", - e.localizedMessage) + logger.info("Ignoring a file because I can't " + + "read the media tag info:\n\t{}\n\t{}", + f.canonicalPath, e.localizedMessage) return null } def fileTag = af.tag