Scan for all supported audio files
This commit is contained in:
parent
e875e0ed5d
commit
6505e3aff7
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "publikator",
|
||||
"version": "0.8.0",
|
||||
"version": "0.9.0",
|
||||
"main": "index.js",
|
||||
"repository": "https://github.com/aengl/publikator.git",
|
||||
"author": "Lynn Smeria <ae@cephea.de>",
|
||||
|
|
|
@ -22,7 +22,7 @@ program.version(packageJson.version);
|
|||
program
|
||||
.command(
|
||||
'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('<target>', 'Target folder for the restructured output')
|
||||
|
|
45
src/scan.js
45
src/scan.js
|
@ -1,19 +1,50 @@
|
|||
const debug = require('debug')('publikator:scan');
|
||||
const path = require('path');
|
||||
const walk = require('walkdir');
|
||||
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 = {
|
||||
/**
|
||||
* Recursively searches for files.
|
||||
*/
|
||||
findFilesSync: (root, extension = '.mp3') => {
|
||||
debug(
|
||||
`scanning directory '${root}' for files with extension '${extension}'`
|
||||
);
|
||||
findFilesSync: root => {
|
||||
debug(`scanning directory '${root}' for audio tracks`);
|
||||
const files = [];
|
||||
walk.sync(root, path => {
|
||||
if (path.endsWith(extension)) {
|
||||
files.push(path);
|
||||
walk.sync(root, filePath => {
|
||||
const ext = path.extname(filePath);
|
||||
if (extensions.has(ext)) {
|
||||
files.push(filePath);
|
||||
}
|
||||
});
|
||||
debug(`found ${files.length} file(s)`);
|
||||
|
|
Loading…
Reference in a new issue