mirror of
https://github.com/develop202/migu_video.git
synced 2025-12-23 10:15:26 +08:00
添加本地部署
This commit is contained in:
@@ -2,6 +2,7 @@ import axios from "axios";
|
||||
import { getStringMD5 } from "./EncryUtils.js";
|
||||
import { getddCalcuURL, getddCalcuURL720p, getEncryptURL } from "./ddCalcuURL.js";
|
||||
import { changedDdCalcu } from "./datas.js";
|
||||
import { printYellow } from "./colorOut.js";
|
||||
|
||||
function getSaltAndSign(md5) {
|
||||
|
||||
@@ -57,12 +58,11 @@ function replaceChars(url, pid, rateType) {
|
||||
}
|
||||
|
||||
// 替换
|
||||
let suffixSplit = suffix.split("")
|
||||
for (let i = 0; i < index.length; i++) {
|
||||
suffixSplit[index[i] - 1] = defaultChange[i]
|
||||
suffix[index[i] - 1] = defaultChange[i]
|
||||
}
|
||||
|
||||
return `${prefix}&ddCalcu=${suffixSplit.join("")}`
|
||||
return `${prefix}&ddCalcu=${suffix}`
|
||||
}
|
||||
|
||||
async function getAndroidVideoURL(userId, token, exports, pid, rateType) {
|
||||
@@ -138,6 +138,7 @@ async function getAndroidVideoURL(userId, token, exports, pid, rateType) {
|
||||
* @returns {} - url: 链接 rateType: 清晰度
|
||||
*/
|
||||
async function getAndroidURL(userId, token, pid, rateType) {
|
||||
|
||||
if (rateType <= 1) {
|
||||
return {
|
||||
url: "",
|
||||
@@ -152,7 +153,13 @@ async function getAndroidURL(userId, token, pid, rateType) {
|
||||
TerminalId: "android",
|
||||
"X-UP-CLIENT-CHANNEL-ID": "2600037000-99000-200300220100002"
|
||||
}
|
||||
if (rateType != 2) {
|
||||
|
||||
// 广东卫视有些特殊
|
||||
if (pid == "608831231") {
|
||||
rateType = 2
|
||||
}
|
||||
|
||||
if (rateType != 2 && userId != "" && token != "") {
|
||||
headers.UserId = userId
|
||||
headers.UserToken = token
|
||||
}
|
||||
@@ -163,12 +170,23 @@ async function getAndroidURL(userId, token, pid, rateType) {
|
||||
|
||||
// 请求
|
||||
const baseURL = "https://play.miguvideo.com/playurl/v1/play/playurl"
|
||||
const params = "?sign=" + result.sign + "&rateType=" + rateType
|
||||
let params = "?sign=" + result.sign + "&rateType=" + rateType
|
||||
+ "&contId=" + pid + "×tamp=" + timestramp + "&salt=" + result.salt
|
||||
const respData = await axios.get(baseURL + params, {
|
||||
let respData = await axios.get(baseURL + params, {
|
||||
headers: headers
|
||||
}).then(r => r.data)
|
||||
|
||||
if (respData.rid == 'TIPS_NEED_MEMBER') {
|
||||
printYellow("该账号没有会员 正在降低画质")
|
||||
|
||||
params = "?sign=" + result.sign + "&rateType=" + (rateType - 1)
|
||||
+ "&contId=" + pid + "×tamp=" + timestramp + "&salt=" + result.salt
|
||||
respData = await axios.get(baseURL + params, {
|
||||
headers: headers
|
||||
}).then(r => r.data)
|
||||
}
|
||||
|
||||
// console.dir(respData, { depth: null })
|
||||
// console.log(respData)
|
||||
const url = respData.body.urlInfo?.url
|
||||
// console.log(rateType)
|
||||
@@ -180,11 +198,12 @@ async function getAndroidURL(userId, token, pid, rateType) {
|
||||
}
|
||||
}
|
||||
|
||||
rateType = respData.body.urlInfo?.rateType
|
||||
|
||||
// 将URL加密
|
||||
const resURL = getddCalcuURL(url, pid, "android", rateType)
|
||||
|
||||
rateType = respData.body.urlInfo?.rateType
|
||||
// console.log("清晰度" + rateType)
|
||||
|
||||
return {
|
||||
url: resURL,
|
||||
rateType: parseInt(rateType)
|
||||
@@ -239,12 +258,14 @@ async function getAndroidURL720p(pid) {
|
||||
}
|
||||
}
|
||||
|
||||
rateType = respData.body.urlInfo?.rateType
|
||||
|
||||
// 将URL加密
|
||||
const resURL = getddCalcuURL720p(url, pid)
|
||||
|
||||
return {
|
||||
url: resURL,
|
||||
rateType: 3
|
||||
rateType: parseInt(rateType)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
28
utils/colorOut.js
Normal file
28
utils/colorOut.js
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
function printRed(msg) {
|
||||
console.log('\x1B[31m%s\x1B[0m', msg)
|
||||
}
|
||||
|
||||
function printGreen(msg) {
|
||||
console.log('\x1B[32m%s\x1B[0m', msg)
|
||||
}
|
||||
|
||||
function printYellow(msg) {
|
||||
console.log('\x1B[33m%s\x1B[0m', msg)
|
||||
}
|
||||
|
||||
function printBlue(msg) {
|
||||
console.log('\x1B[34m%s\x1B[0m', msg)
|
||||
}
|
||||
|
||||
function printMagenta(msg) {
|
||||
console.log('\x1B[35m%s\x1B[0m', msg)
|
||||
}
|
||||
|
||||
function printGrey(msg) {
|
||||
console.log('\x1B[2m%s\x1B[0m', msg)
|
||||
}
|
||||
|
||||
export {
|
||||
printGreen, printBlue, printRed, printYellow, printMagenta, printGrey
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { userId } from "../config.js"
|
||||
import { getDateString } from "./time.js"
|
||||
|
||||
const list = {
|
||||
@@ -6,7 +7,7 @@ const list = {
|
||||
// 第11位字符
|
||||
"keys": "yzwxcdabgh",
|
||||
// 第5 8 14位字母对应下标0 1 3的字符
|
||||
"words": ['z', 'y', '0', 'w'],
|
||||
"words": ['', 'y', '0', 'w'],
|
||||
// 第11位字符替换位置,从0开始
|
||||
"thirdReplaceIndex": 1,
|
||||
// 加密后链接后缀
|
||||
@@ -14,7 +15,7 @@ const list = {
|
||||
},
|
||||
"android": {
|
||||
"keys": "cdabyzwxkl",
|
||||
"words": ['x', 'a', '0', 'a'],
|
||||
"words": ['v', 'a', '0', 'a'],
|
||||
"thirdReplaceIndex": 6,
|
||||
"suffix": "&sv=10004&ct=android"
|
||||
}
|
||||
@@ -97,9 +98,14 @@ function getEncryptURL(exports, videoURL) {
|
||||
/**
|
||||
* h5端现已失效
|
||||
* 获取ddCalcu
|
||||
* 大致思路:把puData最后一个字符和第一个字符拼接,然后拼接倒数第二个跟第二个,一直循环,当第1 2 3 4次(从0开始)循环时需要插入特殊标识字符
|
||||
* 特殊字符:四个特殊字符位置是第5 8 11 14,第5 8 14是根据平台确定的,且各个节目都一样。第11位在h5上是根据节目ID第1位(从0开始,android是第6位)数字为下标的某字符串的值
|
||||
* 在android,标清画质还有区分,第5位字符需要修改,其他不变
|
||||
* 大致思路:把puData最后一个字符和第一个字符拼接,然后拼接倒数第二个跟第二个,一直循环,
|
||||
* 当第1 2 3 4次(从0开始)循环时需要插入特殊标识字符
|
||||
* 特殊字符:
|
||||
* 都是根据一些数字字符串的某一位的值对应某数组的值确定的,形如数组[数字字符串[第几位]],具体根据第几位每个版本都不一样
|
||||
* 第1次是根据userid确定的,未登录时为固定字母
|
||||
* 第2位是根据时间戳确定(需要yyyyMMddhhmmss格式)
|
||||
* 第3根据节目id
|
||||
* 第4是根据平台确定的
|
||||
* @param {string} puData - 服务器返回的那个东东
|
||||
* @param {string} programId - 节目ID
|
||||
* @param {string} clientType - 平台类型 h5 android
|
||||
@@ -123,6 +129,16 @@ function getddCalcu(puData, programId, clientType, rateType) {
|
||||
if (rateType == null || rateType == undefined) {
|
||||
return ""
|
||||
}
|
||||
|
||||
// words第1位是根据userId的第7位(从0开始)数字对应keys里的字母生成的
|
||||
// 不登录标清是默认v
|
||||
const id = userId ? userId : process.env.USERID
|
||||
if (id) {
|
||||
const words1 = list.android.keys[id[7]]
|
||||
list.android.words[0] = words1
|
||||
list.h5.words[0] = words1
|
||||
}
|
||||
|
||||
let keys = list[clientType].keys
|
||||
let words = list[clientType].words
|
||||
const thirdReplaceIndex = list[clientType].thirdReplaceIndex
|
||||
@@ -130,10 +146,7 @@ function getddCalcu(puData, programId, clientType, rateType) {
|
||||
if (clientType == "android" && rateType == "2") {
|
||||
words[0] = "v"
|
||||
}
|
||||
puData = puData.split("");
|
||||
keys = keys.split("")
|
||||
const puDataLength = puData.length
|
||||
programId = programId.split("")
|
||||
let ddCalcu = []
|
||||
for (let i = 0; i < puDataLength / 2; i++) {
|
||||
|
||||
@@ -144,7 +157,7 @@ function getddCalcu(puData, programId, clientType, rateType) {
|
||||
ddCalcu.push(words[i - 1])
|
||||
break;
|
||||
case 2:
|
||||
ddCalcu.push(words[i - 1])
|
||||
ddCalcu.push(keys[parseInt(getDateString(new Date())[0])])
|
||||
break;
|
||||
case 3:
|
||||
ddCalcu.push(keys[programId[thirdReplaceIndex]])
|
||||
@@ -207,31 +220,26 @@ function getddCalcu720p(puData, programId) {
|
||||
return ""
|
||||
}
|
||||
|
||||
const words = ["e", "2", "", "0"]
|
||||
const thirdReplaceIndex = 2
|
||||
const keys = "0123456789"
|
||||
|
||||
puData = puData.split("");
|
||||
const keys = "0123456789".split("")
|
||||
const puDataLength = puData.length
|
||||
|
||||
programId = programId.split("")
|
||||
let ddCalcu = []
|
||||
for (let i = 0; i < puDataLength / 2; i++) {
|
||||
for (let i = 0; i < puData.length / 2; i++) {
|
||||
|
||||
ddCalcu.push(puData[puDataLength - i - 1])
|
||||
ddCalcu.push(puData[puData.length - i - 1])
|
||||
ddCalcu.push(puData[i])
|
||||
switch (i) {
|
||||
case 1:
|
||||
ddCalcu.push(words[i - 1])
|
||||
// ddCalcu.push(token=="" ?"e":keys[] )
|
||||
ddCalcu.push("e")
|
||||
break;
|
||||
case 2:
|
||||
ddCalcu.push(keys[parseInt(getDateString(new Date())[6])])
|
||||
break;
|
||||
case 3:
|
||||
ddCalcu.push(keys[programId[thirdReplaceIndex]])
|
||||
ddCalcu.push(keys[programId[2]])
|
||||
break;
|
||||
case 4:
|
||||
ddCalcu.push(words[i - 1])
|
||||
ddCalcu.push("0")
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import fs from "fs"
|
||||
import fs from "node:fs"
|
||||
function createFile(filePath) {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
writeFile(filePath, "")
|
||||
@@ -29,4 +29,16 @@ function appendFileSync(filePath, content) {
|
||||
})
|
||||
}
|
||||
|
||||
export { createFile, writeFile, appendFile, appendFileSync }
|
||||
function readFileSync(filePath) {
|
||||
return fs.readFileSync(filePath)
|
||||
}
|
||||
|
||||
function renameFileSync(oldFilePath, newFilePath) {
|
||||
fs.renameSync(oldFilePath, newFilePath, err => {
|
||||
if (err) {
|
||||
throw new Error(`文件重命名失败${oldFilePath} -> ${newFilePath}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export { createFile, writeFile, appendFile, appendFileSync, readFileSync, renameFileSync }
|
||||
|
||||
@@ -11,4 +11,9 @@ function getDateTimeString(date) {
|
||||
return `${getDateString(date)}${getTimeString(date)}`
|
||||
}
|
||||
|
||||
export { getDateString, getTimeString, getDateTimeString }
|
||||
function getDateTimeStr(date) {
|
||||
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")} ` +
|
||||
`${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}:${String(date.getSeconds()).padStart(2, "0")}`
|
||||
}
|
||||
|
||||
export { getDateString, getTimeString, getDateTimeString, getDateTimeStr }
|
||||
|
||||
Reference in New Issue
Block a user