// ==UserScript== // @name:en-US CCTV-HLS-Client // @name CCTV客户端视频解析 // @description:en-US parse cctv video to hls url. // @description 将CCTV视频解析成HLS地址. // @namespace https://greasyfork.org/users/135090 // @version 1.5.3 // @author [ZWB](https://greasyfork.org/zh-CN/users/863179) // @license CC // @grant none // @run-at document-end // @match *://*.cctv.com/*/*/*/V*.shtml* // @match *://*.cctv.cn/*/*/*/V*.shtml* // @match *://*.cctv.com/*/*/*/A*.shtml* // @match *://*.cctv.cn/*/*/*/A*.shtml* // @match *://vdn.apps.cntv.cn/api/getHttpVideoInfo* // @icon https://tv.cctv.cn/favicon.ico // @downloadURL none // ==/UserScript== (async () => { async function linkbutton(guid, n) { let base = "https://vdn.apps.cntv.cn"; let pathname = "/api/getHttpVideoInfo.do"; let apihref = base + pathname + `?client=flash&im=0&pid=${guid}`; let bts = n * 40 + 20; let btn = document.createElement("a"); btn.href = apihref; btn.id = "btn" + n; btn.type = "button"; btn.target = "_blank"; btn.textContent = "点击跳转到下载页"+(n+1); btn.style = ` position: fixed; z-index: 999; bottom: ${bts}px; right: 20px; background-color: #f86336; color: white; padding: 5px; border: none; cursor: pointer; font-size: 16px; `; document.body.appendChild(btn); } if (location.hostname.indexOf(".cctv.com") > 0 || location.hostname.indexOf(".cctv.cn") > 0) { setTimeout(async () => { if ( window?.guid?.length >0){ let base = "https://vdn.apps.cntv.cn"; let pathname = "/api/getHttpVideoInfo.do"; let apihref = base + pathname + `?client=flash&im=0&pid=${guid}`; location.href = (apihref); //直接跳转需要取消注释 } if (window?.playerParas?.vdn?.vdnUrl != undefined ){ let apihref = window?.playerParas?.vdn?.vdnUrl; location.href = (apihref); //直接跳转需要取消注释 } if (window?.vodh5player?.playerList?.length > 1) { window?.vodh5player?.playerList?.forEach((i, n) => { let guid = i?.options_?.paras?.videoId; linkbutton(guid, n); }); return; } else if (window?.vodh5player?.playerList?.length == 1){ let guid = window?.vodh5player?.playerList[0]?.options_?.paras?.videoId; let base = "https://vdn.apps.cntv.cn"; let pathname = "/api/getHttpVideoInfo.do"; let apihref = base + pathname + `?client=flash&im=0&pid=${guid}`; location.href = (apihref); //直接跳转需要取消注释 } }, 1250); } if (location.hostname.indexOf("vdn.apps.cntv.cn") > -1) { let data = await JSON.parse(document?.body?.textContent); //解析成JSON对象 let title = data?.title?.replaceAll(" ", ""); //视频标题 let normal = data?.manifest?.hls_enc2_url; //普通加密视频 let is4K = data?.play_channel?.indexOf("4K") > 0 ? true : false; const brarry = ["450", "850", "1200", "2000", "4000"]; document.title = title; //网页标题由视频标题提供 let hlsUrl = data?.hls_url?.replaceAll("main", brarry[4]); if (is4K) { console.info("4K频道只有一种清晰度可选,直接使用此清晰度") } else { let brcount = await parseM3u8(normal); console.log(brcount + "个"); let bri = brcount - 1; if (brcount < 3) { hlsUrl = data?.hls_url?.replaceAll("main", brarry[bri]); //360P及以下未加密 } else { hlsUrl = normal?.replaceAll("main", brarry[bri]); //高码率普通视频 } let tsnlen = hlsUrl.split("/").length - 2; //在api页获取guid值在播放链接中的索引 let tsn = hlsUrl.split("/")[tsnlen]; //根据索引得到guid值,其实也可以用let tsn = location.search.split('&')[2].slice(4); console.info("guid:" + tsn); title = title.length > 0 ? title : tsn + "_guid.ts"; //标题空格用_代替 } let hlsfull = hlsUrl.split("&")[0]; //防止复制到命令行的地址产生歧义 document.body.innerHTML = `