Created
August 7, 2021 09:55
-
-
Save SrejonKhan/c9da1c1cad3faf6c5d2e7edf037d4f1f to your computer and use it in GitHub Desktop.
Run this in console of any YT Playlist to download all playlist video Title, Link in a TSV(Tab Seperated Value) file.
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
// if it doesn't get the actual list, copy new xPath from Elements | |
let conts = getElementByXpath("/html/body/ytd-app/div/ytd-page-manager/ytd-browse/ytd-two-column-browse-results-renderer/div[1]/ytd-section-list-renderer/div[2]/ytd-item-section-renderer/div[3]/ytd-playlist-video-list-renderer/div[3]"); | |
let tsvData = "No.\t Title\t Link\n"; | |
// loop through all contents | |
for(let i = 0; i < conts.childElementCount; i++) { | |
let cont = conts.childNodes[i].childNodes[3].childNodes[1].childNodes[3].childNodes[1].childNodes[3]; | |
let link = "https://youtube.com" + cont.getAttribute("href").split('&')[0]; | |
let title = cont.getAttribute("title"); | |
let data = `${i}\t${title}\t${link}\n`; | |
tsvData += data; | |
} | |
// download tsv | |
download(tsvData, "playlist.tsv", "text/tab-separated-values;charset=utf-8"); | |
// get element by xPath | |
function getElementByXpath(path) { | |
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
} | |
// download file from data | |
function download(data, filename, type) { | |
var file = new Blob([data], {type: type}); | |
if (window.navigator.msSaveOrOpenBlob) // IE10+ | |
window.navigator.msSaveOrOpenBlob(file, filename); | |
else { // Others | |
var a = document.createElement("a"), | |
url = URL.createObjectURL(file); | |
a.href = url; | |
a.download = filename; | |
document.body.appendChild(a); | |
a.click(); | |
setTimeout(function() { | |
document.body.removeChild(a); | |
window.URL.revokeObjectURL(url); | |
}, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment