mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2026-10-20 14:41:23 +08:00
refactor(unblock): Refactor song URL matching to use new utils package (#73)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
gemini-code-assist[bot]
parent
30bd839809
commit
598dd8bd34
+31
-41
@@ -1,13 +1,14 @@
|
||||
// 歌曲链接 - v1
|
||||
// 此版本不再采用 br 作为音质区分的标准
|
||||
// 而是采用 standard, exhigh, lossless, hires, jyeffect(高清环绕声), sky(沉浸环绕声), jymaster(超清母带) 进行音质判断
|
||||
// 当unblock为true时, 会尝试使用unblockneteasemusic进行解锁, 同时音质设置不会生效, 但仍然为必须传入参数
|
||||
// 当unblock为true时, 会尝试使用unblockmusic-utils进行解锁, 同时音质设置不会生效, 但仍然为必须传入参数
|
||||
|
||||
const logger = require('../util/logger.js')
|
||||
const createOption = require('../util/option.js')
|
||||
module.exports = async (query, request) => {
|
||||
const match = require('@unblockneteasemusic/server')
|
||||
const source = ['pyncmd', 'bodian', 'kuwo', 'qq', 'migu', 'kugou']
|
||||
const {
|
||||
matchID,
|
||||
} = require('@neteasecloudmusicapienhanced/unblockmusic-utils')
|
||||
require('dotenv').config()
|
||||
const data = {
|
||||
ids: '[' + query.id + ']',
|
||||
@@ -16,48 +17,37 @@ module.exports = async (query, request) => {
|
||||
}
|
||||
if (query.unblock === 'true') {
|
||||
try {
|
||||
const result = await match(query.id, source)
|
||||
const result = await matchID(query.id, query.source)
|
||||
logger.info('Starting unblock(uses modules unblock):', query.id, result)
|
||||
// avoid optional chaining for compatibility
|
||||
let url
|
||||
if (Array.isArray(result)) {
|
||||
url = result[0] && result[0].url ? result[0].url : result[0]
|
||||
} else {
|
||||
url = result && result.url ? result.url : result
|
||||
}
|
||||
// decide proxyUrl after we resolved the actual url value
|
||||
const useProxy = process.env.ENABLE_PROXY || 'false'
|
||||
let proxyUrl = ''
|
||||
if (url) {
|
||||
if (url.includes('kuwo')) {
|
||||
const useProxy = process.env.ENABLE_PROXY || 'false'
|
||||
if (useProxy === 'true' && process.env.PROXY_URL) {
|
||||
proxyUrl = process.env.PROXY_URL + url
|
||||
} else {
|
||||
proxyUrl = url
|
||||
}
|
||||
}
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
code: 200,
|
||||
msg: 'Warning: you can only adjust unblock source in dotenv config, use /song/url/match instead.',
|
||||
data: [
|
||||
{
|
||||
id: Number(query.id),
|
||||
url,
|
||||
type: 'flac',
|
||||
level: query.level,
|
||||
freeTrialInfo: 'null',
|
||||
fee: 0,
|
||||
proxyUrl: proxyUrl || '',
|
||||
},
|
||||
],
|
||||
},
|
||||
cookie: [],
|
||||
}
|
||||
if (result.data.url && result.data.url.includes('kuwo')) {
|
||||
proxyUrl =
|
||||
useProxy === 'true' && process.env.PROXY_URL
|
||||
? process.env.PROXY_URL + result.data.url
|
||||
: result.data.url
|
||||
}
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
code: 200,
|
||||
msg: 'Warning: Customizing unblock sources is not supported on this endpoint. Please use `/song/url/match` instead.',
|
||||
data: [
|
||||
{
|
||||
id: Number(query.id),
|
||||
url: result.data.url,
|
||||
type: 'flac',
|
||||
level: query.level,
|
||||
freeTrialInfo: 'null',
|
||||
fee: 0,
|
||||
proxyUrl: proxyUrl || '',
|
||||
},
|
||||
],
|
||||
},
|
||||
cookie: [],
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error in unblockneteasemusic:', e)
|
||||
console.error('Error in unblocking music:', e)
|
||||
}
|
||||
}
|
||||
if (data.level == 'sky') {
|
||||
|
||||
Reference in New Issue
Block a user