Greasy Fork is available in English.

you-get-fork

视频下载 bilibili acfun 快手 抖音 腾讯视频 cctv youku

질문, 리뷰하거나, 이 스크립트를 신고하세요.
// ==UserScript==
// @name               you-get-fork
// @description        视频下载 bilibili acfun 快手 抖音 腾讯视频 cctv youku
// @description:en-US  fork from [460910]
// @namespace          https://greasyfork.org/users/135090
// @version            1.5.7
// @author             You
// @run-at             document-end
// @match              https://www.bilibili.com/video/BV*
// @match              https://www.douyin.com/video/*
// @match              https://www.kuaishou.com/short-video/*
// @match              https://www.acfun.cn/v/ac*
// @match              https://v.qq.com/x/*
// @match              https://v.cctv.com/2*/V*.shtml*
// @match              https://v.cctv.cn/2*/V*.shtml*
// @match              https://tv.cctv.cn/2*/V*.shtml*
// @match              https://tv.cctv.com/2*/V*.shtml*
// @match              https://v.youku.com/v_*
// @license            MIT
// @icon               data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAC4jAAAuIwF4pT92AAAIVklEQVR4Xu2bWYwVRRSGzyzIBYwbAmpwFzPigqCi0ZgoJooa3GKMGBg3VMAIcY3xQREFNW5xfXAF1AiKPrhEURl3E6O4srggojCCIIIgIuIM/t+cauZ6p293j3jDZZiHL5lkpk7956/q6upTNdbY2GgNDQ1bLHbjZ0tszKc/Z6FC7CmOF0PEKHGxOEv0F9uL6gxxNpbq0Ff/0PclYrQYOsa1obEiQ5wmrGrSbKuaOCsLlWKAuFNME3PFR2KquEzsJXKiIkOs/0pF6GOv0Cd9zxDzxGtVrg2NlRliNWE2cbbZhFlpdBX7i9FiuvhW/CrqxUwxWVwpjhPdRHWGmK2lOsQ+LvQ1JfT9k1gu5oo3zDWitWuGmJkN2FecKR4Vv4h1okH8HX5eKD4QY0SNyImKDHGzUhFi1oQ+6Ks+9I2GhvDzUnONaN03Q9zMBtDx2WKCuduNBawUC8SL4mr7f2dC/sgT+4XQ10prqYNZOdFca02G2K0yYHAIHmdAN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UkKtfq7fmy9KUn/hXk1rzQiQFR1ZKZgT7hCy3wzc1Ubl8tbnmeeY5kAs5nWs+28mVnM1yT8yx3KTZERWiWhwqLhL3ijoxSywWK8TvYnWZgjY0LhIzxfSc50Au5ERu5LghZxv3xVIb9/mSfCrFzqKvOEEMFcPFFeIacW2Zg8bLx7lmtJMDuZATuf0rX1u/fr3xD9RbKu0GYMCWzD+zDS/KNPfarwAAAABJRU5ErkJggg==
// @grant              none
// ==/UserScript==
(() => {
    // src/util/index.js
    var download = async (blob, fileName) => {
        let link = window.URL.createObjectURL(blob);
        const a = document.createElement("a");
        a.download = `${fileName}`;
        a.href = link;
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
        window.URL.revokeObjectURL(link);
    };
    var safetyParse = (str) => {
        try {
            return JSON.parse(str);
        } catch (error) {
            return null;
        }
    };
    var getFile = async (url) => {
        const res = await fetch(url);
        const reader = res.body.getReader();
        const contentLength = +res.headers.get("Content-Length");
        if (!contentLength) {
            const data = await res.arrayBuffer();
            return new Uint8Array(data);
        }
        let receivedLength = 0;
        let chunks = [];
        while (true) {
            const { done, value } = await reader.read();
            if (done) {
                break;
            }
            chunks.push(value);
            receivedLength += value.length;
            console.log(
                `fileSize: ${contentLength} %c downloaded ${receivedLength}`,
                "background: #222; color: #bada55"
            );
        }
        return new Blob(chunks);
    };
    var getUrlsByM3u8 = async (url, parser) => {
        const urlObj = new URL(url);
        urlObj.pathname = urlObj.pathname.split("/").slice(0, -1).join("/");
        urlObj.search = "";
        const base = urlObj.toString();
        const res = await fetch(url);
        const data = await res.text();
        return data.split("\n").filter((i) => !!i && !i.startsWith("#")).map((i) => {
            if (parser) {
                return parser(i);
            }
            return i.startsWith("/") ? `${base}${i}` : `${base}/${i}`;
        });
    };
    var getFiles = (urls, max = 8) => {
        let connections = 0;
        let files = [];
        urls = urls.map((i, index) => ({
            ...i,
            index
        }));
        return new Promise((resolve, reject) => {
            const getSingleFile = async ({ url, index, ...rest }) => {
                if (connections < max) {
                    try {
                        connections = connections + 1;
                        const data = await getFile(url);
                        connections = connections - 1;
                        files[index] = data;
                        if (urls?.length) {
                            getSingleFile(urls.shift());
                        } else {
                            connections === 0 && resolve(files);
                        }
                    } catch (error) {
                        console.log(error);
                        urls.push({
                            url,
                            index,
                            ...rest
                        });
                    }
                }
            };
            new Array(max).fill(0).forEach((i) => {
                getSingleFile(urls.shift());
            });
        });
    };

    // src/module/acfun.js
    var getVideoInfo = async () => {
        const m3u8FileUrl = safetyParse(window?.pageInfo?.currentVideoInfo?.ksPlayJson)?.adaptationSet?.[0]?.representation?.[0]?.url;
        const urls = await getUrlsByM3u8(m3u8FileUrl);
        return urls.map((url) => ({ url }));
    };
    var acfun_default = async () => {
        const urls = await getVideoInfo();
        const files = await getFiles(urls);
        var tname = document.title;
        download(new Blob(files), tname+".mp4");
    };

    // src/module/bilibili.js
    var getBilibiliVideoInfo = async () => {
        const res = await fetch(window.location.href);
        const str = await res.text();
        const data = JSON.parse(
            str.match(/window.__playinfo__=([\d\D]+?)<\/script>/)[1]
        );
        const dash = data?.data?.dash;
        const video = dash.video.sort((a, b) => b?.width - a?.width)?.[0];
        const audio = dash.audio[0];
        const btit = document.title.substring(0,document.title.length-14);
        return [
            {
                url: video.baseUrl,
                fileName: btit+".m4v"
            },
            {
                url: audio.baseUrl,
                fileName: btit+".m4a"
            }
        ];
    };
    var bilibili_default = async () => {
        const urls = await getBilibiliVideoInfo();
        while (urls?.length) {
            const { url, fileName } = urls.shift();
            const file = await getFile(url);
            download(file, fileName);
        }
    };

    // src/module/douyin.js
    var getDouyinVideoInfo = () => {
        const urls = [...document.querySelectorAll("video source")].map((i) => i.src);
        var dyvt=document.title.concat(".mp4");
        return {
            url: urls[0],
            fileName: dyvt
        };
    };
    var douyin_default = async () => {
        const url = await getDouyinVideoInfo();
        const file = await getFile(url.url);
        download(file, url.fileName);
    };

    // src/module/kuaishou.js
    var getKuaishouVideoInfo = () => {
        var ktname = document.title;
        const urls = [...document.querySelectorAll("video")].map((i) => i.src);
        return {
            url: urls[0],
            fileName: ktname+".mp4"
        };
    };
    var kuaishou_default = async () => {
        const url = await getKuaishouVideoInfo();
        const file = await getFile(url.url);
        download(file, url.fileName);
    };

    // src/module/qq.js
    var proxyhttpBody = null;
    var monitor = async () => {
        try {
            window.__PLAYER__.pluginMsg.emit = new Proxy(
                window.__PLAYER__.pluginMsg.emit,
                {
                    apply: (...args) => {
                        if (args?.[2]?.[0] === "PROXY_HTTP_START" && args?.[2]?.[1]?.vinfoparam) {
                            console.log(args?.[2]?.[1]);
                            proxyhttpBody = JSON.stringify(args?.[2]?.[1]);
                        }
                        return Reflect.apply(...args);
                    }
                }
            );
        } catch (error) {
            console.log("monitor error");
        }
    };
    var getVideoInfo2 = async () => {
        let m3u8FileUrl = null;
        if (!m3u8FileUrl) {
            let res = await fetch("https://vd6.l.qq.com/proxyhttp", {
                method: "post",
                body: proxyhttpBody
            });
            res = await res.json();
            if (res?.errCode === 0 && res?.vinfo) {
                const data = safetyParse(res?.vinfo);
                const m3u8 = data?.vl?.vi?.sort((a, b) => b.vw - a.vw)?.[0]?.ul;
                if (m3u8) {
                    m3u8FileUrl = m3u8.ui[0].url;
                }
            }
        }
        const urls = await getUrlsByM3u8(m3u8FileUrl);
        return urls.map((url) => ({
            url,
            fileName: `qqvideo.mp4`
    }));
    };
    if (window.location.host === "v.qq.com") {
        monitor();
    }
    var qq_default = async () => {
        const urls = await getVideoInfo2();
        const files = await getFiles(urls);
        download(new Blob(files), "qqvideo.mp4");
    };

    // src/module/cctv.js
    var cctv_default = async () => {
        let data = await fetch(`https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid=${window.guid}`);
        data = await data.json();
        const m3u8FileUrl =data?.hls_url;
        var mbase=m3u8FileUrl?.substring(0,m3u8FileUrl?.lastIndexOf("/")+1);
        const urls = await getUrlsByM3u8(m3u8FileUrl, (i) => i);
        const files = await getFiles(urls.map((url) => ({ url:mbase+url })));
        download(new Blob(files), `${data.title}.mpeg`);
    };

    // src/module/youku.js
    var youku_default = async () => {
        if (!document.querySelector("meta#you-get-youku")) {
            const meta = document.createElement("meta");
            meta.httpEquiv = "Content-Security-Policy";
            meta.content = "upgrade-insecure-requests";
            meta.id = "you-get-youku";
            document.querySelector("head").appendChild(meta);
        }
        const data =window?.videoPlayer?.context?.mediaData?.mediaResource?._model?.streamList;
        if (data) {
            const m3u8FileUrl = data.sort((a, b) => b.width - a.width)[0].uri.HLS;
            const vtitle =window?.videoPlayer?.context?.mediaData?.mediaResource?._model?.video?.title;
            const urls = await getUrlsByM3u8(m3u8FileUrl, (i) => i);
            const files = await getFiles(urls.map((url) => ({ url })));
            document.title=vtitle+"---下载中...";
            download(new Blob(files), `${vtitle}.mpeg`);
            document.title=vtitle;
        }
    };

    // src/module/index.js
    var module_default = {
        bilibili: bilibili_default,
        douyin: douyin_default,
        kuaishou: kuaishou_default,
        acfun: acfun_default,
        qq: qq_default,
        cctv: cctv_default,
        youku: youku_default
    };

    // src/index.js
    var youget = () => {
        const handler = Object.entries(module_default).find(
            ([key, fn]) => window.location.host.toLocaleLowerCase().includes(key)
        )?.[1];
        if (handler) {
            handler();
        } else {
            console.log("not support");
        }
    };
    window.youget = youget;
    var bae=document.createElement("a");
    bae.style="position:fixed;top:10vh;right:1vw;font-size:2vw;z-index:99;color:#89FF89";
    bae.textContent="YouGet";
    bae.href="javascript:youget()";
    document.body.append(bae);
})();