Skip to content

Instantly share code, notes, and snippets.

@n0samu
Created October 17, 2022 09:47
Show Gist options
  • Save n0samu/9cf15d253103ec29cbcb39d3c57526c4 to your computer and use it in GitHub Desktop.
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.
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