Scan for all supported audio files

This commit is contained in:
Lynn Smeria 2018-08-27 16:46:42 +02:00
parent e875e0ed5d
commit 6505e3aff7
3 changed files with 40 additions and 9 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "publikator", "name": "publikator",
"version": "0.8.0", "version": "0.9.0",
"main": "index.js", "main": "index.js",
"repository": "https://github.com/aengl/publikator.git", "repository": "https://github.com/aengl/publikator.git",
"author": "Lynn Smeria <ae@cephea.de>", "author": "Lynn Smeria <ae@cephea.de>",

View file

@ -22,7 +22,7 @@ program.version(packageJson.version);
program program
.command( .command(
'organise', 'organise',
'Recursively finds all mp3s in a folder, reads their tags and re-organises them' 'Recursively finds all tracks in a folder, reads their tags and re-organises them'
) )
.argument('<source>', 'Root folder for the recursive search') .argument('<source>', 'Root folder for the recursive search')
.argument('<target>', 'Target folder for the restructured output') .argument('<target>', 'Target folder for the restructured output')

View file

@ -1,19 +1,50 @@
const debug = require('debug')('publikator:scan'); const debug = require('debug')('publikator:scan');
const path = require('path');
const walk = require('walkdir'); const walk = require('walkdir');
const tags = require('./tags'); const tags = require('./tags');
const extensions = new Set([
'.3gp',
'.aac',
'.aif',
'.aifc',
'.aiff',
'.ape',
'.asf',
'.flac',
'.m2a',
'.m4a',
'.m4b',
'.m4p',
'.m4r',
'.m4v',
'.mp2',
'.mp3',
'.mp3',
'.mp4',
'.oga',
'.ogg',
'.ogv',
'.ogx',
'.opus',
'.wav',
'.wma',
'.wmv',
'.wv',
'.wvp',
]);
module.exports = { module.exports = {
/** /**
* Recursively searches for files. * Recursively searches for files.
*/ */
findFilesSync: (root, extension = '.mp3') => { findFilesSync: root => {
debug( debug(`scanning directory '${root}' for audio tracks`);
`scanning directory '${root}' for files with extension '${extension}'`
);
const files = []; const files = [];
walk.sync(root, path => { walk.sync(root, filePath => {
if (path.endsWith(extension)) { const ext = path.extname(filePath);
files.push(path); if (extensions.has(ext)) {
files.push(filePath);
} }
}); });
debug(`found ${files.length} file(s)`); debug(`found ${files.length} file(s)`);