mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-05-18 11:37:31 +08:00
feat: 优化音源逻辑
This commit is contained in:
+45
-43
@@ -146,54 +146,56 @@ const getUnblockMusicAudio = (id: number, data: SongResult, sources: any[]) => {
|
|||||||
* @returns 解析结果
|
* @returns 解析结果
|
||||||
*/
|
*/
|
||||||
export const getParsingMusicUrl = async (id: number, data: SongResult) => {
|
export const getParsingMusicUrl = async (id: number, data: SongResult) => {
|
||||||
const settingStore = useSettingsStore();
|
if(isElectron){
|
||||||
|
const settingStore = useSettingsStore();
|
||||||
|
|
||||||
// 如果禁用了音乐解析功能,则直接返回空结果
|
// 如果禁用了音乐解析功能,则直接返回空结果
|
||||||
if (!settingStore.setData.enableMusicUnblock) {
|
if (!settingStore.setData.enableMusicUnblock) {
|
||||||
return Promise.resolve({ data: { code: 404, message: '音乐解析功能已禁用' } });
|
return Promise.resolve({ data: { code: 404, message: '音乐解析功能已禁用' } });
|
||||||
}
|
|
||||||
|
|
||||||
// 1. 确定使用的音源列表(自定义或全局)
|
|
||||||
const songId = String(id);
|
|
||||||
const savedSourceStr = localStorage.getItem(`song_source_${songId}`);
|
|
||||||
let musicSources: any[] = [];
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (savedSourceStr) {
|
|
||||||
// 使用自定义音源
|
|
||||||
musicSources = JSON.parse(savedSourceStr);
|
|
||||||
console.log(`使用歌曲 ${id} 自定义音源:`, musicSources);
|
|
||||||
} else {
|
|
||||||
// 使用全局音源设置
|
|
||||||
musicSources = settingStore.setData.enabledMusicSources || [];
|
|
||||||
console.log(`使用全局音源设置:`, musicSources);
|
|
||||||
if (isElectron && musicSources.length > 0) {
|
|
||||||
return getUnblockMusicAudio(id, data, musicSources);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
console.error('解析音源设置失败,使用全局设置', e);
|
|
||||||
musicSources = settingStore.setData.enabledMusicSources || [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 按优先级解析
|
// 1. 确定使用的音源列表(自定义或全局)
|
||||||
|
const songId = String(id);
|
||||||
|
const savedSourceStr = localStorage.getItem(`song_source_${songId}`);
|
||||||
|
let musicSources: any[] = [];
|
||||||
|
|
||||||
// 2.1 Bilibili解析(优先级最高)
|
try {
|
||||||
if (musicSources.includes('bilibili')) {
|
if (savedSourceStr) {
|
||||||
return await getBilibiliAudio(data);
|
// 使用自定义音源
|
||||||
}
|
musicSources = JSON.parse(savedSourceStr);
|
||||||
|
console.log(`使用歌曲 ${id} 自定义音源:`, musicSources);
|
||||||
|
} else {
|
||||||
|
// 使用全局音源设置
|
||||||
|
musicSources = settingStore.setData.enabledMusicSources || [];
|
||||||
|
console.log(`使用全局音源设置:`, musicSources);
|
||||||
|
if (musicSources.length > 0) {
|
||||||
|
return getUnblockMusicAudio(id, data, musicSources);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('解析音源设置失败,使用全局设置', e);
|
||||||
|
musicSources = settingStore.setData.enabledMusicSources || [];
|
||||||
|
}
|
||||||
|
|
||||||
// 2.2 GD音乐台解析
|
// 2. 按优先级解析
|
||||||
if (musicSources.includes('gdmusic')) {
|
|
||||||
const gdResult = await getGDMusicAudio(id, data);
|
// 2.1 Bilibili解析(优先级最高)
|
||||||
if (gdResult) return gdResult;
|
if (musicSources.includes('bilibili')) {
|
||||||
// GD解析失败,继续下一步
|
return await getBilibiliAudio(data);
|
||||||
console.log('GD音乐台解析失败,尝试使用其他音源');
|
}
|
||||||
}
|
|
||||||
console.log('musicSources', musicSources);
|
// 2.2 GD音乐台解析
|
||||||
// 2.3 使用unblockMusic解析其他音源
|
if (musicSources.includes('gdmusic')) {
|
||||||
if (isElectron && musicSources.length > 0) {
|
const gdResult = await getGDMusicAudio(id, data);
|
||||||
return getUnblockMusicAudio(id, data, musicSources);
|
if (gdResult) return gdResult;
|
||||||
|
// GD解析失败,继续下一步
|
||||||
|
console.log('GD音乐台解析失败,尝试使用其他音源');
|
||||||
|
}
|
||||||
|
console.log('musicSources', musicSources);
|
||||||
|
// 2.3 使用unblockMusic解析其他音源
|
||||||
|
if (musicSources.length > 0) {
|
||||||
|
return getUnblockMusicAudio(id, data, musicSources);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 后备方案:使用API请求
|
// 3. 后备方案:使用API请求
|
||||||
|
|||||||
Reference in New Issue
Block a user