Last active
May 15, 2021 01:03
-
-
Save yanneves/c650680a400584b322f20435aa619076 to your computer and use it in GitHub Desktop.
Media batch rename
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
{ | |
"type": "module" | |
} |
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
import fs from "fs" | |
const run = async () => { | |
const files = await fs.promises.readdir("./") | |
const ops = files | |
.filter((filename) => filename.includes(".mkv")) | |
.map((filename) => { | |
const renamed = filename | |
.replace(/^.+S\d+E/, "") | |
.replace(/\.1080p.+\.mkv/, ".mkv") | |
.replace(/(\d+)\./, "$1 - ") | |
.replace(/\./g, " ") | |
.replace(/\smkv$/, ".mkv") | |
const op = [`./${filename}`, `./${renamed}`] | |
return process.argv.includes("--exec") | |
? fs.promises.rename(...op) | |
: Promise.resolve(console.info(op)) | |
}) | |
try { | |
await Promise.all(ops) | |
console.info("All done!") | |
} catch (e) { | |
console.error(e) | |
} | |
} | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment