1
1
// Import Packages
2
2
const NeteaseMusic = require ( 'simple-netease-cloud-music' )
3
+ const cache = require ( '../cache' )
3
4
const nm = new NeteaseMusic ( )
4
5
5
6
const controllers = { }
@@ -17,7 +18,13 @@ controllers.summary = async (ctx, next) => {
17
18
data [ _ . id ] . url = 'https://api.a632079.me/nm/redirect/music/' + _ . id
18
19
19
20
// Get Music Detail
20
- const detail = await nm . song ( _ . id . toString ( ) )
21
+ let detail
22
+ if ( await cache . get ( 'nm:detail:' + _ . id ) ) {
23
+ detail = await cache . get ( 'nm:detail:' + _ . id )
24
+ } else {
25
+ detail = await nm . song ( _ . id . toString ( ) )
26
+ cache . set ( 'nm:detail:' + _ . id , detail , 60 * 60 * 2 ) // Cache 2 Hour
27
+ }
21
28
data [ _ . id ] . name = detail . songs [ 0 ] . name
22
29
data [ _ . id ] . artists = [ ]
23
30
for ( let artist of detail . songs [ 0 ] . ar ) {
@@ -26,11 +33,26 @@ controllers.summary = async (ctx, next) => {
26
33
data [ _ . id ] . album = { }
27
34
data [ _ . id ] . album . id = detail . songs [ 0 ] . al . id
28
35
data [ _ . id ] . album . name = detail . songs [ 0 ] . al . name
29
- data [ _ . id ] . album . picture = ( await nm . picture ( ( await nm . album ( detail . songs [ 0 ] . al . id . toString ( ) ) ) . songs [ 0 ] . al . pic_str ) ) . url
36
+
37
+ let album
38
+ if ( await cache . get ( 'nm:album:' + detail . songs [ 0 ] . al . id ) ) {
39
+ album = await cache . get ( 'nm:album:' + detail . songs [ 0 ] . al . id )
40
+ } else {
41
+ album = await nm . album ( detail . songs [ 0 ] . al . id . toString ( ) )
42
+ cache . set ( 'nm:album:' + detail . songs [ 0 ] . al . id , album , 60 * 60 * 4 ) // Cache 4 Hour
43
+ }
44
+ data [ _ . id ] . album . picture = ( await nm . picture ( album . songs [ 0 ] . al . pic_str ) ) . url
30
45
31
46
// Get Lyric
32
47
if ( ctx . query && ctx . query . lyric ) {
33
- const lyric = await nm . lyric ( _ . id . toString ( ) )
48
+ let lyric
49
+ if ( await cache . get ( 'nm:lyric:' + _ . id ) ) {
50
+ lyric = await cache . get ( 'nm:lyric:' + _ . id )
51
+ } else {
52
+ lyric = await nm . lyric ( _ . id . toString ( ) )
53
+ cache . set ( 'nm:lyric:' + _ . id , lyric , 60 * 60 * 4 ) // Cache 4 Hour
54
+ }
55
+
34
56
data [ _ . id ] . lyric = { }
35
57
data [ _ . id ] . lyric . base = ( lyric . lrc && lyric . lrc . lyric ) ? lyric . lrc . lyric : '[00:00.00] 纯音乐,敬请聆听。'
36
58
data [ _ . id ] . lyric . translate = ( lyric . tlyric && lyric . tlyric . lyric ) ? lyric . tlyric . lyric : null
0 commit comments