1
1
const spotify = require ( 'spotify-node-applescript' )
2
- let base_api_url = "http://colorflyv1.herokuapp.com/v1/color/"
3
- const genius = require ( 'genius- lyrics-api' )
2
+ let color_base_url = "http://colorflyv1.herokuapp.com/v1/color/"
3
+ let lyrics_base_url = "http://colorflyv1.herokuapp.com/v1/ lyrics/"
4
4
5
5
const getColor = ( api_url ) => {
6
6
const xhr = new XMLHttpRequest ( )
@@ -17,25 +17,32 @@ const getColor = (api_url) =>{
17
17
xhr . send ( )
18
18
}
19
19
20
+ const getLyrics = ( api_url , opt ) => {
21
+ const xhr = new XMLHttpRequest ( )
22
+ xhr . open ( 'POST' , api_url , true )
23
+ xhr . setRequestHeader ( "Content-Type" , "application/json; charset=UTF-8" ) ;
24
+ xhr . onload = ( ) => {
25
+ const data = JSON . parse ( xhr . response )
26
+ document . getElementById ( 'lyrics' ) . textContent = data [ 'lyrics' ]
27
+ }
28
+ xhr . send ( JSON . stringify ( opt ) )
29
+ }
30
+
20
31
const renderPage = ( ) => {
21
32
spotify . getTrack ( ( err , track ) => {
22
33
let temp_track = track [ 'name' ]
23
34
24
35
if ( temp_track !== track_name ) {
25
36
let track_name = track [ 'name' ]
26
37
let image_url = track [ 'artwork_url' ]
27
- let api_url = base_api_url + image_url
38
+ let api_url = color_base_url + image_url
28
39
let artist_name = track [ 'artist' ]
29
- getColor ( api_url )
30
40
const options = {
31
- apiKey : '--insert api key here--' ,
32
- title : track [ 'name' ] ,
33
41
artist : track [ 'artist' ] ,
34
- optimizeQuery : true
42
+ song : track [ 'name' ]
35
43
}
36
- genius . getLyrics ( options ) . then ( ( lyrics ) => {
37
- document . getElementById ( 'lyrics' ) . textContent = lyrics
38
- } )
44
+ getColor ( api_url )
45
+ getLyrics ( lyrics_base_url , options )
39
46
document . getElementById ( 'cover_art' ) . src = image_url
40
47
document . getElementById ( 'track_name' ) . textContent = track_name
41
48
document . getElementById ( 'artist_name' ) . textContent = artist_name
0 commit comments