Last active
October 3, 2018 19:06
-
-
Save Getaji/c5dcd7a4c4b2dcbdb8c1420a44fdb0ea to your computer and use it in GitHub Desktop.
カレントディレクトリの音声ファイルのメタデータを読み込み、"01 TITLE.ext"の書式でリネームするスクリプト。npmパッケージのmusic-metadataが必要。
This file contains hidden or 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
| const fs = require('fs'); | |
| const mm = require('music-metadata'); | |
| fs.readdirSync('./').forEach(file => { | |
| mm.parseFile(file, { native: true }) | |
| .then(metadata => { | |
| const track = metadata.common.track.no; | |
| const title = metadata.common.title.replace(/\//g, '-'); | |
| const ext = file.match(/\.\w+/)[0]; | |
| const newname = String(track).padStart(2, '0') + ' ' + title + ext; | |
| fs.renameSync(file, newname); | |
| }) | |
| .catch(err => { | |
| console.error(err.message); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment