Created
October 17, 2022 09:47
-
-
Save n0samu/9cf15d253103ec29cbcb39d3c57526c4 to your computer and use it in GitHub Desktop.
JavaScript code to download FLV videos from pages on tangoandchaos.org. Written at the request of someone on Discord.
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
function saveFile(fileUrl, mimeType) { | |
var fileName = fileUrl.split('/').pop(); | |
fetch(fileUrl) | |
.then(response => response.blob()) | |
.then(blob => { | |
var link = window.document.createElement("a"); | |
link.href = window.URL.createObjectURL(blob, { type: mimeType }); | |
link.download = fileName; | |
document.body.appendChild(link); | |
link.click(); | |
document.body.removeChild(link); | |
}); | |
} | |
function saveVideo(videoElement) { | |
var playerParams = new URLSearchParams(videoElement.getAttribute('flashvars')); | |
var videoURL = new URL(playerParams.get('streamName') + '.flv', document.baseURI); | |
saveFile(videoURL.href, 'video/x-flv'); | |
} | |
var videoElements = document.querySelectorAll('embed, ruffle-embed'); | |
videoElements.forEach(saveVideo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment