Created
November 8, 2022 12:49
-
-
Save bpevs/9951786444f7c7a88190cd45bcf2ac15 to your computer and use it in GitHub Desktop.
Create VX1 .pls for bpev.me/blog/vx1 sessions
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 titleCase from "https://deno.land/x/case@2.1.1/titleCase.ts"; | |
const [dir, postDir] = Deno.args; | |
const contents = []; | |
for await (const file of Deno.readDir(dir)) { | |
if (file.name[0] === ".") continue; | |
contents.push(file); | |
} | |
const filenames = contents | |
.map((dir) => dir.name) | |
.sort() | |
.reverse(); | |
const entriesAsync = filenames.map(formatEntry); | |
const entries = await Promise.all(entriesAsync); | |
const plsText = `[playlist] | |
${entries.join("\n")} | |
NumberOfEntries=${entries.length} | |
Version=2 | |
`; | |
console.log(plsText); | |
async function formatEntry(fileName, index) { | |
const num = index + 1; | |
const [nameOrDate, memoName] = fileName.split("_"); | |
const title = memoName | |
? titleCase(memoName.split(".")[0]) + ` (${nameOrDate})` | |
: titleCase(nameOrDate.split(".")[0]); | |
return "" + | |
`File${num}=https://static.bpev.me/blog/${postDir}/version/${fileName}\n` + | |
`Title${num}=${title}\n` + | |
`Length${num}=${await getDurationSeconds(fileName)}\n`; | |
} | |
async function getDurationSeconds(fileName) { | |
const p = Deno.run({ | |
cmd: [ "/Users/ben/apps/ffmpeg", "-i", fileName ], | |
stderr: "piped", | |
}); | |
await p.status(); | |
const output = new TextDecoder().decode(await p.stderrOutput()); | |
const time = output.match(/Duration: ([^.]*)/)[1]; | |
const [hours, minutes, seconds] = time.split(":"); | |
return (parseInt(hours) * 3600) + (parseInt(minutes) * 60) + parseInt(seconds); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment