Skip to content

Instantly share code, notes, and snippets.

@kirill578
Last active December 18, 2022 20:12
Show Gist options
  • Select an option

  • Save kirill578/0ecaf6e205bffb01ef8806bece67298f to your computer and use it in GitHub Desktop.

Select an option

Save kirill578/0ecaf6e205bffb01ef8806bece67298f to your computer and use it in GitHub Desktop.

Revisions

  1. kirill578 revised this gist Dec 18, 2022. 1 changed file with 77 additions and 33 deletions.
    110 changes: 77 additions & 33 deletions kan.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,23 @@
    (async () => {
    let html = "<html><body>";

    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');
    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);
    }
    @@ -14,6 +28,38 @@
    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];
    @@ -23,46 +69,44 @@
    } catch (e) {
    continue;
    }
    const all = await Promise.all(response.entry.map(async (ep) => {
    const options = { title: ep.extensions?.on_demand?.title ?? ep.title }
    try {
    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')) {
    const breakdown = await fetch(ep.content.src).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;
    options = {
    ...options,
    ...await getResolutions(ep.content.src)
    }
    }
    } catch (e) {
    console.log(e)
    }
    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>`
    return options
    }))];
    }

    });

    if (didAddAnything) {
    html += `<br />`
    }



    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 /><br /><br /><br />`
    html += `<br />`
    }
    }
    });

    document.documentElement.innerHTML = html
    if (didAddAnything) {
    document.documentElement.innerHTML = "<html><body>" + html;
    }

    })();
  2. kirill578 revised this gist Dec 18, 2022. 1 changed file with 24 additions and 1 deletion.
    25 changes: 24 additions & 1 deletion kan.js
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,28 @@
    (async () => {
    let html = "<html><body>";

    const urlsSet = new Set();

    const 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 response = await fetch(`https://www.kan.org.il/AppKan/${itemJsonPart}`).then(a => a.json());
    const url = `https://www.kan.org.il/AppKan/${itemJsonPart}`;
    urlsSet.add(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;
    }
    const all = await Promise.all(response.entry.map(async (ep) => {
    const options = { title: ep.extensions?.on_demand?.title ?? ep.title }
    try {
    @@ -32,6 +52,7 @@
    html += `<a target="_blank" style="padding: 5px" href="${downloadUrl}">${res}</a>`

    });

    if (didAddAnything) {
    html += `<br />`
    }
    @@ -41,5 +62,7 @@
    html += `<br /><br /><br /><br />`
    }
    }

    document.documentElement.innerHTML = html

    })();
  3. kirill578 revised this gist Dec 18, 2022. 1 changed file with 23 additions and 25 deletions.
    48 changes: 23 additions & 25 deletions kan.js
    Original file line number Diff line number Diff line change
    @@ -1,47 +1,45 @@
    (async () => {


    let html = "<html><body>";

    for (const match of document.documentElement.innerHTML.matchAll(/(itemJson.ashx.*?)['"]/g)) {

    const itemJsonPart = match[1];

    const response = await fetch(`https://www.kan.org.il/AppKan/${itemJsonPart}`).then(a => a.json());

    const all = await Promise.all(response.entry.map(async (ep) => {
    const breakdown = await fetch(ep.content.src).then(res => res.text());
    const matches = breakdown.matchAll(/RESOLUTION=(\d+x\d+)\n(https:\/\/.*?m3u8)/g);
    const options = { title: ep.extensions?.on_demand?.title ?? ep.title }
    for (const match of matches) {
    const [_, reso, url] = match;
    options[reso] = url;
    try {
    if (ep.content.src.includes('m3u8')) {
    const breakdown = await fetch(ep.content.src).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.log(e)
    }
    return options
    }));


    let didAddAnything = false
    all.forEach(({ title, ...other }) => {
    console.log(title)
    html += `<div>${title}</div>`
    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>`

    });

    html += `<br />`

    console.log(" ");
    if (didAddAnything) {
    html += `<br />`
    }
    });

    html += `<br /><br /><br /><br />`
    if (didAddAnything) {
    html += `<br /><br /><br /><br />`
    }
    }

    document.documentElement.innerHTML = html




    })()

    })();
  4. kirill578 created this gist Dec 18, 2022.
    47 changes: 47 additions & 0 deletions kan.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    (async () => {


    let html = "<html><body>";

    for (const match of document.documentElement.innerHTML.matchAll(/(itemJson.ashx.*?)['"]/g)) {

    const itemJsonPart = match[1];

    const response = await fetch(`https://www.kan.org.il/AppKan/${itemJsonPart}`).then(a => a.json());

    const all = await Promise.all(response.entry.map(async (ep) => {
    const breakdown = await fetch(ep.content.src).then(res => res.text());
    const matches = breakdown.matchAll(/RESOLUTION=(\d+x\d+)\n(https:\/\/.*?m3u8)/g);
    const options = { title: ep.extensions?.on_demand?.title ?? ep.title }
    for (const match of matches) {
    const [_, reso, url] = match;
    options[reso] = url;
    }
    return options
    }));


    all.forEach(({ title, ...other }) => {
    console.log(title)
    html += `<div>${title}</div>`
    Object.entries(other).forEach(([res, url]) => {
    const downloadUrl = `https://m3u8.dev/?source=${encodeURI(url)}`;
    html += `<a target="_blank" style="padding: 5px" href="${downloadUrl}">${res}</a>`

    });

    html += `<br />`

    console.log(" ");
    });

    html += `<br /><br /><br /><br />`
    }

    document.documentElement.innerHTML = html




    })()