class SpotifyToMp3::Spotify

Public Instance Methods

album_uri?(uri) click to toggle source
# File lib/spotify_to_mp3/spotify.rb, line 29
def album_uri?(uri)
  uri.start_with?('http://open.spotify.com/album/', 'spotify:album:')
end
get_album(uri) click to toggle source
# File lib/spotify_to_mp3/spotify.rb, line 13
def get_album(uri)
  album_id = parse_id(uri)
  album = RSpotify::Album.find(album_id)

  tracks = []
  album.tracks.each do |track|
    tracks << Track.new(album.artists.first.name, track.name)
  end

  Album.new(album.artists.first.name, album.name, tracks)
end
get_track(uri) click to toggle source
# File lib/spotify_to_mp3/spotify.rb, line 7
def get_track(uri)
  track_id = parse_id(uri)
  track = RSpotify::Track.find(track_id)
  Track.new(track.artists.first.name, track.name)
end
track_uri?(uri) click to toggle source
# File lib/spotify_to_mp3/spotify.rb, line 25
def track_uri?(uri)
  uri.start_with?('http://open.spotify.com/track/', 'spotify:track:')
end

Private Instance Methods

parse_id(uri) click to toggle source
# File lib/spotify_to_mp3/spotify.rb, line 35
def parse_id(uri)
  id = uri.sub(/.*:/, '')
  id = id.sub(/.*\//, '') if uri.start_with?('http')
  id
end