mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2024-11-22 09:56:41 +08:00
commit
5c2c8024b9
|
@ -10,6 +10,7 @@ import { CacheAPIs } from '@/shared/CacheAPIs'
|
||||||
import { FetchTracksResponse } from '@/shared/api/Track'
|
import { FetchTracksResponse } from '@/shared/api/Track'
|
||||||
import store from '@/desktop/main/store'
|
import store from '@/desktop/main/store'
|
||||||
import { db, Tables } from '@/desktop/main/db'
|
import { db, Tables } from '@/desktop/main/db'
|
||||||
|
const match = require('@unblockneteasemusic/server')
|
||||||
|
|
||||||
log.info('[electron] appServer/routes/r3play/audio.ts')
|
log.info('[electron] appServer/routes/r3play/audio.ts')
|
||||||
|
|
||||||
|
@ -143,15 +144,16 @@ async function audio(fastify: FastifyInstance) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const cache = await getAudioFromCache(id)
|
const localCache = await getAudioFromCache(id)
|
||||||
if (cache) {
|
if (localCache) {
|
||||||
return cache
|
return localCache
|
||||||
}
|
}
|
||||||
|
|
||||||
const { body: fromNetease }: { body: any } = await NeteaseCloudMusicApi.song_url_v1({
|
const { body: fromNetease }: { body: any } = await NeteaseCloudMusicApi.song_url_v1({
|
||||||
...req.query,
|
...req.query,
|
||||||
cookie: req.cookies as unknown as any,
|
cookie: req.cookies as unknown as any,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (
|
if (
|
||||||
fromNetease?.code === 200 &&
|
fromNetease?.code === 200 &&
|
||||||
!fromNetease?.data?.[0]?.freeTrialInfo &&
|
!fromNetease?.data?.[0]?.freeTrialInfo &&
|
||||||
|
@ -160,6 +162,40 @@ async function audio(fastify: FastifyInstance) {
|
||||||
reply.status(200).send(fromNetease)
|
reply.status(200).send(fromNetease)
|
||||||
return
|
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')) {
|
if (store.get('settings.enableFindTrackOnYouTube')) {
|
||||||
const fromYoutube = getAudioFromYouTube(id)
|
const fromYoutube = getAudioFromYouTube(id)
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
"@fastify/static": "^6.6.1",
|
"@fastify/static": "^6.6.1",
|
||||||
"@sentry/electron": "^3.0.7",
|
"@sentry/electron": "^3.0.7",
|
||||||
"NeteaseCloudMusicApi": "^4.8.9",
|
"NeteaseCloudMusicApi": "^4.8.9",
|
||||||
|
"@unblockneteasemusic/server": "^0.27.3",
|
||||||
"better-sqlite3": "8.3.0",
|
"better-sqlite3": "8.3.0",
|
||||||
"change-case": "^4.1.2",
|
"change-case": "^4.1.2",
|
||||||
"compare-versions": "^4.1.3",
|
"compare-versions": "^4.1.3",
|
||||||
|
|
|
@ -12,11 +12,17 @@ import {
|
||||||
FetchUserLikedTracksIDsResponse,
|
FetchUserLikedTracksIDsResponse,
|
||||||
FetchUserPlaylistsResponse,
|
FetchUserPlaylistsResponse,
|
||||||
} from './api/User'
|
} 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 { FetchPlaylistResponse, FetchRecommendedPlaylistsResponse } from './api/Playlists'
|
||||||
import { AppleMusicAlbum, AppleMusicArtist } from './AppleMusic'
|
import { AppleMusicAlbum, AppleMusicArtist } from './AppleMusic'
|
||||||
|
|
||||||
export enum CacheAPIs {
|
export enum CacheAPIs {
|
||||||
|
Unblock = 'unblock',
|
||||||
Album = 'album',
|
Album = 'album',
|
||||||
Artist = 'artists',
|
Artist = 'artists',
|
||||||
ArtistAlbum = 'artist/album',
|
ArtistAlbum = 'artist/album',
|
||||||
|
@ -41,6 +47,7 @@ export enum CacheAPIs {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CacheAPIsParams {
|
export interface CacheAPIsParams {
|
||||||
|
[CacheAPIs.Unblock]: { track_id: number }
|
||||||
[CacheAPIs.Album]: { id: number }
|
[CacheAPIs.Album]: { id: number }
|
||||||
[CacheAPIs.Artist]: { id: number }
|
[CacheAPIs.Artist]: { id: number }
|
||||||
[CacheAPIs.ArtistAlbum]: { id: number }
|
[CacheAPIs.ArtistAlbum]: { id: number }
|
||||||
|
@ -64,6 +71,7 @@ export interface CacheAPIsParams {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CacheAPIsResponse {
|
export interface CacheAPIsResponse {
|
||||||
|
[CacheAPIs.Unblock]: UnblockResponse
|
||||||
[CacheAPIs.Album]: FetchAlbumResponse
|
[CacheAPIs.Album]: FetchAlbumResponse
|
||||||
[CacheAPIs.Artist]: FetchArtistResponse
|
[CacheAPIs.Artist]: FetchArtistResponse
|
||||||
[CacheAPIs.ArtistAlbum]: FetchArtistAlbumsResponse
|
[CacheAPIs.ArtistAlbum]: FetchArtistAlbumsResponse
|
||||||
|
|
|
@ -4,6 +4,15 @@ export enum TrackApiNames {
|
||||||
FetchLyric = 'fetchLyric',
|
FetchLyric = 'fetchLyric',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unblock music
|
||||||
|
export interface UnblockParam {
|
||||||
|
track_id: number
|
||||||
|
}
|
||||||
|
export interface UnblockResponse {
|
||||||
|
code: number
|
||||||
|
url: string
|
||||||
|
}
|
||||||
|
|
||||||
// 获取歌曲详情
|
// 获取歌曲详情
|
||||||
export interface FetchTracksParams {
|
export interface FetchTracksParams {
|
||||||
ids: number[]
|
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