mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2024-11-22 03:21:19 +08:00
commit
5c2c8024b9
|
@ -10,6 +10,7 @@ import { CacheAPIs } from '@/shared/CacheAPIs'
|
|||
import { FetchTracksResponse } from '@/shared/api/Track'
|
||||
import store from '@/desktop/main/store'
|
||||
import { db, Tables } from '@/desktop/main/db'
|
||||
const match = require('@unblockneteasemusic/server')
|
||||
|
||||
log.info('[electron] appServer/routes/r3play/audio.ts')
|
||||
|
||||
|
@ -143,15 +144,16 @@ async function audio(fastify: FastifyInstance) {
|
|||
})
|
||||
}
|
||||
|
||||
const cache = await getAudioFromCache(id)
|
||||
if (cache) {
|
||||
return cache
|
||||
const localCache = await getAudioFromCache(id)
|
||||
if (localCache) {
|
||||
return localCache
|
||||
}
|
||||
|
||||
const { body: fromNetease }: { body: any } = await NeteaseCloudMusicApi.song_url_v1({
|
||||
...req.query,
|
||||
cookie: req.cookies as unknown as any,
|
||||
})
|
||||
|
||||
if (
|
||||
fromNetease?.code === 200 &&
|
||||
!fromNetease?.data?.[0]?.freeTrialInfo &&
|
||||
|
@ -160,6 +162,40 @@ async function audio(fastify: FastifyInstance) {
|
|||
reply.status(200).send(fromNetease)
|
||||
return
|
||||
}
|
||||
const trackID = id
|
||||
// 先查缓存
|
||||
const cacheData = await cache.get(CacheAPIs.Unblock, trackID)
|
||||
if (cacheData) {
|
||||
return cacheData
|
||||
}
|
||||
if (!trackID) {
|
||||
reply.code(400).send({
|
||||
code: 400,
|
||||
msg: 'id is required or id is invalid',
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// todo: 暂时写死的,是否开放给用户配置
|
||||
await match(trackID, ['qq', 'kuwo', 'migu', 'kugou', 'joox']).then((data: unknown) => {
|
||||
if (data === null || data === undefined || (data as any)?.url === '') {
|
||||
reply.code(500).send({
|
||||
code: 400,
|
||||
msg: 'no track info',
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
cache.set(CacheAPIs.Unblock, { id: trackID, url: (data as any)?.url }, trackID)
|
||||
reply.code(200).send({
|
||||
code: 200,
|
||||
data: [data],
|
||||
})
|
||||
})
|
||||
} catch (err) {
|
||||
reply.code(500).send(err)
|
||||
}
|
||||
|
||||
if (store.get('settings.enableFindTrackOnYouTube')) {
|
||||
const fromYoutube = getAudioFromYouTube(id)
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
"@fastify/static": "^6.6.1",
|
||||
"@sentry/electron": "^3.0.7",
|
||||
"NeteaseCloudMusicApi": "^4.8.9",
|
||||
"@unblockneteasemusic/server": "^0.27.3",
|
||||
"better-sqlite3": "8.3.0",
|
||||
"change-case": "^4.1.2",
|
||||
"compare-versions": "^4.1.3",
|
||||
|
|
|
@ -12,11 +12,17 @@ import {
|
|||
FetchUserLikedTracksIDsResponse,
|
||||
FetchUserPlaylistsResponse,
|
||||
} from './api/User'
|
||||
import { FetchAudioSourceResponse, FetchLyricResponse, FetchTracksResponse } from './api/Track'
|
||||
import {
|
||||
FetchAudioSourceResponse,
|
||||
FetchLyricResponse,
|
||||
FetchTracksResponse,
|
||||
UnblockResponse,
|
||||
} from './api/Track'
|
||||
import { FetchPlaylistResponse, FetchRecommendedPlaylistsResponse } from './api/Playlists'
|
||||
import { AppleMusicAlbum, AppleMusicArtist } from './AppleMusic'
|
||||
|
||||
export enum CacheAPIs {
|
||||
Unblock = 'unblock',
|
||||
Album = 'album',
|
||||
Artist = 'artists',
|
||||
ArtistAlbum = 'artist/album',
|
||||
|
@ -41,6 +47,7 @@ export enum CacheAPIs {
|
|||
}
|
||||
|
||||
export interface CacheAPIsParams {
|
||||
[CacheAPIs.Unblock]: { track_id: number }
|
||||
[CacheAPIs.Album]: { id: number }
|
||||
[CacheAPIs.Artist]: { id: number }
|
||||
[CacheAPIs.ArtistAlbum]: { id: number }
|
||||
|
@ -64,6 +71,7 @@ export interface CacheAPIsParams {
|
|||
}
|
||||
|
||||
export interface CacheAPIsResponse {
|
||||
[CacheAPIs.Unblock]: UnblockResponse
|
||||
[CacheAPIs.Album]: FetchAlbumResponse
|
||||
[CacheAPIs.Artist]: FetchArtistResponse
|
||||
[CacheAPIs.ArtistAlbum]: FetchArtistAlbumsResponse
|
||||
|
|
|
@ -4,6 +4,15 @@ export enum TrackApiNames {
|
|||
FetchLyric = 'fetchLyric',
|
||||
}
|
||||
|
||||
// unblock music
|
||||
export interface UnblockParam {
|
||||
track_id: number
|
||||
}
|
||||
export interface UnblockResponse {
|
||||
code: number
|
||||
url: string
|
||||
}
|
||||
|
||||
// 获取歌曲详情
|
||||
export interface FetchTracksParams {
|
||||
ids: number[]
|
||||
|
|
11040
pnpm-lock.yaml
11040
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user