added /api/musickit/ for musickit passthrough
This commit is contained in:
parent
5857b280d4
commit
f23753d910
3 changed files with 115 additions and 43 deletions
26
src/ciderkit/public.js
Normal file
26
src/ciderkit/public.js
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
const CiderKit = {
|
||||||
|
v1: {
|
||||||
|
musickit: {
|
||||||
|
async mkv3(route, body, options) {
|
||||||
|
let opts = {
|
||||||
|
method: 'POST',
|
||||||
|
cache: 'no-cache',
|
||||||
|
credentials: 'same-origin',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
redirect: 'follow',
|
||||||
|
referrerPolicy: 'no-referrer',
|
||||||
|
body: {}
|
||||||
|
}
|
||||||
|
opts.body = JSON.stringify({
|
||||||
|
route: route,
|
||||||
|
body: body,
|
||||||
|
options: options
|
||||||
|
})
|
||||||
|
let response = await fetch("http://localhost:9000/api/musickit/v3", opts);
|
||||||
|
return response.json()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ import {Plugins} from "./plugins";
|
||||||
import { watch } from "chokidar";
|
import { watch } from "chokidar";
|
||||||
import * as os from "os";
|
import * as os from "os";
|
||||||
const wallpaper = require('wallpaper');
|
const wallpaper = require('wallpaper');
|
||||||
|
const bodyParser = require('body-parser');
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import * as AdmZip from "adm-zip";
|
import * as AdmZip from "adm-zip";
|
||||||
|
@ -405,7 +406,14 @@ export class BrowserWindow {
|
||||||
private startWebServer(): void {
|
private startWebServer(): void {
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
app.use(function (req, res, next) {
|
||||||
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
|
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||||
|
next();
|
||||||
|
});
|
||||||
app.use(express.static(join(utils.getPath('srcPath'), "./renderer/")));
|
app.use(express.static(join(utils.getPath('srcPath'), "./renderer/")));
|
||||||
|
app.use(bodyParser.urlencoded({ extended: true }))
|
||||||
|
app.use(bodyParser.json())
|
||||||
app.set("views", join(utils.getPath('srcPath'), "./renderer/views"));
|
app.set("views", join(utils.getPath('srcPath'), "./renderer/views"));
|
||||||
app.set("view engine", "ejs");
|
app.set("view engine", "ejs");
|
||||||
let firstRequest = true;
|
let firstRequest = true;
|
||||||
|
@ -425,6 +433,35 @@ export class BrowserWindow {
|
||||||
res.render("main", this.EnvironmentVariables);
|
res.render("main", this.EnvironmentVariables);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get("/api/ciderkit.js", (req, res) =>{
|
||||||
|
res.sendFile(join(utils.getPath('srcPath'), "./ciderkit/public.js"));
|
||||||
|
})
|
||||||
|
|
||||||
|
app.post("/api/musickit/:action", async (req, res) => {
|
||||||
|
const action = req.params.action
|
||||||
|
switch (action) {
|
||||||
|
case "v3":
|
||||||
|
try {
|
||||||
|
const encoded = btoa(JSON.stringify(req.body))
|
||||||
|
console.log(encoded)
|
||||||
|
|
||||||
|
const result = await BrowserWindow.win.webContents.executeJavaScript(`
|
||||||
|
wsapi.v3("${encoded}")
|
||||||
|
`)
|
||||||
|
res.header("Content-Type", "application/json");
|
||||||
|
res.send(result)
|
||||||
|
break;
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
res.send("error")
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
res.send("null")
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
app.get("/api/playback/:action", (req, res) => {
|
app.get("/api/playback/:action", (req, res) => {
|
||||||
const action = req.params.action;
|
const action = req.params.action;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
@ -615,7 +652,8 @@ export class BrowserWindow {
|
||||||
details.requestHeaders['Accept-Language'] = 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
details.requestHeaders['Accept-Language'] = 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
||||||
details.requestHeaders['Referer'] = 'https://y.qq.com/',
|
details.requestHeaders['Referer'] = 'https://y.qq.com/',
|
||||||
details.requestHeaders['User-Agent'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X; zh-CN) AppleWebKit/537.51.1 ('
|
details.requestHeaders['User-Agent'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X; zh-CN) AppleWebKit/537.51.1 ('
|
||||||
'KHTML, like Gecko) Mobile/17D50 UCBrowser/12.8.2.1268 Mobile AliApp(TUnionSDK/0.1.20.3) '}
|
'KHTML, like Gecko) Mobile/17D50 UCBrowser/12.8.2.1268 Mobile AliApp(TUnionSDK/0.1.20.3) '
|
||||||
|
}
|
||||||
if (details.url.includes("https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg")) {
|
if (details.url.includes("https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg")) {
|
||||||
details.requestHeaders['Accept'] = '*/*',
|
details.requestHeaders['Accept'] = '*/*',
|
||||||
details.requestHeaders['Accept-Encoding'] = 'gzip, deflate, br',
|
details.requestHeaders['Accept-Encoding'] = 'gzip, deflate, br',
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
const wsapi = {
|
const wsapi = {
|
||||||
cache: {playParams: {id: 0}, status: null, remainingTime: 0},
|
cache: {playParams: {id: 0}, status: null, remainingTime: 0},
|
||||||
playbackCache: {status: null, time: Date.now()},
|
playbackCache: {status: null, time: Date.now()},
|
||||||
|
async v3(encoded = "") {
|
||||||
|
let decoded = atob(encoded);
|
||||||
|
let json = JSON.parse(decoded);
|
||||||
|
console.log(json)
|
||||||
|
let response = await (await MusicKit.getInstance().api.v3.music(json.route, json.body, json.options))
|
||||||
|
let ret = response.data
|
||||||
|
return JSON.stringify(ret)
|
||||||
|
},
|
||||||
search(term, limit) {
|
search(term, limit) {
|
||||||
MusicKit.getInstance().api.search(term, {limit: limit, types: 'songs,artists,albums,playlists'}).then((results)=>{
|
MusicKit.getInstance().api.search(term, {limit: limit, types: 'songs,artists,albums,playlists'}).then((results)=>{
|
||||||
ipcRenderer.send('wsapi-returnSearch', JSON.stringify(results))
|
ipcRenderer.send('wsapi-returnSearch', JSON.stringify(results))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue