// ==UserScript== // @name 视频全平台解析下载助手 // @namespace http://tampermonkey.net/ // @version 1.0.0 // @description 支持哔哩哔哩、YouTube、抖音、爱奇艺、腾讯视频、优酷、西瓜视频、小红书、快手、微博等全平台视频解析下载,支持最高清MP4、MP3音频、弹幕字幕等 // @author WorkBuddy // @match *://www.bilibili.com/* // @match *://www.youtube.com/* // @match *://www.douyin.com/* // @match *://www.ixigua.com/* // @match *://www.iqiyi.com/* // @match *://v.qq.com/* // @match *://www.youku.com/* // @match *://www.xiaohongshu.com/* // @match *://www.kuaishou.com/* // @match *://weibo.com/* // @match *://m.bilibili.com/* // @match *://m.youtube.com/* // @match *://m.douyin.com/* // @match *://m.ixigua.com/* // @match *://m.iqiyi.com/* // @match *://m.v.qq.com/* // @match *://m.youku.com/* // @match *://m.xiaohongshu.com/* // @match *://m.kuaishou.com/* // @match *://m.weibo.com/* // @grant GM_xmlhttpRequest // @grant GM_download // @grant GM_notification // @connect * // @run-at document-end // @license MIT // ==/UserScript== (function() { 'use strict'; // 平台配置 const platforms = { bilibili: { name: '哔哩哔哩', regex: /bilibili\.com/, videoIdRegex: /\/video\/(BV[\w]+)|(av\d+)/, api: 'https://api.bilibili.com/x/web-interface/view', playUrl: 'https://api.bilibili.com/x/player/playurl' }, youtube: { name: 'YouTube', regex: /youtube\.com|youtu\.be/, videoIdRegex: /[?&]v=([^&]+)|(youtu\.be\/)([\w-]+)/, api: 'https://www.youtube.com/oembed?url=' }, douyin: { name: '抖音', regex: /douyin\.com/, videoIdRegex: /\/video\/(\d+)/, api: 'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/' }, iqiyi: { name: '爱奇艺', regex: /iqiyi\.com/, videoIdRegex: /\/([a-z0-9]+)\.html/, api: 'https://pcw-api.iqiyi.com' }, qq: { name: '腾讯视频', regex: /v\.qq\.com/, videoIdRegex: /\/([a-z0-9\/]+)\.html/, api: 'https://vv.video.qq.com' }, youku: { name: '优酷', regex: /youku\.com/, videoIdRegex: /\/id_([a-zA-Z0-9]+)/, api: 'https://api.youku.com' }, xiaohongshu: { name: '小红书', regex: /xiaohongshu\.com/, videoIdRegex: /\/explore\/([a-z0-9]+)/, api: 'https://edith.xiaohongshu.com' }, kuaishou: { name: '快手', regex: /kuaishou\.com/, videoIdRegex: /\/short-video\/([a-z0-9]+)/, api: 'https://www.kuaishou.com' }, weibo: { name: '微博', regex: /weibo\.com/, videoIdRegex: /\/tv\/show\/([a-z0-9]+)/, api: 'https://weibo.com' }, ixigua: { name: '西瓜视频', regex: /ixigua\.com/, videoIdRegex: /\/(\d+)/, api: 'https://www.ixigua.com' } }; // 第三方解析API列表 const parseApis = [ 'https://jx.xmflv.com/?url=', 'https://jx.quankan.app/?url=', 'https://jx.m3u8.tv/jiexi/?url=', 'https://jx.aidouer.net/?url=', 'https://jx.jsonplayer.com/player/?url=' ]; // 创建下载面板UI function createDownloadPanel() { const panel = document.createElement('div'); panel.id = 'video-downloader-panel'; panel.innerHTML = `
🎬 视频下载助手
视频标题
平台名称
`; // 添加样式 const style = document.createElement('style'); style.textContent = ` #video-downloader-panel { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 99999; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; } .vd-panel { width: 420px; background: #fff; border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,0.3); overflow: hidden; animation: vdSlideIn 0.3s ease; } @keyframes vdSlideIn { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } } .vd-header { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #fff; } .vd-title { font-size: 16px; font-weight: bold; } .vd-close { background: none; border: none; color: #fff; font-size: 24px; cursor: pointer; line-height: 1; } .vd-content { padding: 20px; } .vd-info { margin-bottom: 15px; padding: 10px; background: #f5f7fa; border-radius: 8px; } .vd-title-text { font-weight: bold; color: #333; margin-bottom: 5px; word-break: break-all; } .vd-platform { color: #999; font-size: 13px; } .vd-quality, .vd-formats { margin-bottom: 15px; } .vd-quality label, .vd-formats label { display: block; margin-bottom: 8px; color: #666; font-size: 14px; } #vd-quality-select { width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 6px; font-size: 14px; } .vd-format-options { display: flex; flex-wrap: wrap; gap: 10px; } .vd-format-options label { display: flex; align-items: center; cursor: pointer; font-size: 13px; } .vd-format-options input { margin-right: 5px; } .vd-buttons { display: flex; gap: 10px; margin-bottom: 15px; } .vd-btn { flex: 1; padding: 10px; border: none; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: bold; color: #fff; transition: transform 0.2s; } .vd-btn:hover { transform: translateY(-2px); } .vd-btn-primary { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); } .vd-btn-success { background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%); } .vd-btn-info { background: linear-gradient(135deg, #2193b0 0%, #6dd5ed 100%); } .vd-status { padding: 10px; margin-bottom: 15px; border-radius: 6px; font-size: 13px; text-align: center; } .vd-status.loading { background: #e3f2fd; color: #1976d2; } .vd-status.success { background: #e8f5e9; color: #2e7d32; } .vd-status.error { background: #ffebee; color: #c62828; } .vd-download-links { max-height: 200px; overflow-y: auto; padding: 10px; background: #f5f7fa; border-radius: 6px; } .vd-download-link { display: flex; align-items: center; padding: 8px; margin-bottom: 8px; background: #fff; border-radius: 4px; text-decoration: none; color: #333; font-size: 13px; } .vd-download-link:hover { background: #e3f2fd; } .vd-download-link span { flex: 1; } .vd-download-link-icon { font-size: 16px; } .vd-btn-warning { background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); } .vd-player-container { margin-top: 15px; padding: 10px; background: #000; border-radius: 8px; position: relative; } .vd-player-container iframe { width: 100%; height: 300px; border: none; border-radius: 4px; } .vd-player-close { position: absolute; top: -10px; right: -10px; width: 30px; height: 30px; background: rgba(255, 255, 255, 0.9); border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 20px; color: #333; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); z-index: 10; transition: all 0.3s; } .vd-player-close:hover { transform: scale(1.1); background: #fff; } .vd-player-loading { display: flex; align-items: center; justify-content: center; height: 300px; color: #fff; font-size: 14px; } .vd-player-loading::after { content: ''; display: inline-block; width: 20px; height: 20px; margin-left: 10px; border: 2px solid #fff; border-top-color: transparent; border-radius: 50%; animation: vdSpin 0.8s linear infinite; } @keyframes vdSpin { to { transform: rotate(360deg); } } .vd-player-controls { display: flex; gap: 10px; padding: 10px 0; flex-wrap: wrap; } .vd-player-control-btn { flex: 1; min-width: 80px; padding: 8px; border: none; border-radius: 4px; cursor: pointer; font-size: 12px; background: rgba(255, 255, 255, 0.1); color: #fff; transition: all 0.3s; } .vd-player-control-btn:hover { background: rgba(255, 255, 255, 0.2); } .vd-player-control-btn.active { background: #667eea; } `; document.head.appendChild(style); document.body.appendChild(panel); // 事件绑定 panel.querySelector('.vd-close').addEventListener('click', () => { panel.remove(); }); return panel; } // 创建浮动按钮 function createFloatButton() { const btn = document.createElement('div'); btn.id = 'vd-float-btn'; btn.innerHTML = '🎬'; btn.title = '视频下载助手'; const style = document.createElement('style'); style.textContent = ` #vd-float-btn { position: fixed; top: 50%; right: 20px; width: 50px; height: 50px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 99998; font-size: 24px; box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4); transition: all 0.3s; } #vd-float-btn:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6); } `; document.head.appendChild(style); document.body.appendChild(btn); btn.addEventListener('click', () => { const existingPanel = document.getElementById('video-downloader-panel'); if (existingPanel) { existingPanel.remove(); } else { const panel = createDownloadPanel(); initVideoInfo(); } }); } // 获取当前平台和视频信息 function getPlatformAndVideoInfo() { const url = window.location.href; for (const [key, platform] of Object.entries(platforms)) { if (platform.regex.test(url)) { let videoId = null; const match = url.match(platform.videoIdRegex); if (match) { videoId = match[1] || match[2] || match[3]; } return { platform: key, platformName: platform.name, videoId: videoId, url: url }; } } return null; } // 获取视频信息 async function fetchVideoInfo(platformInfo) { const { platform, videoId, url } = platformInfo; try { switch (platform) { case 'bilibili': return await fetchBilibiliInfo(videoId); case 'youtube': return await fetchYoutubeInfo(videoId, url); case 'douyin': return await fetchDouyinInfo(url); case 'iqiyi': return await fetchIqiyiInfo(url); case 'qq': return await fetchQQVideoInfo(url); case 'youku': return await fetchYoukuInfo(url); case 'xiaohongshu': return await fetchXiaohongshuInfo(url); case 'kuaishou': return await fetchKuaishouInfo(url); case 'weibo': return await fetchWeiboInfo(url); case 'ixigua': return await fetchIxiguaInfo(url); default: throw new Error('不支持的平台'); } } catch (error) { console.error('获取视频信息失败:', error); throw error; } } // 哔哩哔哩视频信息 async function fetchBilibiliInfo(bvid) { const response = await fetch(`https://api.bilibili.com/x/web-interface/view?bvid=${bvid}`); const data = await response.json(); if (data.code === 0 && data.data) { return { title: data.data.title, cover: data.data.pic, duration: data.data.duration, author: data.data.owner.name }; } throw new Error('获取B站视频信息失败'); } // YouTube视频信息 async function fetchYoutubeInfo(videoId, url) { return { title: document.title || 'YouTube视频', cover: `https://img.youtube.com/vi/${videoId}/maxresdefault.jpg`, duration: '未知', author: 'YouTube创作者' }; } // 抖音视频信息 async function fetchDouyinInfo(url) { const title = document.querySelector('.title')?.textContent || document.querySelector('[data-e2e="video-desc"]')?.textContent || '抖音视频'; return { title: title, cover: '', duration: '未知', author: '抖音用户' }; } // 爱奇艺视频信息 async function fetchIqiyiInfo(url) { const title = document.querySelector('.intro-title')?.textContent || document.querySelector('[data-player-hook="title"]')?.textContent || '爱奇艺视频'; return { title: title, cover: '', duration: '未知', author: '爱奇艺' }; } // 腾讯视频信息 async function fetchQQVideoInfo(url) { const title = document.querySelector('.player_title')?.textContent || document.querySelector('.video_title')?.textContent || '腾讯视频'; return { title: title, cover: '', duration: '未知', author: '腾讯视频' }; } // 优酷视频信息 async function fetchYoukuInfo(url) { const title = document.querySelector('.title')?.textContent || document.querySelector('.video-title')?.textContent || '优酷视频'; return { title: title, cover: '', duration: '未知', author: '优酷' }; } // 小红书视频信息 async function fetchXiaohongshuInfo(url) { const title = document.querySelector('.title')?.textContent || document.querySelector('[class*="title"]')?.textContent || '小红书视频'; return { title: title, cover: '', duration: '未知', author: '小红书用户' }; } // 快手视频信息 async function fetchKuaishouInfo(url) { const title = document.querySelector('.video-title')?.textContent || document.querySelector('[class*="title"]')?.textContent || '快手视频'; return { title: title, cover: '', duration: '未知', author: '快手用户' }; } // 微博视频信息 async function fetchWeiboInfo(url) { const title = document.querySelector('.WB_text')?.textContent || document.querySelector('[class*="title"]')?.textContent || '微博视频'; return { title: title.substring(0, 50), cover: '', duration: '未知', author: '微博用户' }; } // 西瓜视频信息 async function fetchIxiguaInfo(url) { const title = document.querySelector('.title')?.textContent || document.querySelector('[class*="title"]')?.textContent || '西瓜视频'; return { title: title, cover: '', duration: '未知', author: '西瓜视频用户' }; } // 解析视频URL function parseVideoUrl(url, quality) { const parseUrl = parseApis[0] + encodeURIComponent(url); return parseUrl; } // 初始化视频信息 async function initVideoInfo() { const platformInfo = getPlatformAndVideoInfo(); if (!platformInfo) { showStatus('当前页面不支持解析', 'error'); return; } try { const videoInfo = await fetchVideoInfo(platformInfo); // 更新UI const titleEl = document.querySelector('.vd-title-text'); const platformEl = document.querySelector('.vd-platform'); if (titleEl) titleEl.textContent = videoInfo.title; if (platformEl) platformEl.textContent = `${videoInfo.platformName} - ${videoInfo.author}`; // 存储当前视频信息 window.currentVideoInfo = { ...platformInfo, ...videoInfo }; showStatus(`已识别: ${videoInfo.title}`, 'success'); } catch (error) { showStatus('获取视频信息失败: ' + error.message, 'error'); } } // 显示状态信息 function showStatus(message, type = 'success') { const statusEl = document.getElementById('vd-status'); if (statusEl) { statusEl.textContent = message; statusEl.className = `vd-status ${type}`; } } // 解析视频 async function parseVideo() { if (!window.currentVideoInfo) { showStatus('请先刷新页面', 'error'); return; } showStatus('正在解析视频...', 'loading'); const quality = document.getElementById('vd-quality-select').value; const parseUrl = parseVideoUrl(window.currentVideoInfo.url, quality); // 显示解析链接 const linksContainer = document.getElementById('vd-download-links'); linksContainer.innerHTML = ''; parseApis.forEach((api, index) => { const link = document.createElement('a'); link.className = 'vd-download-link'; link.href = api + encodeURIComponent(window.currentVideoInfo.url); link.target = '_blank'; link.innerHTML = ` 解析源 ${index + 1}: ${api} ↗️ `; linksContainer.appendChild(link); }); showStatus('解析完成! 点击上方链接下载', 'success'); } // 在线播放 async function playVideoInline() { if (!window.currentVideoInfo) { showStatus('请先解析视频', 'error'); return; } const playerContainer = document.getElementById('vd-player-container'); playerContainer.style.display = 'block'; playerContainer.innerHTML = '
正在加载播放器...
'; showStatus('正在加载播放器...', 'loading'); try { const quality = document.getElementById('vd-quality-select').value; const parseUrl = parseApis[0] + encodeURIComponent(window.currentVideoInfo.url); // 创建内嵌播放器 playerContainer.innerHTML = `

