|
@@ -3,9 +3,7 @@ import {
|
3
3
|
createTRPCRouter,
|
4
4
|
publicProcedure,
|
5
5
|
} from "~/server/api/trpc";
|
6
|
-
import { type GeniusSongReference, type GeniusHit } from "~/schema";
|
6
|
+
import { type GeniusSongReference, type GeniusHit } from "~/schema";
|
7
|
-
import {parse} from "node-html-parser";
|
8
|
-
|
9
7
|
const geniusBaseUrl = "https://api.genius.com";
|
10
8
|
const ovhApiUrl = "https://api.lyrics.ovh";
|
11
9
|
|
|
@@ -90,11 +88,19 @@ export const geniusRouter = createTRPCRouter({
|
90
88
|
let lyrics = "";
|
91
89
|
|
92
90
|
if(lyrics === "" && data?.response?.song?.primary_artist?.name && data?.response?.song?.title) {
|
91
|
+
// console.log("artist: ", data?.response?.song?.primary_artist?.name);
|
92
|
+
// console.log("title: ", data?.response?.song?.title);
|
93
|
+
try{
|
93
|
-
const url = `${ovhApiUrl}/v1/${data?.response?.song.primary_artist.name}/${data?.response?.song.title}`;
|
94
|
+
const url = `${ovhApiUrl}/v1/${data?.response?.song.primary_artist.name}/${data?.response?.song.title}`;
|
94
|
-
const response = await fetch(url);
|
95
|
+
const response = await fetch(url);
|
95
|
-
const res = await response.json() as { lyrics: string };
|
96
|
+
const res = await response.json() as { lyrics: string };
|
97
|
+
// console.log(res);
|
96
|
-
lyrics = res.lyrics ?? "Lyrics not found";
|
98
|
+
lyrics = res.lyrics ?? "Lyrics not found";
|
97
|
-
lyrics = (res.lyrics || "").replaceAll("\n\n", "\n").replaceAll("\\", "").replaceAll("\"","");
|
99
|
+
lyrics = (res.lyrics || "").replaceAll("\n\n", "\n").replaceAll("\\", "").replaceAll("\"","");
|
100
|
+
} catch (err) {
|
101
|
+
console.log(err);
|
102
|
+
lyrics = "Lyrics not found";
|
103
|
+
}
|
98
104
|
} else {
|
99
105
|
lyrics = "Lyrics not found";
|
100
106
|
}
|