AXCWG 3 сар өмнө
parent
commit
45ae7a185a
1 өөрчлөгдсөн 23 нэмэгдсэн , 4 устгасан
  1. 23 4
      main.js

+ 23 - 4
main.js

@@ -222,14 +222,33 @@ function SubmitWrapper(req, res) {
 }
 
 app.post('/lyric', async (req, res) => {
-    let name = req.body.name;
+    let name = req.body.name
     let artist = req.body.artist;
-    let id = (await (await fetch(ncmAPIUrl + `/cloudsearch?keywords=${name}%20${artist}`)).json()).result.songs[0].id
+    let album = req.body.albumName;
+    let id = "";
+    for (const result of (await (await fetch(ncmAPIUrl + `/cloudsearch?keywords=${name}%20${artist}%20${album}`)).json()).result.songs) {
+        if(result.name === await convertert2s.convertPromise(name) ){
+            id = result.id
+            console.log(id)
+            break;
+        }
+
+    }
     let lyric = await (await fetch(ncmAPIUrl + `/lyric?id=${id}`)).json()
     let ifTrans = false;
-    if (lyric.tlyric.lyric !== '') {
-        ifTrans = true;
+    console.log(lyric)
+    try{
+        if (lyric.tlyric.lyric !== '') {
+            ifTrans = true;
+        }
+    }catch(err){
+        console.log(err);
+        res.header("Access-Control-Allow-Origin", "*");
+
+        res.end("{}")
+        return
     }
+
     let response = {
         ifTrans: ifTrans,
         lyric: lyric.lrc.lyric,