From 3264149137efd0effc0ee8760434ee6c5756a0d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=82=A6?= Date: Wed, 7 Jan 2026 18:15:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=AD=8C=E6=9B=B2=E5=85=83=E6=95=B0?= =?UTF-8?q?=E6=8D=AE):=20=E6=B7=BB=E5=8A=A0=E5=AF=B9Tunehub=E5=92=8C?= =?UTF-8?q?=E9=9F=B3=E4=B9=90=E5=B9=B3=E5=8F=B0URL=E7=9A=84=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增parseTunehubParams和parsePageUrlParams函数用于解析不同音乐平台的URL参数,并添加buildSongMetaFromTunehub函数构建歌曲元数据。当URL匹配时优先从Tunehub获取歌曲信息,否则回退到原有逻辑。 --- backend/src/handler/song_meta.js | 72 ++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/backend/src/handler/song_meta.js b/backend/src/handler/song_meta.js index 4b3f756..abc65fd 100644 --- a/backend/src/handler/song_meta.js +++ b/backend/src/handler/song_meta.js @@ -1,6 +1,62 @@ const logger = require('consola'); const { getMetaWithUrl } = require('../service/media_fetcher'); const { matchUrlFromStr } = require('../utils/regex'); +const { getSongInfo, buildSongUrl } = require('../service/music_platform/tunehub'); + +function parseTunehubParams(url) { + try { + const parsed = new URL(url); + if (!parsed.hostname.includes('music-dl.sayqz.com')) { + return null; + } + const source = parsed.searchParams.get('source'); + const id = parsed.searchParams.get('id'); + if (!source || !id) { + return null; + } + return { source, id }; + } catch (err) { + return null; + } +} + +function parsePageUrlParams(url) { + if (!url) { + return null; + } + if (url.indexOf('music.163.com') >= 0 || url.indexOf('m.music.163.com') >= 0) { + const match = url.match(/id=(\d+)/); + if (match && match[1]) { + return { source: 'netease', id: match[1] }; + } + } + if (url.indexOf('y.qq.com') >= 0) { + const match = url.match(/songDetail\/([A-Za-z0-9]+)/); + if (match && match[1]) { + return { source: 'qq', id: match[1] }; + } + } + return null; +} + +function buildSongMetaFromTunehub(source, info, pageUrl, songId) { + return { + songName: info.name || '', + artist: info.artist || '', + album: info.album || '', + duration: 0, + coverUrl: info.pic || '', + pageUrl, + audios: [ + { + url: info.url || buildSongUrl(source, songId), + } + ], + fromMusicPlatform: true, + resourceForbidden: false, + source, + }; +} async function getMeta(req, res) { const query = req.query; @@ -15,8 +71,18 @@ async function getMeta(req, res) { return; } - const songMeta = await getMetaWithUrl(url); - songMeta && (songMeta.pageUrl = url); + let songMeta = null; + const params = parseTunehubParams(url) || parsePageUrlParams(url); + if (params) { + const tunehubInfo = await getSongInfo(params.source, params.id); + if (tunehubInfo) { + songMeta = buildSongMetaFromTunehub(params.source, tunehubInfo, url, params.id); + } + } + if (!songMeta) { + songMeta = await getMetaWithUrl(url); + songMeta && (songMeta.pageUrl = url); + } res.send({ status: songMeta ? 0 : 1, @@ -28,4 +94,4 @@ async function getMeta(req, res) { module.exports = { getMeta: getMeta -} \ No newline at end of file +}