Last active
January 26, 2022 09:25
-
-
Save Far-Se/8e5767d3e25a0c208060df42173da917 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let fetch = require("cross-fetch"); | |
let fs = require("fs"); | |
let process = require("process"); | |
var ffmpeg = require("fluent-ffmpeg"); | |
const cliProgress = require('cli-progress'); | |
const cliSelect = require('cli-select'); | |
const REMOVE_ALL_MP4 = true; | |
const progressBar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic); | |
(async () => { | |
let doDelete = await cliSelect({ | |
"values": ["Delete All Mp4 Files", "Keep MP4 Files"] | |
}) | |
if (REMOVE_ALL_MP4 && doDelete.id == 0) { | |
let files = fs.readdirSync('./'); | |
files.forEach(f => { | |
if (~f.indexOf('.mp4')) { | |
fs.unlinkSync(f); | |
} | |
}); | |
} | |
const response = await fetch('https://old.pogu.live/videos/CreativeMonkeyz'); | |
const body = await response.text(); | |
const json = JSON.parse(body.match(/ id="__NEXT_DATA__" type="application\/json">(.*?)<\/script>/)[1]); | |
const videos = json.props.pageProps.twitchData.videos; | |
let titles = []; | |
videos.forEach(t => titles.push(t.title)); | |
let videoID = await cliSelect({ | |
values: titles | |
}); | |
const item = videos[videoID.id]; | |
const m3u8 = item.animated_preview_url.replace(/storyboard.*?jpg/, 'chunked\/index-dvr.m3u8'); | |
const title = item.title.replace(/[^a-z0-9 ]/ig, ' ').replace(/ +/ig, " ").slice(0, 30); | |
console.log(m3u8,"\n\n"); | |
progressBar.start(100, 0); | |
ffmpeg(m3u8) // -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 today.mp4 | |
.on("error", error => { | |
console.log(error); | |
}) | |
.on('progress', function(progress) { | |
progressBar.update(parseInt(progress.percent)); | |
}) | |
.on("end", () => { | |
progressBar.stop(); | |
console.log("DONE"); | |
process.exit(); | |
}) | |
.outputOptions("-c copy") | |
.outputOptions("-bsf:a aac_adtstoasc") | |
.outputOptions("-crf 50") | |
.output(title + ".mp4") | |
.run(); | |
})(); | |
setInterval(() => {}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment