Skip to content

Instantly share code, notes, and snippets.

@ovrmrw
Created April 18, 2017 07:03
Show Gist options
  • Save ovrmrw/1c73db1517c3aee38959cbf62f6fad35 to your computer and use it in GitHub Desktop.
Save ovrmrw/1c73db1517c3aee38959cbf62f6fad35 to your computer and use it in GitHub Desktop.
Re-name MP3 files from its ID3 tag's title.
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)
})
@ovrmrw
Copy link
Author

ovrmrw commented Apr 18, 2017

NHK出版 で購入したNHKラジオ英会話のファイル名がひどいことになっていたのでID3タグのtitleを元にリネームする。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment