Merge pull request #2140 from Sherlockouo/unblock

feat: UNM supported
This commit is contained in:
Sherlockouo 2023-09-28 01:10:59 +08:00 committed by GitHub
commit 5c2c8024b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 6573 additions and 4529 deletions

View File

@ -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)

View File

@ -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",

View File

@ -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

View File

@ -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[]

File diff suppressed because it is too large Load Diff