Created
April 18, 2017 07:03
-
-
Save ovrmrw/1c73db1517c3aee38959cbf62f6fad35 to your computer and use it in GitHub Desktop.
Re-name MP3 files from its ID3 tag's title.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as fs from 'fs-extra' | |
import * as nodeID3 from 'node-id3' | |
import * as path from 'path' | |
const TARGET = 'au_kaiwa_1705_A' | |
const filePaths = fs.readdirSync(TARGET) | |
.map((file) => path.join(process.cwd(), TARGET, file)) | |
.filter((filePath) => fs.existsSync(filePath)) | |
console.log(filePaths) | |
const tags = filePaths | |
.map((filePath) => { | |
const obj = nodeID3.read(filePath) | |
return { ...obj, filePath } | |
}) | |
console.log(tags) | |
const results = tags | |
.map((tag) => { | |
if (tag.trackNumber.length === 1) { | |
tag = { ...tag, trackNumber: '0' + tag.trackNumber } | |
} | |
return tag | |
}) | |
.map((tag) => { | |
return { | |
newFilePath: path.join(process.cwd(), `new_${TARGET}`, `${tag.trackNumber}_${tag.title}.mp3`), | |
originalFilePath: tag.filePath, | |
} | |
}) | |
console.log(results) | |
results.forEach((result) => { | |
fs.copy(result.originalFilePath, result.newFilePath) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NHK出版 で購入したNHKラジオ英会話のファイル名がひどいことになっていたのでID3タグのtitleを元にリネームする。