assorted/bookmarklet-youtube-playlist/mix_playlist.js

30 lines
1.1 KiB
JavaScript

var parse = (list) => {
const vp = /(?:youtube\.com.*(?:\?|&)(?:v)=|youtube\.com.*embed\/|youtube\.com.*v\/|youtu\.be\/)((?!videoseries)[a-zA-Z0-9_-]*)/;
const dl = Array.from(document.querySelectorAll(`a[href*="list=${list}"]`), e => e.href.match(vp)[1]);
return dl.filter((v, i, a) => a.indexOf(v) === i).map(e => `https://youtube.com/watch?v=${e}`);
};
var dl = (() => {
let a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
return (data, fileName) => {
let bytes = data,
blob = new Blob([bytes], {type: "octet/stream"}),
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
};
})();
(function() {
const lp = /(?:(?:\?|&)(?:v|list)=|embed\/|v\/|youtu\.be\/)((?!videoseries)[a-zA-Z0-9_-]*)/g;
const m = Array.from(window.location.href.matchAll(lp)).flat();
const l = m.length == 4 ? m[3] : undefined;
if (l) dl(parse(l).join('\n'), `${l}.txt`);
else console.warn('Could not parse playlist.');
})();