Skip to content

Instantly share code, notes, and snippets.

@Getaji
Last active October 3, 2018 19:06
Show Gist options
  • Select an option

  • Save Getaji/c5dcd7a4c4b2dcbdb8c1420a44fdb0ea to your computer and use it in GitHub Desktop.

Select an option

Save Getaji/c5dcd7a4c4b2dcbdb8c1420a44fdb0ea to your computer and use it in GitHub Desktop.
カレントディレクトリの音声ファイルのメタデータを読み込み、"01 TITLE.ext"の書式でリネームするスクリプト。npmパッケージのmusic-metadataが必要。
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