File tree Expand file tree Collapse file tree 1 file changed +30
-32
lines changed
Expand file tree Collapse file tree 1 file changed +30
-32
lines changed Original file line number Diff line number Diff line change @@ -16,37 +16,35 @@ module.exports = async (win) => {
1616 metadata . title
1717 ) } `;
1818
19- let response = await fetch (
20- `https://genius.com/api/search/multi?per_page=5&q=${ encodeURI (
21- queryString
22- ) } `
23- ) ;
24- if ( ! response . ok ) {
25- event . returnValue = null ;
26- return ;
27- }
28-
29- const info = await response . json ( ) ;
30- let url = "" ;
31- try {
32- url = info . response . sections . filter (
33- ( section ) => section . type === "song"
34- ) [ 0 ] . hits [ 0 ] . result . url ;
35- } catch {
36- event . returnValue = null ;
37- return ;
38- }
39-
40- if ( is . dev ( ) ) {
41- console . log ( "Fetching lyrics from Genius:" , url ) ;
42- }
43-
44- response = await fetch ( url ) ;
45- if ( ! response . ok ) {
46- event . returnValue = null ;
47- return ;
48- }
49-
50- event . returnValue = await response . text ( ) ;
19+ event . returnValue = await fetchFromGenius ( queryString ) ;
5120 } ) ;
5221} ;
22+
23+ const fetchFromGenius = async ( queryString ) => {
24+ let response = await fetch (
25+ `https://genius.com/api/search/multi?per_page=5&q=${ encodeURI ( queryString ) } `
26+ ) ;
27+ if ( ! response . ok ) {
28+ return null ;
29+ }
30+
31+ const info = await response . json ( ) ;
32+ let url = "" ;
33+ try {
34+ url = info . response . sections . filter ( ( section ) => section . type === "song" ) [ 0 ]
35+ . hits [ 0 ] . result . url ;
36+ } catch {
37+ return null ;
38+ }
39+
40+ if ( is . dev ( ) ) {
41+ console . log ( "Fetching lyrics from Genius:" , url ) ;
42+ }
43+
44+ response = await fetch ( url ) ;
45+ if ( ! response . ok ) {
46+ return null ;
47+ }
48+
49+ return await response . text ( ) ;
50+ } ;
You can’t perform that action at this time.
0 commit comments