在楼上的基础上完善了下
- function base64ToHex(base64String) {
- const decodedString = atob(base64String);
- let hexString = '';
- for (let i = 0; i < decodedString.length; i++) {
- const hexValue = decodedString.charCodeAt(i).toString(16);
- hexString += hexValue.length === 2 ? hexValue : '0' + hexValue;
- }
- return hexString.toUpperCase();
- }
- function shuffle(array) {
- let arrayLength = array.length;
- for (let i = 0; i < arrayLength; i++) {
- let lastElementIndex = arrayLength - 1;
- let randomIndex = Math.random() * (lastElementIndex + 1) >> 0;
- let temp = array[lastElementIndex];
- array[lastElementIndex] = array[randomIndex];
- array[randomIndex] = temp;
- }
- return array;
- }
- function dealM3u8(videoElement, videoUrl, videoPlayer) {
- const request = new XMLHttpRequest();
- videoUrl = videoUrl.replace("www.bde4.cc", document.domain).replace("https:", location.protocol);
- request.responseType = "arraybuffer";
- request.open("GET", videoUrl, true);
- request.onload = function (event) {
- const response = request.response;
- let byteArray = new Uint8Array(response);
- byteArray = byteArray.slice(3354);
- const decompressedData = pako.inflate(byteArray);
- let decodedString = '';
- let index;
- for (index = 0; index < decompressedData.length / 16384; index++) {
- decodedString += String.fromCharCode.apply(null, decompressedData.slice(index * 16384, (index + 1) * 16384));
- }
- decodedString += String.fromCharCode.apply(null, decompressedData.slice(index * 16384));
- decodedString = decodedString.replace(/.*?\.ts/g, "https://vod.bdys.me/$&");
- const isNewVideo = !!(videoElement.src == '');
- videoElement.src = "data:application/vnd.apple.mpegurl;base64," + btoa(decodedString);
- if (Hls.isSupported()) {
- if (videoPlayer.hls) { } else {
- const hlsConfig = {
- autoStartLoad: true,
- startFragPrefetch: true,
- maxBufferLength: 0x12c
- };
- videoPlayer.hls = new Hls(hlsConfig);
- }
- videoPlayer.hls.loadSource(videoElement.src);
- videoPlayer.hls.attachMedia(videoElement);
- videoPlayer.once("url", () => hls.destroy());
- videoPlayer.once("destroy", () => hls.destroy());
- } else {
- videoPlayer.notice.show = "浏览器不支持m3u8播放!";
- }
- if (!isNewVideo) {
- videoPlayer.play();
- }
- };
- request.send();
- }
- function error(message) {
- const toastOptions = {
- text: message,
- position: "mid-center",
- icon: "error",
- loader: false,
- stack: false
- };
- $.toast(toastOptions);
- }
- let lines = [];
- let playLines = [];
- function dealUrl(videoData) {
- if (videoData.url.indexOf("handler") > 0) {
- videoData.url += '/' + new Date().getTime() + ".mp4";
- }
- videoData.url = videoData.url.replace("?rkey", new Date().getTime() + ".mp4?ver=6010&rkey");
- if (videoData.url.indexOf("bde4.cc") > 0) {
- videoData.url = videoData.url.replace("ftn_handler/", new Date().getTime() + ".mp4?rkey=").replace("bde4.cc", "weiyun.com");
- }
- return videoData.url;
- }
- function updatePlayLines(newUrl) {
- for (const playLine of playLines) {
- if (playLine.url.indexOf("/god/") > 0) {
- if ((newUrl.indexOf("/tos/") > 0 && playLine.url.indexOf("type") > 0) || (newUrl.indexOf("/tos/") < 0 && playLine.url.indexOf("type") < 0)) {
- playLine.url = newUrl;
- }
- }
- }
- }
- function getUrl(verifyCode, videoPlayer) {
- let videoUrl = null;
- const timestamp = new Date().getTime();
- const key = CryptoJS.enc.Utf8.parse(md5(pid + '-' + timestamp).substring(0, 16));
- const encryptedKey = CryptoJS.AES.encrypt(pid + '-' + timestamp, key, {
- 'mode': CryptoJS.mode.ECB,
- 'padding': CryptoJS.pad.Pkcs7
- });
- $.ajax("/god/" + pid + (verifyCode === 888 ? "?type=1" : ''), {
- 'method': "POST",
- 'dataType': "json",
- 'data': {
- 't': timestamp,
- 'sg': base64ToHex(encryptedKey + ''),
- 'verifyCode': verifyCode
- },
- 'success': function (response) {
- if (response.url != null) {
- if (verifyCode !== 888) {
- videoUrl = dealUrl(response);
- } else {
- videoUrl = response.url;
- }
- updatePlayLines(videoUrl);
- videoPlayer.video.src = response.url;
- } else {
- showError(response.error);
- }
- }
- });
- return videoUrl;
- }
- (function () {
- const getGlobalObject = function () {
- let globalObject;
- try {
- globalObject = Function("return (function() {}.constructor("return this")( ));")();
- } catch (error) {
- globalObject = window;
- }
- return globalObject;
- };
- const globalObject = getGlobalObject();
- globalObject.setInterval(checkDebugger, 4000);
- })();
- function switch2(videoIndex, videoUrl, videoPlayer) {
- if (videoUrl.indexOf("type") < 0) {
- if (time != null && new Date().getTime() - time < 86400000) {
- showError("距离发布未超过24小时不予开放!");
- return;
- }
- if (!window.member && IsPC()) {
- showError("暂不开放!");
- return;
- }
- }
- if (playLines.length > 1 && videoUrl.indexOf("type") < 0) {
- $("#aaa").attr("src", "/play/verifyCode?t=" + new Date().getTime());
- $("#myModal").modal("show");
- return;
- }
- getUrl(playLines.length == 1 && videoUrl.indexOf("type") < 0 ? 666 : 888, videoPlayer);
- }
复制代码 |