diff --git a/package.json b/package.json index ebe112c..2e5afbd 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ }, "main": "background.js", "dependencies": { + "@nondanee/unblockneteasemusic": "^0.25.3", "axios": "^0.21.0", "big-integer": "^1.6.48", "core-js": "^3.6.5", diff --git a/src/electron/ipcMain.js b/src/electron/ipcMain.js index 0a9dbc4..24877ef 100644 --- a/src/electron/ipcMain.js +++ b/src/electron/ipcMain.js @@ -1,4 +1,5 @@ import { app, ipcMain } from "electron"; +import match from "@nondanee/unblockneteasemusic"; export function initIpcMain(win) { // Make vuex copy for electron. @@ -8,6 +9,12 @@ export function initIpcMain(win) { global.vuexCopy = state; }); + ipcMain.on("unblock-music", (event, id) => { + match(id, ["qq", "kuwo", "migu"]).then((res) => { + event.returnValue = res; + }); + }); + ipcMain.on("close", () => { win.close(); app.quit(); diff --git a/src/store/actions.js b/src/store/actions.js index 8749de2..0ee1b07 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -6,6 +6,9 @@ import localforage from "localforage"; import store from "@/store"; import { cacheTrack } from "@/utils/db"; +const electron = window.require("electron"); +const ipcRenderer = electron.ipcRenderer; + export default { switchTrack({ state, dispatch, commit }, basicTrack) { getTrackDetail(basicTrack.id).then((data) => { @@ -36,7 +39,12 @@ export default { document.title = `${track.name} · ${track.ar[0].name} - YesPlayMusic`; if (track.playable === false) { - dispatch("nextTrack"); + const res = ipcRenderer.sendSync("unblock-music", track.id); + if (res?.url) { + commitMP3(res.url); + } else { + dispatch("nextTrack"); + } return; } diff --git a/vue.config.js b/vue.config.js index 278d93d..1f5b623 100644 --- a/vue.config.js +++ b/vue.config.js @@ -49,6 +49,7 @@ module.exports = { pluginOptions: { // electron-builder的配置文件 electronBuilder: { + externals: ["@nondanee/unblockneteasemusic"], builderOptions: { productName: "YesPlayMusic", copyright: "Copyright © YesPlayMusic", diff --git a/yarn.lock b/yarn.lock index 3e24172..8da41d4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1270,6 +1270,11 @@ resolved "https://registry.npm.taobao.org/@nodelib/fs.stat/download/@nodelib/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b" integrity sha1-K1o6s/kYzKSKjHVMCBaOPwPrphs= +"@nondanee/unblockneteasemusic@^0.25.3": + version "0.25.3" + resolved "https://registry.yarnpkg.com/@nondanee/unblockneteasemusic/-/unblockneteasemusic-0.25.3.tgz#72d936f18f46523a2b929b8eaec8dfd2acf25e7e" + integrity sha512-Fgl0iRvuFCNhyFlovbqqnJQRomaFVjMLosS1hRUd/X47y6HeNlQsxa9c8RtmeLwNnZ27rj0DsUZlECqU7FyNPA== + "@npmcli/move-file@^1.0.1": version "1.0.1" resolved "https://registry.npm.taobao.org/@npmcli/move-file/download/@npmcli/move-file-1.0.1.tgz#de103070dac0f48ce49cf6693c23af59c0f70464"