Greasy Fork

ddrk-m3u8解析0.3

解析低端影视to=>m3u8

目前为 2021-05-11 提交的版本。查看 最新版本

// ==UserScript==
// @name         ddrk-m3u8解析0.3
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  解析低端影视to=>m3u8
// @author       Lonelam
// @match        https://ddrk.me/*
// @match        https://ddys.tv/*
// @grant  none
// ==/UserScript==


window._fetch = fetch;
window.fetch = (src) => {
    function download(filename, text) {
        var element = document.createElement('a');
        element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
        element.setAttribute('download', filename);
        element.style.display = 'none';
        document.body.appendChild(element);
        element.click();
        document.body.removeChild(element);
    }
    let p = window._fetch(src);
    if (src.includes && src.includes('9543/video?id=')) {
        p.then((resp)=> {

            var movie_name = /^https?:\/\/ddrk.(me|tv)\/(.*)\//.exec(location.href)[2] || 'unknown-movie';
            let ep_name = new URL(location.href).searchParams.get('ep') || '0';
            var file_name = prompt("请输入视频标题,不需要下载m3u8请点取消",movie_name+'-'+ep_name);
            if (file_name) {
                resp.json().then((data) => {
                    let pint = pako.ungzip(data.pin,{to:'string'});

                    if (file_name) {
                        download(file_name +".m3u8", pint);
                    }
                })
            }
        });

    }
    return p;
}