Skip to content

Instantly share code, notes, and snippets.

@Beej126
Last active September 23, 2024 15:42
Show Gist options
  • Save Beej126/a519731404b665c40f9ba9b555a38e9b to your computer and use it in GitHub Desktop.
Save Beej126/a519731404b665c40f9ba9b555a38e9b to your computer and use it in GitHub Desktop.
browser console script for pulling eztv.unblockit.tv episode links in bulk
//helper function
function groupBy(objectArray, property) {
return objectArray.reduce((acc, obj) => {
const key = obj[property];
if (!acc[key]) {
acc[key] = [];
}
// Add object to list for given key's value
acc[key].push(obj);
return acc;
}, {});
}
//main screen scrape pulling title, size & url from html table cells
let tors = $("table.forum_header_noborder > tbody > tr").toArray()
.map(tr => {
const i = {
size: $(tr).find("td:nth-child(4)").text(),
url: $(tr).find("a[href^=magnet]").attr("href"),
title: $(tr).find("td:nth-child(2)").text()
};
i.size = Number.parseFloat(i.size) * (i.size.includes("GB") ? 1000 : 1); //format gigs into megs
i.episode = (ep = i.title.match(/s[0-9]{1,2}e[0-9]{1,2}/i)) ? ep[0] : undefined; //extract the episode from the title
i.res = (r = i.title.match(/\w*0p\b/i)) ? r[0] : undefined; //find words that end in "0p" from the title (i.e. 1080p, 720p)
return i;
})
.filter(t=>t.url);
//quick and dirty filter and output
console.log(tors.filter(tor => tor.title.includes("MeGusta") && tor.title.includes("1080p")).map(tor=>tor.url).join("\r\n"));
//group by episode so we can pick our preferred size & resolution
const grouped = groupBy(tors, "episode");
//sort each episode group by 720p & smallest size
//https://stackoverflow.com/questions/6913512/how-to-sort-an-array-of-objects-by-multiple-fields/46256174#46256174
const vals = Object.values(grouped);
//ascending = b-a, descending = a-b
vals.forEach(g => g = g.sort((a, b) => b.title.includes("1080") - a.title.includes("1080") || b.title.includes("720") - a.title.includes("720") || a.size - b.size));
//final results
//pull the first match that's under 1.5 gigs
console.log(vals.flatMap(g => g.find(t=>t.size < 1500).url).join("\r\n"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment