Created
October 7, 2021 19:04
-
-
Save picwellwisher12pk/cf4046eadb71b1f4b962b7a32cf7e683 to your computer and use it in GitHub Desktop.
YTS torrents downloader
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
function downloadFile (url) { | |
let name; | |
fetch(url) | |
.then((resp) => { | |
resp.headers.forEach((header) => { | |
if (header.includes("attachment")) { | |
const filename = header.match(/filename="(.*)"/); | |
name = filename[1]; | |
} | |
}); | |
return resp.blob(); | |
}) | |
.then((blob) => { | |
const url = window.URL.createObjectURL(blob); | |
const a = document.createElement("a"); | |
a.style.display = "none"; | |
a.href = url; | |
a.download = name; | |
document.body.appendChild(a); | |
a.click(); | |
window.URL.revokeObjectURL(url); | |
console.log("your file has downloaded!"); // or you know, something with better UX... | |
}) | |
.catch((e) => console.log("oh no!",e)); | |
} | |
let fetchURL = async (url) => { | |
return await fetch(url) | |
.then((response) => response.text()) | |
.then((data) => { | |
let parser = new DOMParser(); | |
let htmlDoc = parser.parseFromString(data, "text/html"); | |
let links = htmlDoc.querySelectorAll("a"); | |
Array.from(links).every(function (link) { | |
if (link.text.includes("720p")) { | |
downloadFile(link.href); | |
return false; | |
} | |
return true; | |
}); | |
}); | |
}; | |
document.querySelectorAll("a.browse-movie-link").forEach((link) => { | |
fetchURL(link.href); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment