Skip to content

Commit

Permalink
feat: add supports for netease music driver (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuycy authored May 9, 2024
1 parent 787ab3e commit fa41f68
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/lang/en/drivers.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down Expand Up @@ -923,6 +928,7 @@
"WebDav": "WebDav",
"WeiYun": "WeiYun",
"WoPan": "WoPan",
"YandexDisk": "YandexDisk"
"YandexDisk": "YandexDisk",
"NeteaseMusic": "NeteaseMusic"
}
}
32 changes: 28 additions & 4 deletions src/pages/home/previews/audio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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({
Expand All @@ -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)
Expand Down

0 comments on commit fa41f68

Please sign in to comment.