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 {