Skip to content

Commit

Permalink
Make music scanning much more forgiving
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Jun 25, 2017
1 parent f20c67b commit 5ded061
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ app.on('ready', () => {
state.currentIndex = newIndex
queue(null, newIndex)
if (state.playing) { broadcast('play') }
} else { console.warn('Can go back, empty trackOrder array') }
} else { console.warn('Can\'t go back, empty trackOrder array') }
}

ipcMain.on('prev', prev)
Expand All @@ -117,7 +117,7 @@ app.on('ready', () => {
state.currentIndex = newIndex
queue(null, newIndex)
if (state.playing) { broadcast('play') }
} else { console.warn('Can go forward, empty trackOrder array') }
} else { console.warn('Can\'t go forward, empty trackOrder array') }
}

ipcMain.on('next', next)
Expand Down
10 changes: 8 additions & 2 deletions main/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function isValidFile (data, enc, cb) {

function concatTrackDict (obj) {
function writeTrackDict (data, enc, cb) {
console.log(`Scanning ${data.filepath}`)
parseMetadata(data, handleMeta)

function handleMeta (err, meta) {
Expand All @@ -46,14 +47,19 @@ function parseMetadata (data, cb) {
var { filepath } = data
var readableStream = fs.createReadStream(filepath)
mm(readableStream, { duration: true }, (err, meta) => {
readableStream.close()
readableStream.destroy()
if (err) {
switch (err.message) {
case 'Could not find metadata header':
console.warn(err.message += ` (file: ${filepath})`)
break
case 'expected frame header but was not found':
console.warn(err.message += ` (file: ${filepath})`)
break
default:
return cb(err)
// Ignore errors
console.warn(err.message += ` (file: ${filepath})`)
return cb(null)
}
}

Expand Down

0 comments on commit 5ded061

Please sign in to comment.