-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added retry button for ManualLyricDialog
- Loading branch information
Showing
2 changed files
with
79 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,49 @@ | ||
|
||
import axios from 'axios'; | ||
import htmlToText from 'html-to-text'; | ||
import axios from "axios"; | ||
import htmlToText from "html-to-text"; | ||
import showError from "./showError"; | ||
const delim1 = '</div></div></div></div><div class="hwc"><div class="BNeawe tAd8D AP7Wnd"><div><div class="BNeawe tAd8D AP7Wnd">'; | ||
const delim2 = '</div></div></div></div></div><div><span class="hwc"><div class="BNeawe uEec3 AP7Wnd">'; | ||
const url = "https://www.google.com/search?q="; | ||
|
||
export default async function fetchLyrics(artists:string, title: string) { | ||
let lyrics; | ||
export default async function fetchLyrics(artists: string, title: string) { | ||
let lyrics; | ||
try { | ||
console.log("[lyric query]:", `${url}${encodeURIComponent(title + " " + artists)}+lyrics`); | ||
lyrics = (await axios.get<string>(`${url}${encodeURIComponent(title + " " + artists)}+lyrics`, { responseType: "text" })).data; | ||
[, lyrics] = lyrics.split(delim1); | ||
[lyrics] = lyrics.split(delim2); | ||
} catch (err) { | ||
showError(err, "[Lyric Query Error]: "); | ||
try { | ||
lyrics = (await axios.get<string>(`${url}${encodeURIComponent(title + " " + artists)}+lyrics`, {responseType: "text"})).data; | ||
console.log("[lyric query]:", `${url}${encodeURIComponent(title + " " + artists)}+song+lyrics`); | ||
lyrics = (await axios.get<string>(`${url}${encodeURIComponent(title + " " + artists)}+song+lyrics`)).data; | ||
[, lyrics] = lyrics.split(delim1); | ||
[lyrics] = lyrics.split(delim2); | ||
} catch (err_1) { | ||
showError(err_1, "[Lyric Query Error]: "); | ||
try { | ||
console.log("[lyric query]:", `${url}${encodeURIComponent(title + " " + artists)}+song`); | ||
lyrics = (await axios.get<string>(`${url}${encodeURIComponent(title + " " + artists)}+song`)).data; | ||
[, lyrics] = lyrics.split(delim1); | ||
[lyrics] = lyrics.split(delim2); | ||
} catch (m) { | ||
} catch (err_2) { | ||
showError(err_2, "[Lyric Query Error]: "); | ||
try { | ||
lyrics = (await axios.get<string>(`${url}${encodeURIComponent(title + " " + artists)}+song+lyrics`)).data; | ||
[, lyrics] = lyrics.split(delim1); | ||
[lyrics] = lyrics.split(delim2); | ||
} catch (n) { | ||
try { | ||
lyrics = (await axios.get<string>(`${url}${encodeURIComponent(title + " " + artists)}+song`)).data; | ||
[, lyrics] = lyrics.split(delim1); | ||
[lyrics] = lyrics.split(delim2); | ||
} catch (o) { | ||
try { | ||
lyrics = (await axios.get<string>(`${url}${encodeURIComponent(title + " " + artists)}`)).data; | ||
[, lyrics] = lyrics.split(delim1); | ||
[lyrics] = lyrics.split(delim2); | ||
} catch (p) { | ||
lyrics = 'Not Found'; | ||
} | ||
} | ||
console.log("[lyric query]:", `${url}${encodeURIComponent(title + " " + artists)}`); | ||
lyrics = (await axios.get<string>(`${url}${encodeURIComponent(title + " " + artists)}`)).data; | ||
[, lyrics] = lyrics.split(delim1); | ||
[lyrics] = lyrics.split(delim2); | ||
} catch (err_3) { | ||
showError(err_3, "[Lyric Query Error]: "); | ||
lyrics = "Not Found"; | ||
} | ||
} | ||
} | ||
const rets = lyrics.split('\n'); | ||
let final = ''; | ||
for (const ret of rets) { | ||
final = `${final}${htmlToText.htmlToText(ret)}\n`; | ||
} | ||
return final.trim(); | ||
} | ||
} | ||
const rets = lyrics.split("\n"); | ||
let final = ""; | ||
for (const ret of rets) { | ||
final = `${final}${htmlToText.htmlToText(ret)}\n`; | ||
} | ||
return final.trim(); | ||
} |