💡 提示: 播放器使用第三方解析接口,如无法播放请尝试其他解析源

`; // 绑定关闭按钮 playerContainer.querySelector('.vd-close-player').addEventListener('click', () => { playerContainer.style.display = 'none'; playerContainer.innerHTML = ''; }); showStatus('播放器加载成功!', 'success'); } catch (error) { showStatus('加载播放器失败: ' + error.message, 'error'); playerContainer.innerHTML = '
加载失败,请稍后重试
'; } } // 下载视频 function downloadVideo() { if (!window.currentVideoInfo) { showStatus('请先解析视频', 'error'); return; } const format = document.querySelector('input[name="vd-format"]:checked').value; const quality = document.getElementById('vd-quality-select').value; switch (format) { case 'mp4': // 使用第一个解析API window.open(parseApis[0] + encodeURIComponent(window.currentVideoInfo.url), '_blank'); break; case 'mp3': // 使用专门提取音频的解析API const audioApi = 'https://jx.xmflv.com/?url='; window.open(audioApi + encodeURIComponent(window.currentVideoInfo.url), '_blank'); break; case 'danmu': // 下载弹幕字幕 downloadDanmu(); break; case 'cover': // 下载封面 if (window.currentVideoInfo.cover) { window.open(window.currentVideoInfo.cover, '_blank'); } else { showStatus('无法获取封面图片', 'error'); } break; } showStatus('正在打开下载页面...', 'success'); } // 下载弹幕 function downloadDanmu() { if (!window.currentVideoInfo || window.currentVideoInfo.platform !== 'bilibili') { showStatus('目前仅支持B站弹幕下载', 'error'); return; } const bvid = window.currentVideoInfo.videoId; const danmuUrl = `https://api.bilibili.com/x/v1/dm/list.so?oid=${bvid}`; window.open(danmuUrl, '_blank'); } // 复制链接 function copyLink() { if (!window.currentVideoInfo) { showStatus('请先解析视频', 'error'); return; } const quality = document.getElementById('vd-quality-select').value; const parseUrl = parseApis[0] + encodeURIComponent(window.currentVideoInfo.url); navigator.clipboard.writeText(parseUrl).then(() => { showStatus('链接已复制到剪贴板', 'success'); }).catch(() => { showStatus('复制失败,请手动复制', 'error'); }); } // 初始化 function init() { // 延迟加载,确保页面完全加载 setTimeout(() => { createFloatButton(); // 监听URL变化 let lastUrl = location.href; new MutationObserver(() => { const currentUrl = location.href; if (currentUrl !== lastUrl) { lastUrl = currentUrl; if (document.getElementById('video-downloader-panel')) { initVideoInfo(); } } }).observe(document.body, { subtree: true, childList: true }); }, 1000); } // 绑定按钮事件 document.addEventListener('click', (e) => { if (e.target.id === 'vd-parse-btn') { parseVideo(); } else if (e.target.id === 'vd-download-btn') { downloadVideo(); } else if (e.target.id === 'vd-copy-btn') { copyLink(); } }); // 启动脚本 init(); console.log('🎬 视频全平台解析下载助手已启动!'); console.log('支持平台: 哔哩哔哩、YouTube、抖音、爱奇艺、腾讯视频、优酷、西瓜视频、小红书、快手、微博'); })();