Greasy Fork

Greasy Fork is available in English.

PotPlayer云盘-专供版

此脚本为《PotPlayer播放云盘视频》姊妹篇,需配合MediaPlayParse - PanVideo.as脚本使用。在potplayer中选择画质、字幕,迅雷云盘增加原画,阿里云盘增加时长。

当前为 2022-05-24 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         PotPlayer云盘-专供版
// @namespace    https://github.com/Bleu404/PotplayerPanVideoSV
// @version      1.0.3
// @description  此脚本为《PotPlayer播放云盘视频》姊妹篇,需配合MediaPlayParse - PanVideo.as脚本使用。在potplayer中选择画质、字幕,迅雷云盘增加原画,阿里云盘增加时长。
// @author       bleu
// @compatible   edge Tampermonkey
// @compatible   chrome Tampermonkey
// @compatible   firefox Tampermonkey
// @license      MIT
// @match        https://pan.xunlei.com/*
// @match        https://www.aliyundrive.com/*
// @icon         https://fastly.jsdelivr.net/gh/Bleu404/PRPO@latest/png/ppvsv.png
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_xmlhttpRequest
// @grant        GM_registerMenuCommand
// @grant        unsafeWindow
// @connect      *
// @require      https://fastly.jsdelivr.net/npm/[email protected]/dist/sweetalert2.all.min.js
// @require      https://fastly.jsdelivr.net/npm/[email protected]/bleutools.min.js
// ==/UserScript==

