Skip to content

Commit

Permalink
Fix multi disc filenames not filtered
Browse files Browse the repository at this point in the history
  • Loading branch information
the1812 committed Dec 18, 2019
1 parent 751298a commit 4bc410b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dist/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const createFiles = async (metadata) => {
const fileTypes = Object.keys(writerMappings);
const fileTypeFilter = (file) => fileTypes.some(type => file.endsWith(type));
const dir = readdirSync('.');
const discFiles = dir.filter(f => f.match(/^Disc (\d+)/)).flatMap(f => readdirSync(f).map(inner => `${f}/${inner}`));
const discFiles = dir.filter(f => f.match(/^Disc (\d+)/)).flatMap(f => readdirSync(f).map(inner => `${f}/${inner}`)).filter(fileTypeFilter);
const files = dir.filter(fileTypeFilter).concat(discFiles).slice(0, metadata.length);
if (files.length === 0) {
console.log('未找到任何支持的音乐文件.');
Expand All @@ -53,6 +53,7 @@ const createFiles = async (metadata) => {
}
return dir + `${metadata[index].trackNumber.padStart(maxLength, '0')} ${metadata[index].title}${path_1.extname(file)}`.replace(/[\/\\:\*\?"<>\|]/g, '');
});
debug_1.log(files, targetFiles);
files.forEach((file, index) => {
renameSync(file, targetFiles[index]);
});
Expand Down
3 changes: 2 additions & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const createFiles = async (metadata: Metadata[]) => {
const fileTypes = Object.keys(writerMappings)
const fileTypeFilter = (file: string) => fileTypes.some(type => file.endsWith(type))
const dir = readdirSync('.')
const discFiles = dir.filter(f => f.match(/^Disc (\d+)/)).flatMap(f => readdirSync(f).map(inner => `${f}/${inner}`))
const discFiles = dir.filter(f => f.match(/^Disc (\d+)/)).flatMap(f => readdirSync(f).map(inner => `${f}/${inner}`)).filter(fileTypeFilter)
const files = dir.filter(fileTypeFilter).concat(discFiles).slice(0, metadata.length)
if (files.length === 0) {
console.log('未找到任何支持的音乐文件.')
Expand All @@ -60,6 +60,7 @@ const createFiles = async (metadata: Metadata[]) => {
}
return dir + `${metadata[index].trackNumber.padStart(maxLength, '0')} ${metadata[index].title}${extname(file)}`.replace(/[\/\\:\*\?"<>\|]/g, '')
})
log(files, targetFiles)
files.forEach((file, index) => {
renameSync(file, targetFiles[index])
})
Expand Down

0 comments on commit 4bc410b

Please sign in to comment.