Created
January 14, 2012 08:54
-
-
Save ashbb/1610747 to your computer and use it in GitHub Desktop.
Search an artist on spotify musicservice. Original code was written by Peter.
This file contains hidden or 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
| ['green_shoes','meta-spotify'].each(&method(:require)) | |
| Shoes.app do | |
| def artist_lookup artist | |
| @slot.clear do | |
| @e.text = artist.name | |
| uri = artist.uri | |
| songs = Array.new | |
| chosen_artist = MetaSpotify::Artist.lookup(uri, :extras => 'albumdetail') | |
| q, r = chosen_artist.albums.length.divmod 10 | |
| q.times do |i| | |
| para link("#{i*10+1} - #{i*10+10}"){album_lookup uri, chosen_artist, i*10} if q > 0 | |
| end | |
| para link("#{q*10+1} - #{q*10+r}"){album_lookup uri, chosen_artist, q*10} if r > 0 | |
| end | |
| end | |
| def album_lookup uri, chosen_artist, n | |
| @slot.clear do | |
| songs = Array.new | |
| chosen_artist.albums[n, 10].each do |album| | |
| album = MetaSpotify::Album.lookup(album.uri, :extras => "track") | |
| tracks = album.tracks.to_a | |
| tracks.each do |track| | |
| track.artists.each do |artist| | |
| if chosen_artist.uri==uri | |
| songs << [album.name.gsub(/&/,' and '), track.name.gsub(/&/,' and ')] | |
| end | |
| end | |
| end | |
| end | |
| songs.uniq! | |
| songs.sort! if songs | |
| songs.each do |aname, song| | |
| para link(song){alert aname} | |
| end | |
| end | |
| end | |
| @e = edit_line | |
| button("Search") do | |
| @artists = MetaSpotify::Artist.search(@e.text) | |
| @slot.clear do | |
| if @artists[:artists].length > 0 | |
| @artists[:artists].each do |artist| | |
| para link("#{artist.name.gsub('&', ' and ')}"){artist_lookup artist} | |
| end | |
| else | |
| para "No Artists found for the search term." | |
| end | |
| end | |
| flush | |
| end | |
| button('Exit'){exit} | |
| @slot = stack{} | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment