diff --git a/src/lang/en/drivers.json b/src/lang/en/drivers.json index b2938d18a9..0f46d3df8d 100755 --- a/src/lang/en/drivers.json +++ b/src/lang/en/drivers.json @@ -801,6 +801,11 @@ "refresh_token": "Refresh token", "root_folder_path": "Root folder path" }, + "NeteaseMusic": { + "cookie": "Cookie", + "song_limit": "Max number of songs when getting list", + "song_limit-tips": "Only get 200 songs by default" + }, "config": { "115 Cloud": {}, "115 Share": {}, @@ -923,6 +928,7 @@ "WebDav": "WebDav", "WeiYun": "WeiYun", "WoPan": "WoPan", - "YandexDisk": "YandexDisk" + "YandexDisk": "YandexDisk", + "NeteaseMusic": "NeteaseMusic" } } diff --git a/src/pages/home/previews/audio.tsx b/src/pages/home/previews/audio.tsx index 7ae9d8d1d3..5e0dcf4f8d 100644 --- a/src/pages/home/previews/audio.tsx +++ b/src/pages/home/previews/audio.tsx @@ -6,10 +6,10 @@ import { onCleanup, onMount } from "solid-js" import { useLink, useRouter } from "~/hooks" import { getSetting, getSettingBool, objStore } from "~/store" import { ObjType, StoreObj } from "~/types" -import { baseName } from "~/utils" +import { baseName, fsGet } from "~/utils" const Preview = () => { - const { proxyLink, rawLink } = useLink() + const { proxyLink, rawLink, previewPage } = useLink() const { searchParams } = useRouter() let audios = objStore.objs.filter((obj) => obj.type === ObjType.AUDIO) if (audios.length === 0 || searchParams["from"] === "search") { @@ -24,15 +24,24 @@ const Preview = () => { if (lrcObj) { lrc = proxyLink(lrcObj, true) } - return { + const audio = { name: obj.name, artist: "Unknown", url: rawLink(obj, true), cover: + obj.thumb || getSetting("audio_cover") || "https://jsd.nn.ci/gh/alist-org/logo@main/logo.svg", lrc: lrc, } + if (objStore.provider === "NeteaseMusic") { + const matched = obj.name.match(/((.+)\s-\s)?(.+)\.(mp3|flac)/) + audio.artist = matched?.[2] || "Unknown" + audio.name = matched?.[3] || obj.name + const lrcURL = new URL(previewPage(obj).replace(/\.(mp3|flac)/, ".lrc")) + audio.lrc = decodeURIComponent(lrcURL.pathname) + } + return audio } onMount(() => { ap = new APlayer({ @@ -45,9 +54,24 @@ const Preview = () => { volume: 0.7, mutex: true, listFolded: false, - lrcType: 3, + lrcType: objStore.provider === "NeteaseMusic" ? 1 : 3, audio: audios.map(objToAudio), }) + if (objStore.provider === "NeteaseMusic") { + ap.on("loadstart", () => { + const i = ap.list.index + if (!ap.list.audios[i].lrc) return + const lrcURL = ap.list.audios[i].lrc + fsGet(lrcURL).then((resp) => { + ap.lrc.async = true + ap.lrc.parsed[i] = undefined + ap.list.audios[i].lrc = resp.data.raw_url + ap.lrc.switch(i) // fetch lrc into `parsed` + ap.list.audios[i].lrc = "" + ap.lrc.async = false + }) + }) + } const curIndex = audios.findIndex((obj) => obj.name === objStore.obj.name) if (curIndex !== -1) { ap.list.switch(curIndex)