Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 32 lines (24 sloc) 985 Bytes
#!/usr/bin/env jruby
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
require 'rubygems'
gem 'spotify-api'
require 'clients/lastfm'
require 'clients/spotify'
# a demo app which grabs tracks from and creates a spotify
# playlist based on friends loved tracks
if __FILE__ == $0
username = ARGV.shift or raise "#{$0} <username>"
puts "fetching tracks (friends/recently_loved)"
limit = 10 # 10 tracks per friend
tracks = LastFM.friends_loved_tracks(username, limit).values.flatten
puts "resolving spotify ids"
spotify_tracks = begin
Spotify.resolve( {|t| [t["title"], t["artist"]] })
rescue Errno::ECONNREFUSED
fail "Could not connect to spotify-api server. Make sure it it running."
if spotify_tracks.size > 0
puts "creating playlist with #{spotify_tracks.size} tracks"
puts Spotify.create_playlist("loved by friends of #{username}", { |t| t['id'] })
You can’t perform that action at this time.