refactor!: 移除品牌字样,音源改为 sources/ 目录自动加载,脚本不入库
This commit is contained in:
1 parent
f548e5990b
commit
5dd0468860
34 files changed
+256
-232
No files matched your search
@@ -23,8 +23,8 @@ const sources: ApiSourceInfo[] = [
|
||||
// },
|
||||
// },
|
||||
{
|
||||
id: 'v5',
|
||||
name: 'lx-music-source-v5 聚合源',
|
||||
id: 'source',
|
||||
name: '外部聚合音源',
|
||||
disabled: false,
|
||||
supportQualitys: {
|
||||
kw: ['128k', '320k', 'flac'],
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// 接口选择层:按 apiSource 配置把请求路由到 v5 聚合源或服务器内置直连接口
|
||||
// 接口选择层:按 apiSource 配置把请求路由到外部聚合音源或服务器内置直连接口
|
||||
import apiSourceInfo from './api-source-info.ts'
|
||||
import { apiSource, userApi } from '../src/renderer/store.js'
|
||||
import internalApi from '../src/apis/index.js'
|
||||
import { createApi as createLxSourceApi } from '../src/apis/lx-source.js'
|
||||
import { createApi as createSourceApi } from '../src/apis/source.js'
|
||||
|
||||
interface SourceApi {
|
||||
getMusicUrl(songInfo: any, type: string): { promise: Promise<any>; cancelHttp(): void }
|
||||
@@ -10,11 +10,11 @@ interface SourceApi {
|
||||
}
|
||||
|
||||
const allApi: Record<string, SourceApi> = {
|
||||
v5_kw: createLxSourceApi('kw'),
|
||||
v5_kg: createLxSourceApi('kg'),
|
||||
v5_tx: createLxSourceApi('tx'),
|
||||
v5_wy: createLxSourceApi('wy'),
|
||||
v5_mg: createLxSourceApi('mg'),
|
||||
source_kw: createSourceApi('kw'),
|
||||
source_kg: createSourceApi('kg'),
|
||||
source_tx: createSourceApi('tx'),
|
||||
source_wy: createSourceApi('wy'),
|
||||
source_mg: createSourceApi('mg'),
|
||||
}
|
||||
|
||||
const apiList: Record<string, SourceApi | undefined> = {}
|
||||
|
||||
@@ -82,7 +82,7 @@ export default {
|
||||
lyric: Buffer.from(body.content, 'base64').toString('utf-8'),
|
||||
tlyric: '',
|
||||
rlyric: '',
|
||||
lxlyric: '',
|
||||
yrc: '',
|
||||
}
|
||||
default:
|
||||
return Promise.reject(new Error(`未知歌词格式: ${body.fmt}`))
|
||||
|
||||
@@ -224,10 +224,10 @@ export default {
|
||||
// return Promise.reject(new Error('Get lyric failed'))
|
||||
// }
|
||||
// if (lrcInfo.tlyric) lrcInfo.tlyric = lrcInfo.tlyric.replace(lrcTools.rxps.wordTimeAll, '')
|
||||
// lrcInfo.lxlyric = lrcTools.parse(lrcInfo.lyric)
|
||||
// lrcInfo.yrc = lrcTools.parse(lrcInfo.lyric)
|
||||
// // console.log(lrcInfo.lyric)
|
||||
// // console.log(lrcInfo.tlyric)
|
||||
// // console.log(lrcInfo.lxlyric)
|
||||
// // console.log(lrcInfo.yrc)
|
||||
// // console.log(JSON.stringify(lrcInfo))
|
||||
// })
|
||||
// })
|
||||
@@ -255,9 +255,9 @@ export default {
|
||||
// console.log(lrcInfo)
|
||||
if (lrcInfo.tlyric) lrcInfo.tlyric = lrcInfo.tlyric.replace(lrcTools.rxps.wordTimeAll, '')
|
||||
try {
|
||||
lrcInfo.lxlyric = lrcTools.parse(lrcInfo.lyric)
|
||||
lrcInfo.yrc = lrcTools.parse(lrcInfo.lyric)
|
||||
} catch {
|
||||
lrcInfo.lxlyric = ''
|
||||
lrcInfo.yrc = ''
|
||||
}
|
||||
lrcInfo.lyric = lrcInfo.lyric.replace(lrcTools.rxps.wordTimeAll, '')
|
||||
if (!existTimeExp.test(lrcInfo.lyric)) return Promise.reject(new Error('Get lyric failed'))
|
||||
|
||||
@@ -11,7 +11,7 @@ const mrcTools = {
|
||||
parseLyric(str) {
|
||||
str = str.replace(/\r/g, '')
|
||||
const lines = str.split('\n')
|
||||
const lxlrcLines: string[] = []
|
||||
const yrcLines: string[] = []
|
||||
const lrcLines: string[] = []
|
||||
|
||||
for (const line of lines) {
|
||||
@@ -40,11 +40,11 @@ const mrcTools = {
|
||||
})
|
||||
const wordArr = words.split(this.rxps.wordTime)
|
||||
const newWords = times.map((time, index) => `${time}${wordArr[index]}`).join('')
|
||||
lxlrcLines.push(`[${time}]${newWords}`)
|
||||
yrcLines.push(`[${time}]${newWords}`)
|
||||
}
|
||||
return {
|
||||
lyric: lrcLines.join('\n'),
|
||||
lxlyric: lxlrcLines.join('\n'),
|
||||
yrc: yrcLines.join('\n'),
|
||||
}
|
||||
},
|
||||
getText(url, tryNum = 0) {
|
||||
@@ -67,7 +67,7 @@ const mrcTools = {
|
||||
})
|
||||
},
|
||||
getLrc(url) {
|
||||
return this.getText(url).then(text => ({ lxlyric: '', lyric: text }))
|
||||
return this.getText(url).then(text => ({ yrc: '', lyric: text }))
|
||||
},
|
||||
getTrc(url) {
|
||||
if (!url) return Promise.resolve('')
|
||||
|
||||
@@ -72,7 +72,7 @@ const toBigintArray = (data: string): bigint[] => {
|
||||
return jArr
|
||||
}
|
||||
|
||||
// https://github.com/lyswhut/lx-music-desktop/issues/445#issuecomment-1139338682
|
||||
// 基于社区通用的 mrc 逐字歌词解析思路
|
||||
const MAX = 9223372036854775807n
|
||||
const MIN = -9223372036854775808n
|
||||
const toLong = (str: string | bigint): bigint => {
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
export const bHh = '624868746c'
|
||||
|
||||
export const headers: Record<string, string | string[]> = {
|
||||
'User-Agent': 'lx-music request',
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
|
||||
[bHh]: [bHh],
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -30,10 +30,10 @@ const parseTools = {
|
||||
parseLyric(lrc) {
|
||||
lrc = lrc.trim()
|
||||
lrc = lrc.replace(/\r/g, '')
|
||||
if (!lrc) return { lyric: '', lxlyric: '' }
|
||||
if (!lrc) return { lyric: '', yrc: '' }
|
||||
const lines = lrc.split('\n')
|
||||
|
||||
const lxlrcLines: string[] = []
|
||||
const yrcLines: string[] = []
|
||||
const lrcLines: string[] = []
|
||||
|
||||
for (let line of lines) {
|
||||
@@ -41,11 +41,11 @@ const parseTools = {
|
||||
let result = this.rxps.lineTime.exec(line)
|
||||
if (!result) {
|
||||
if (line.startsWith('[offset')) {
|
||||
lxlrcLines.push(line)
|
||||
yrcLines.push(line)
|
||||
lrcLines.push(line)
|
||||
}
|
||||
if (this.rxps.lineTime2.test(line)) {
|
||||
// lxlrcLines.push(line)
|
||||
// yrcLines.push(line)
|
||||
lrcLines.push(line)
|
||||
}
|
||||
continue
|
||||
@@ -67,17 +67,17 @@ const parseTools = {
|
||||
})
|
||||
const wordArr = words.split(this.rxps.wordTime)
|
||||
const newWords = times.map((time, index) => `${time}${wordArr[index]}`).join('')
|
||||
lxlrcLines.push(`${startTimeStr}${newWords}`)
|
||||
yrcLines.push(`${startTimeStr}${newWords}`)
|
||||
}
|
||||
return {
|
||||
lyric: lrcLines.join('\n'),
|
||||
lxlyric: lxlrcLines.join('\n'),
|
||||
yrc: yrcLines.join('\n'),
|
||||
}
|
||||
},
|
||||
parseRlyric(lrc) {
|
||||
lrc = lrc.trim()
|
||||
lrc = lrc.replace(/\r/g, '')
|
||||
if (!lrc) return { lyric: '', lxlyric: '' }
|
||||
if (!lrc) return { lyric: '', yrc: '' }
|
||||
const lines = lrc.split('\n')
|
||||
|
||||
const lrcLines: string[] = []
|
||||
@@ -177,14 +177,14 @@ const parseTools = {
|
||||
lyric: '',
|
||||
tlyric: '',
|
||||
rlyric: '',
|
||||
lxlyric: '',
|
||||
yrc: '',
|
||||
}
|
||||
if (lrc) {
|
||||
let { lyric, lxlyric } = this.parseLyric(this.removeTag(lrc))
|
||||
let { lyric, yrc } = this.parseLyric(this.removeTag(lrc))
|
||||
info.lyric = lyric
|
||||
info.lxlyric = lxlyric
|
||||
info.yrc = yrc
|
||||
// console.log(lyric)
|
||||
// console.log(lxlyric)
|
||||
// console.log(yrc)
|
||||
}
|
||||
if (rlrc) info.rlyric = this.fixRlrcTimeTag(this.parseRlyric(this.removeTag(rlrc)), info.lyric)
|
||||
if (tlrc) info.tlyric = this.fixTlrcTimeTag(tlrc, info.lyric)
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ export interface LyricInfo {
|
||||
lyric: string
|
||||
tlyric: string
|
||||
rlyric?: string
|
||||
lxlyric?: string
|
||||
yrc?: string
|
||||
}
|
||||
|
||||
/** 搜索结果 */
|
||||
|
||||
+11
-11
@@ -8,7 +8,7 @@ import type { LyricInfo, HttpRequestObject } from '../types.ts'
|
||||
|
||||
// str = str.replace(/\r/g, '')
|
||||
|
||||
// let lxlyric = str.replace(/\[((\d+),\d+)\].*/g, str => {
|
||||
// let yrc = str.replace(/\[((\d+),\d+)\].*/g, str => {
|
||||
// let result = str.match(/\[((\d+),\d+)\].*/)
|
||||
// let time = parseInt(result[2])
|
||||
// let ms = time % 1000
|
||||
@@ -31,8 +31,8 @@ import type { LyricInfo, HttpRequestObject } from '../types.ts'
|
||||
// return str
|
||||
// })
|
||||
|
||||
// lxlyric = decodeName(lxlyric)
|
||||
// return lxlyric.trim()
|
||||
// yrc = decodeName(yrc)
|
||||
// return yrc.trim()
|
||||
// }
|
||||
|
||||
const eapiRequest = (url: string, data: object) => {
|
||||
@@ -72,7 +72,7 @@ const parseTools = {
|
||||
return `[${m}:${s}.${ms}]`
|
||||
},
|
||||
parseLyric(lines) {
|
||||
const lxlrcLines: string[] = []
|
||||
const yrcLines: string[] = []
|
||||
const lrcLines: string[] = []
|
||||
|
||||
for (let line of lines) {
|
||||
@@ -80,7 +80,7 @@ const parseTools = {
|
||||
let result = this.rxps.lineTime.exec(line)
|
||||
if (!result) {
|
||||
if (line.startsWith('[offset')) {
|
||||
lxlrcLines.push(line)
|
||||
yrcLines.push(line)
|
||||
lrcLines.push(line)
|
||||
}
|
||||
continue
|
||||
@@ -103,11 +103,11 @@ const parseTools = {
|
||||
const wordArr = words.split(this.rxps.wordTime)
|
||||
wordArr.shift()
|
||||
const newWords = times.map((time, index) => `${time}${wordArr[index]}`).join('')
|
||||
lxlrcLines.push(`${startTimeStr}${newWords}`)
|
||||
yrcLines.push(`${startTimeStr}${newWords}`)
|
||||
}
|
||||
return {
|
||||
lyric: lrcLines.join('\n'),
|
||||
lxlyric: lxlrcLines.join('\n'),
|
||||
yrc: yrcLines.join('\n'),
|
||||
}
|
||||
},
|
||||
parseHeaderInfo(str) {
|
||||
@@ -170,7 +170,7 @@ const parseTools = {
|
||||
lyric: '',
|
||||
tlyric: '',
|
||||
rlyric: '',
|
||||
lxlyric: '',
|
||||
yrc: '',
|
||||
}
|
||||
if (ylrc) {
|
||||
let lines = this.parseHeaderInfo(ylrc)
|
||||
@@ -196,7 +196,7 @@ const parseTools = {
|
||||
const timeRxp = /^\[[\d:.]+\]/
|
||||
const headers = lines.filter(l => timeRxp.test(l)).join('\n')
|
||||
info.lyric = `${headers}\n${result.lyric}`
|
||||
info.lxlyric = result.lxlyric
|
||||
info.yrc = result.yrc
|
||||
return info
|
||||
}
|
||||
}
|
||||
@@ -242,13 +242,13 @@ const parseTools = {
|
||||
// lyric: body.lrc.lyric,
|
||||
// tlyric: body.tlyric?.lyric ?? '',
|
||||
// rlyric: body.romalrc?.lyric ?? '',
|
||||
// // lxlyric: parseLyric(body.klyric.lyric),
|
||||
// // yrc: parseLyric(body.klyric.lyric),
|
||||
// }
|
||||
// })
|
||||
// return requestObj
|
||||
// }
|
||||
|
||||
// https://github.com/lyswhut/lx-music-mobile/issues/370
|
||||
// 参考社区通用的歌词时间标签修正思路
|
||||
const fixTimeLabel = (lrc: string, tlrc?: string, romalrc?: string) => {
|
||||
if (lrc) {
|
||||
let newLrc = lrc.replace(/\[(\d{2}:\d{2}):(\d{2})]/g, '[$1.$2]')
|
||||
|
||||
Reference in new issue
Block a user