Skip to content

Instantly share code, notes, and snippets.

@chalkpe
Created May 9, 2020 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chalkpe/d74ceec5170c5d6ff78403052ccb5522 to your computer and use it in GitHub Desktop.
Save chalkpe/d74ceec5170c5d6ff78403052ccb5522 to your computer and use it in GitHub Desktop.
const {join} = require('path')
const {readdir} = require('fs').promises
const id3 = require('node-id3')
const iconv = require('iconv-lite')
const songs = f => f.isFile() && f.name.endsWith('.mp3')
const albums = f => f.isDirectory() && f.name.startsWith('HTD')
const ls = iconv.skipDecodeWarning = p => readdir(p, {withFileTypes: true})
async function* patch (path) {
for (const {name: album} of (await ls(path)).filter(albums)) {
for (const {name: song} of (await ls(album)).filter(songs)) {
const file = join(album, song)
const {raw, ...tags} = id3.read(file)
const title = iconv.decode(tags.title, 'Shift_JIS')
yield {file, title, success: id3.update({...tags, title}, file)}
}
}
}
(async () => {for await (const p of patch('.')) console.log(p)})()
{
"dependencies": {
"iconv-lite": "^0.5.1",
"node-id3": "^0.1.16"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment