Last active
April 29, 2020 12:30
-
-
Save chapmanjacobd/7b6849c68dc78eb7679c7c639c64b9ae to your computer and use it in GitHub Desktop.
nothin' good on the radio simulator
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 { writeFileSync } from "fs"; | |
const numberOfSongs = process.argv.slice(2).length; | |
const randomFile = process.argv | |
.slice(2) | |
.map((x) => ' -i "' + x + '" \\\n') | |
.join(""); | |
function rndInt(min: number, max: number) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
function shuffle(array: any[]) { | |
var currentIndex = array.length, | |
temporaryValue: any, | |
randomIndex: number; | |
// While there remain elements to shuffle... | |
while (0 !== currentIndex) { | |
// Pick a remaining element... | |
randomIndex = Math.floor(Math.random() * currentIndex); | |
currentIndex -= 1; | |
// And swap it with the current element. | |
temporaryValue = array[currentIndex]; | |
array[currentIndex] = array[randomIndex]; | |
array[randomIndex] = temporaryValue; | |
} | |
return array; | |
} | |
const flatten = (arr: any[]): any[] => | |
arr.reduce((a, v) => { | |
v instanceof Array ? a.push(...flatten(v)) : a.push(v); | |
return a; | |
}, []); | |
const output = () => { | |
const filterInstFunc = (i: number) => | |
` | |
[${i}]atrim=start=20,atrim=duration=8[${i + 1000}]; | |
[${i}]atrim=start=${rndInt(30, 40) + 5},atrim=duration=${rndInt(3, 21)}[${i + 2000}]; | |
[${i}]atrim=start=${rndInt(50, 90)},atrim=duration=12[${i + 3000}];`; | |
const concatFunc = (i: number): string[] => [i + 1000, i + 2000, i + 3000].map(String); | |
const filterInstances = Array.from(Array(numberOfSongs).keys()).map(filterInstFunc); | |
const filterInstancesConcat = flatten(Array.from(Array(numberOfSongs).keys()).map(concatFunc)); | |
return ( | |
"ffmpeg " + | |
randomFile + | |
" -f lavfi -i anullsrc -filter_complex " + | |
'" ' + | |
filterInstances.join("") + | |
"[" + | |
shuffle(filterInstancesConcat).join("][") + | |
"]" + | |
`concat=n=${numberOfSongs * 3}:v=0:a=1` + | |
'"' + | |
" /tmp/out.oga; and mpv /tmp/out.oga --no-video" | |
); | |
}; | |
// # cut up method | |
writeFileSync("run.sh", "#!/bin/fish\n" + output()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment