AXCWG 3 months ago
parent
commit
9f2e2a5b4a
1 changed files with 12 additions and 3 deletions
  1. 12 3
      main.js

+ 12 - 3
main.js

@@ -29,6 +29,7 @@ const nrc = require('node-run-cmd')
 const https = require("node:https");
 const {OpenCC} = require("opencc");
 const {HttpsProxyAgent} = require("https-proxy-agent");
+const fetch = require("node-fetch");
 const converters2t = new OpenCC('s2t.json')
 const convertert2s = new OpenCC('t2s.json')
 app.use(bodyParser.json({"limit": "200mb"}));
@@ -229,10 +230,18 @@ app.post('/lyric', async (req, res) => {
     let name = req.body.name
     let artist = req.body.artist;
     let album = req.body.albumName;
+    let lrc = "";
+    await fetchThatShit()
+    async function fetchThatShit() {
+        try {
+            lrc = await (await fetch(`https://api.lrc.cx/api/v1/lyrics/single?title=${name}&album=${album}&artist=${artist}`, {
+                agent: new HttpsProxyAgent("http://localhost:7890")
+            })).text()
+        } catch (err) {
+            await fetchThatShit()
+        }
+    }
 
-    let lrc = await (await fetch(`https://api.lrc.cx/api/v1/lyrics/single?title=${name}&album=${album}&artist=${artist}`, {
-        agent: new HttpsProxyAgent("http://localhost:7890")
-    })).text()
 
     res.header("Access-Control-Allow-Origin", "*");
     res.end(lrc)