From 83b78bab34b4b0d26cd94acb4ba7ddb9658b8497 Mon Sep 17 00:00:00 2001 From: pan93412 Date: Tue, 28 Dec 2021 00:49:31 +0800 Subject: [PATCH] feat: allow customizing UNM's sources (#1134) * feat(ipcMain/unm): allow passing customized source * feat(utils/Player): pass settings.unmSource According to c280221a44608777a69038306a6ea8e92953fb9a, we can let users customize their desired source now. * feat(views/settings): allow configuring sources We haven't supported specifying the environment variable in YPM yet. --- src/electron/ipcMain.js | 18 +++++++- src/utils/Player.js | 6 ++- src/views/settings.vue | 96 +++++++++++++++++++++++++++++++---------- 3 files changed, 94 insertions(+), 26 deletions(-) diff --git a/src/electron/ipcMain.js b/src/electron/ipcMain.js index dc1fed6..64e5168 100644 --- a/src/electron/ipcMain.js +++ b/src/electron/ipcMain.js @@ -48,8 +48,18 @@ async function getBiliVideoFile(url) { return `data:application/octet-stream;base64,${encodedData}`; } +/** + * Parse the source string (`a, b`) to source list `['a', 'b']`. + * + * @param {string} sourceString The source string. + * @returns {string[]} The source list. + */ +function parseSourceStringToList(sourceString) { + return sourceString.split(',').map(s => s.trim()); +} + export function initIpcMain(win, store) { - ipcMain.handle('unblock-music', async (_, track) => { + ipcMain.handle('unblock-music', async (_, track, source) => { // 兼容 unblockneteasemusic 所使用的 api 字段 track.alias = track.alia || []; track.duration = track.dt || 0; @@ -62,11 +72,15 @@ export function initIpcMain(win, store) { }, 5000); }); + const sourceList = + typeof source === 'string' ? parseSourceStringToList(source) : null; + log(`[UNM] using source: ${sourceList || ''}`); + try { const matchedAudio = await Promise.race([ // TODO: tell users to install yt-dlp. // we passed "null" to source, to let UNM choose the default source. - match(track.id, null, track), + match(track.id, sourceList, track), timeoutPromise, ]); diff --git a/src/utils/Player.js b/src/utils/Player.js index c6b633e..8fab401 100644 --- a/src/utils/Player.js +++ b/src/utils/Player.js @@ -299,7 +299,11 @@ export default class { ) { return null; } - const source = await ipcRenderer.invoke('unblock-music', track); + const source = await ipcRenderer.invoke( + 'unblock-music', + track, + store.state.settings.unmSource + ); if (store.state.settings.automaticallyCacheSongs && source?.url) { // TODO: 将unblockMusic字样换成真正的来源(比如酷我咪咕等) cacheTrackSource(track, source.url, 128000, 'unblockMusic'); diff --git a/src/views/settings.vue b/src/views/settings.vue index 959b622..37da6a9 100644 --- a/src/views/settings.vue +++ b/src/views/settings.vue @@ -222,6 +222,58 @@ +
+

UnblockNeteaseMusic 设定

+
+
+ +
+
+
+ + +
+
+
+
+
+
备选音源
+
+ 音源的具体代号 + + 可以点此到 UNM 的说明页面查询
+ 多个音源请用 , 逗号分隔。
+ 留空则使用 UNM 内置的默认值。 +
+
+
+ + +
+
+
+

第三方

@@ -240,29 +292,6 @@
-
-
- -
-
-
- - -
-
-
@@ -852,6 +881,21 @@ export default { }); }, }, + unmSource: { + /** + * @returns {string} + */ + get() { + return this.settings.unmSource || ''; + }, + /** @param {string?} value */ + set(value) { + this.$store.commit('updateSettings', { + key: 'unmSource', + value: value.length ? value : null, + }); + }, + }, isLastfmConnected() { return this.lastfm.key !== undefined; }, @@ -1128,6 +1172,12 @@ h3 { font-weight: 500; opacity: 0.78; } + + .description { + font-size: 14px; + margin-top: 0.5em; + opacity: 0.7; + } } select {