diff --git a/dist/cli/index.js b/dist/cli/index.js index f0a89da..59f3cc5 100644 --- a/dist/cli/index.js +++ b/dist/cli/index.js @@ -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('未找到任何支持的音乐文件.'); @@ -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]); }); diff --git a/src/cli/index.ts b/src/cli/index.ts index 893283d..9f2ff90 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -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('未找到任何支持的音乐文件.') @@ -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]) })