(function () {
    'use strict';
    let bleuc,contextMenu, itemsInfo, arryIndex, Option, observer;
    const flieTypeStr = ".wmv,.rmvb,.avi,.mp4,.mkv,.flv,.swf.mpeg4,.mpeg2,.3gp,.mpga,.qt,.rm,.wmz,.wmd,.wvx,.wmx,.wm,.mpg,.mpeg,mov,.asf,.m4v,";
    const tools = {
        runFunction(funcName, attrval) {
            switch (document.domain) {
                case 'xunlei.com':
                    return xunlei[funcName](attrval);
                case 'www.aliyundrive.com':
                    return aliyun[funcName](attrval);
                default:
                    return null;
            }
        },
        checkFileType(name) {
            let type = name.substring(name.lastIndexOf('.')) || "bleu"
            return flieTypeStr.indexOf(`${type},`) > 0 ? true : false
        },
        async putFileInWebdav(name, info) {
            let header = {
                "authorization": `Basic ${btoa(`${bleuc.cun}:${bleuc.cpw}`)}`
            }
            let url = `https://${bleuc.cip}/PanPlaylist`;
            await bleu.XHR('PROPFIND', url, undefined, header, undefined).then(async (res) => {
                if (!(res.status >= 200 && res.status < 300)) {
                    await bleu.XHR('MKCOL', url, undefined, header, undefined)
                }
            })
            url = `https://${bleuc.cip}/PanPlaylist/${name}`;
            await bleu.XHR('PUT',url , info, header, 'xml').then((res) => {
                res.status >= 200 && res.status < 300 ? bleu.swalInfo(`✅${name}`, 3000, 'center') :
                    bleu.swalInfo(`❌${name}`, 3000, 'center');
            }, () => bleu.swalInfo(`❌${name}`, 3000, 'center'))
        },
        checkConfig() {
            bleuc = JSON.parse(GM_getValue('bleuc') || null) || {cip: '',cun: '',cpw: ''};
            if (!(bleuc.cip != '' && bleuc.cun != '' && bleuc.cpw != '')) {
                bleu.swalInfo(`❗请先设置WEBDAV`, '', 'center')
                return false
            }
            return true
        },
        saveConfig() {
            let temp = document.querySelector('#cip').value.trim()
            temp = temp.charAt(temp.length - 1) === '/' ? temp.substring(0, temp.length - 1) : temp
            temp = temp.indexOf('https://') < 0 ? temp : temp.replace('https://', '')
            GM_setValue("bleuc", JSON.stringify({
                'cip': temp,
                'cun': document.querySelector('#cun').value.trim(),
                'cpw': document.querySelector('#cpw').value.trim(),
            }));
        },
        configHtml() {
            bleuc = JSON.parse(GM_getValue('bleuc') || null) || {cip: '',cun: '',cpw: ''};
            let html = `
                <div class="bleuc_config_item"><p>
                <div><label>主机:</label><input type="text" class="bleuc_inp" id="cip" value="${bleuc.cip}"/></div>
                <div><label>用户:</label><input type="text" class="bleuc_inp" id="cun" value="${bleuc.cun}"/></div>
                <div><label>密码:</label><input type="text" class="bleuc_inp" id="cpw" value="${bleuc.cpw}"/></div></p></div>
                `;
            return html;
        },
        cssStyle: `
            .bleuc_config_item{border-radius: 10px;font-size: 20px;margin: 12px 50px;color: #fff;background: linear-gradient(45deg,#12c2e9, #c471ed, #f64f59);box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, 0.2);}
            .bleuc_config_item label{font-size: 15px}
            .bleuc_config_item input.bleuc_inp{margin: 0px 10px;font-size: 15px;background: linear-gradient(45deg,#12c2e9, #c471ed, #f64f59);border-style:none;color:black;width:200px}
            .bleuc_config_item p{text-align: left;margin: 0px 20px;}`,

    }
    const xunlei = {
        addTag() {
            if (contextMenu.innerText.match(/PotPlayer/)) return
            let ul = document.createElement('ul');
            ul.innerHTML = `<a id="bleuReSave" class="pan-dropdown-menu-item">PotPlayer打开</a>`;
            contextMenu.firstChild.prepend(ul.firstChild);
            main.addClickEvent();
        },
        getselectFilesInfo() {
            let temp = document.querySelectorAll('li.pan-list-item.pan-list-item-active');
            temp.forEach((item) => {
                this._pushItem(item.__vue__.info);
            })
        },
        async updateFile(item) {
            Option["list"].push({
                "title": item.name,
                "url": `https://api-pan.xunlei.com/drive/v1/files/${item.id}`
            });
        },
        async openNextDir(item) {
            let url = `https://api-pan.xunlei.com/drive/v1/files?limit=100&parent_id=${item.id}&filters={"phase":{"eq":"PHASE_TYPE_COMPLETE"},"trashed":{"eq":false}}&with_audit=true`;
            await bleu.XHR('GET', url, undefined, Option.header).then((res) => {
                arryIndex++;
                if (!(res.status >= 200 && res.status < 300)) {bleu.swalInfo("🔴💬刷新页面,重新获取header", '', 'center');return};
                res.response.files.forEach((item) => {
                    xunlei._pushItem(item);
                })
            })
        },
        findContext(node) {
            if (node.className === 'pan-content') {
                node = node.querySelector('div.pan-dropdown-menu.context-menu');
                if (!node) return;
                contextMenu = node;
                xunlei.addTag();
            }
        },
        closeMenu() {},
        _pushItem(temp) {
            if (!itemsInfo[arryIndex]) itemsInfo[arryIndex] = [];
            if (temp.kind === 'drive#file' && !tools.checkFileType(temp.name)) return
            let itemInfo = {
                'id': temp.id,
                'isdir': temp.kind === 'drive#file' ? false : true,
                'name': temp.name,
            };
            itemsInfo[arryIndex].push(itemInfo);
        },
        getHeaderInfo() {
            Option.header = {};
            Option.header.withCredentials = false;
            Option.header['content-type'] = 'application/json';
            for (let key in localStorage) {
                let temp = localStorage.getItem(key)
                if (key.indexOf('credentials') === 0) {
                    Option.header["Authorization"] = JSON.parse(temp).token_type + ' ' + JSON.parse(temp).access_token;
                    Option["clientid"] = key.substring(key.indexOf('_') + 1);
                }
                if (key.indexOf('captcha') === 0)
                    Option.header['x-captcha-token'] = JSON.parse(temp).token
                if (key === 'deviceid')
                    Option.header['x-device-id'] = temp.substring(temp.indexOf('.') + 1, 32 + temp.indexOf('.') + 1)
            }
        },
        async finallyFunc() {
            Option.header["clientid"] = Option["clientid"];
            await tools.putFileInWebdav('panvideo.txt', JSON.stringify(Option));
            unsafeWindow.location.href = `potplayer://panvideo##xunlei##${JSON.stringify(Option.header)}##https://${bleuc.cip}/PanPlaylist/panvideo.txt##${bleuc.cun}##${bleuc.cpw}`;
        }
    }
    const aliyun = {
        addTag() {
            if (contextMenu.innerText.match(/PotPlayer|新建/)) return
            let ul = document.createElement('ul');
            ul.innerHTML = `<li id="bleuReSave" class="ant-dropdown-menu-item ant-dropdown-menu-item-only-child" role="menuitem"><div class="outer-menu--ihDUR"><div data-confirm="false" class="menu-wrapper--1ZYh_" data-spm-anchor-id="aliyundrive.drive.0.i11.40516c75ahPUGN"><div class="menu-name--1F5vk" data-spm-anchor-id="aliyundrive.drive.0.i12.40516c75ahPUGN">PotPlayer打开</div></div></div></li>`;
            contextMenu.prepend(ul.firstChild);
            main.addClickEvent();
        },
        getselectFilesInfo() {
            let temp = document.querySelectorAll('div[data-index]')
            let attrName;
            for(let attr in temp[0]){
                if(attr.indexOf('__reactFiber')==0){
                    attrName = attr;
                    break;
                }
            }
            temp.forEach((item)=>{
                if(item.querySelector('input')&&item.querySelector('input').checked){
                    let value = item[attrName].return.pendingProps;
                    aliyun._pushItem(value.data[value.index]||value.data[value.rowIndex][value.columnIndex]);
                }
            })
            
        },
        async updateFile(item) {
            Option["list"].push({
                "title": item.name,
                "url": "https://"+item.id
            });
        },
        async openNextDir(item) {
            let url = `https://api.aliyundrive.com/adrive/v3/file/list?jsonmask=next_marker%2Citems(name%2Cfile_id%2Cdrive_id%2Ctype%2Csize%2Ccreated_at%2Cupdated_at%2Ccategory%2Cfile_extension%2Cparent_file_id%2Cmime_type%2Cstarred%2Cthumbnail%2Curl%2Cstreams_info%2Ccontent_hash%2Cuser_tags%2Ctrashed%2Cvideo_media_metadata%2Cvideo_preview_metadata)`,
                token = JSON.parse(localStorage.getItem('token')),
                data = {
                    'drive_id': token.default_drive_id,
                    'parent_file_id': item.id,
                    'limit': 100,
                },
                header = {
                    'x-canary': 'client=web,app=adrive,version=v2.4.0',
                    //'x-device-id': document.cookie.match(/cna=([^;]*)/)[1],
                    authorization: `${token.token_type} ${token.access_token}`
                };
            await bleu.XHR('POST', url, JSON.stringify(data),header).then((res) => {
                arryIndex++;
                if(!(res.status>=200&&res.status<300)){bleu.swalInfo("🔴💬刷新页面,重新获取", '', 'center');return}
                res.response.items.forEach((item)=>{
                    aliyun._pushItem(item);
                })
            })
        },
        findContext(node) {
            node = document.querySelector('ul.ant-dropdown-menu');
            if (!node) return;
            //observer.disconnect();
            contextMenu = node;
            aliyun.addTag();
        },
        closeMenu(){
            contextMenu.parentNode.className='ant-dropdown dropdown-menu--1KRbu ant-dropdown-placement-bottomLeft  ant-dropdown-hidden';
            contextMenu.parentNode.style.left='-578px'; 
            contextMenu.parentNode.style.top='-646px';
        },
        _pushItem(temp) {
            if(!itemsInfo[arryIndex]) itemsInfo[arryIndex]= [];
            if (temp.type==='file'&&temp.category!="video") return
            let itemInfo = {
                'id': temp.fileId||temp.file_id,
                'isdir': temp.type === 'file' ? false : true,
                'name': temp.name,
            };
            itemsInfo[arryIndex].push(itemInfo);
        },
        getHeaderInfo() {
            Option.header ={};
            let token = JSON.parse(localStorage.getItem('token'));
            Option.header["authorization"] =`${token.token_type} ${token.access_token}`;
            Option.header["drive_id"] =token.default_drive_id;
        },
        async finallyFunc(){
            await tools.putFileInWebdav('panvideo.txt', JSON.stringify(Option));
            unsafeWindow.location.href = `potplayer://panvideo##aliyun##${JSON.stringify(Option.header)}##https://${bleuc.cip}/PanPlaylist/panvideo.txt##${bleuc.cun}##${bleuc.cpw}`;
        }
    }
    const main = {
        init() {
            observer = new MutationObserver(function (mutations) {
                for (let mutation of mutations) {
                    if (mutation.type === 'childList') {
                        tools.runFunction('findContext', mutation.target);
                    }
                }
            });
            observer.observe(document, {
                'childList': true,
                'subtree': true
            });
        },
        addClickEvent() {
            let bleuButton = document.getElementById('bleuReSave');
            bleuButton.addEventListener('click', async function () {
                itemsInfo = [];
                arryIndex = 0;
                Option = {}, Option["list"] = [];
                tools.runFunction('closeMenu');
                tools.runFunction('getselectFilesInfo');
                tools.runFunction('getHeaderInfo');
                await main.updateAllFiles(itemsInfo[arryIndex]);
                tools.runFunction('finallyFunc');
            })
        },
        async updateAllFiles(loopArry) {
            for (let index = 0; index < loopArry.length; index++) {
                if (!loopArry[index].isdir) {
                    await tools.runFunction('updateFile', loopArry[index]);
                } else {
                    await tools.runFunction('openNextDir', loopArry[index]);
                    await main.updateAllFiles(itemsInfo[arryIndex]);
                }
                bleu.sleep(800);
            }
        },
    };
    tools.checkConfig();
    bleu.addCssStyle(tools.cssStyle);
    GM_registerMenuCommand('配置WEBDAV', () => {
        bleu.swalUI('WEBDAV', tools.configHtml(), '400px').then(tools.saveConfig)
    }, 'w')
    main.init();
})();