Created
May 9, 2020 11:33
-
-
Save chalkpe/d74ceec5170c5d6ff78403052ccb5522 to your computer and use it in GitHub Desktop.
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
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)})() |
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
{ | |
"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