Back to Parent

#Get a random sample of a Spotify playlist depending on mood input 
def search_track trackname 

  auth = ""
  File.open("spotify-auth.txt", "r") do |file|
    file.each { |line| auth += line }
  end
  user_hash = JSON.parse( auth )
  

  RSpotify.authenticate(ENV["SPOTIFY_CLIENT_ID"], ENV["SPOTIFY_CLIENT_SECRET"])
  #spotify_user = RSpotify::User.new(@@spotify_auth)
  puts user_hash
  spotify_user = RSpotify::User.new( user_hash )
    
  
  # Access private data
  puts spotify_user.country #=> "US"
  puts spotify_user.email   #=> "example@email.com"

  playlist = spotify_user.create_playlist!('mood-music') # automatically refreshes token
 
  puts playlist

  tracks = RSpotify::Track.search(trackname.to_s) 
  playlist.add_tracks!(tracks)
  playlist.tracks.first.name #=> "Somebody That I Used To Know"

  #First song in playlist 
  tracks.first
end
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0