Sha256: 6d950a2e5bff6d9fb985ff3b0e49eb85f300e4b9d73d82a866d3206b177f764d

Contents?: true

Size: 684 Bytes

Versions: 2

Compression:

Stored size: 684 Bytes

Contents

require 'spotify_to_mp3/track'

module SpotifyToMp3
  class TrackIdResolver
    def initialize(spotify)
      @spotify = spotify
    end

    def resolve(track_id)
      resolve_spotify_track(track_id) || resolve_plain_track(track_id)
    end

    private

    def resolve_spotify_track(id)
      if @spotify.resolvable_uri?(id)
        spotify_track = @spotify.get_track(id)
        description = "#{spotify_track.artist} - #{spotify_track.name}"
        grooveshark_query = "artist:\"#{spotify_track.artist}\" title:\"#{spotify_track.name}\""
        Track.new(description, grooveshark_query)
      end
    end

    def resolve_plain_track(id)
      Track.new(id)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spotify-to-mp3-0.6.1 lib/spotify_to_mp3/track_id_resolver.rb
spotify-to-mp3-0.6.0 lib/spotify_to_mp3/track_id_resolver.rb