Skip to content

Instantly share code, notes, and snippets.

@kirill578
Last active December 18, 2022 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirill578/0ecaf6e205bffb01ef8806bece67298f to your computer and use it in GitHub Desktop.
Save kirill578/0ecaf6e205bffb01ef8806bece67298f to your computer and use it in GitHub Desktop.
(async () => {
const getResolutions = async (m3u8url) => {
const options = {};
try {
const breakdown = await fetch(m3u8url).then(res => res.text());
const matches = breakdown.matchAll(/RESOLUTION=(\d+x\d+)\n(https:\/\/.*?m3u8)/g);
for (const match of matches) {
const [_, reso, url] = match;
options[reso] = url;
}
} catch (e) {
console.error(e);
}
return options;
}
const urlsSet = new Set();
const catId = new URLSearchParams(window.location.search).get('catId') ?? new URLSearchParams(window.location.search).get('catid');
if (catId) {
urlsSet.add('https://www.kan.org.il/AppKan/itemJson.ashx?catId=' + catId);
}
for (const match of document.documentElement.innerHTML.matchAll(/(itemJson.ashx.*?)['"]/g)) {
const itemJsonPart = match[1];
const url = `https://www.kan.org.il/AppKan/${itemJsonPart}`;
urlsSet.add(url);
}
const getm3u8inHtml = async (html) => [...html.matchAll(/(https:\/\/.*?m3u8)/g)].map(a => a[1])
const pageHtml = await fetch(window.location.href).then((response) => response.text());
const m3u8onPage = await getm3u8inHtml(pageHtml);
let html = '';
const all = [];
for (let index = 0; index < m3u8onPage.length; index++) {
const url = m3u8onPage[index];
all.push({ title: `on page ${index}`, ...await getResolutions(url) })
}
const linkedPages = [...pageHtml.matchAll(/mailto:.*?(https:\/\/.*?)['"]/g)].map(a => a[1]);
for (let index = 0; index < linkedPages.length; index++) {
const linkedPage = linkedPages[index];
const pageHtml = await fetch(linkedPage).then((response) => response.text());
let title = linkedPage
try {
title = /<title>(.*?)<\/title>/g.exec(pageHtml)[1]
} catch (e) {
}
const m3u8onPage = await getm3u8inHtml(pageHtml);
for (let index = 0; index < m3u8onPage.length; index++) {
const url = m3u8onPage[index];
all.push({ title, ...await getResolutions(url) });
}
}
const urls = [...urlsSet];
for (let index = 0; index < urls.length; index++) {
const url = urls[index];
let response;
try {
response = await fetch(url).then(a => a.json());
} catch (e) {
continue;
}
all = [
...all,
...await Promise.all(response.entry.map(async (ep) => {
const options = { title: ep.extensions?.on_demand?.title ?? ep.title }
if (ep.content.src.includes('m3u8')) {
options = {
...options,
...await getResolutions(ep.content.src)
}
}
return options
}))];
}
let didAddAnything = false
all.forEach(({ title, ...other }) => {
console.log(title)
if (Object.keys(other).length > 0) {
html += `<div>${title}</div>`
}
Object.entries(other).forEach(([res, url]) => {
didAddAnything = true;
const downloadUrl = `https://m3u8.dev/?source=${encodeURI(url)}`;
html += `<a target="_blank" style="padding: 5px" href="${downloadUrl}">${res}</a>`
});
if (didAddAnything) {
html += `<br />`
}
});
if (didAddAnything) {
document.documentElement.innerHTML = "<html><body>" + html;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment