class Mumbletune::Resolvers::SpotifyURIResolver

Public Instance Methods

matches?(uri) click to toggle source
# File lib/mumbletune/resolver.rb, line 30
def matches?(uri)
        http_uris = URI.extract(uri, ['http', 'https'])
        sp_uris = URI.extract(uri, 'spotify')
        if http_uris.any?
                parsed_uri = URI.parse(http_uris.join)
                if parsed_uri.hostname =~ /(?:open|play)\.spotify\.com/i
                        true
                else
                        false
                end
        elsif sp_uris.any?
                true
        else
                false
        end
end
resolve(uri) click to toggle source
# File lib/mumbletune/resolver.rb, line 46
def resolve(uri)
        raise "Not a Spotify URI." unless matches?(uri)
        regexp = /(?<type>track|artist|album)[\/|:](?<id>\w+)/i
        matched = regexp.match(uri)
        type = matched[:type]
        id = matched[:id]
        sp_uri = "spotify:#{type}:#{id}"

        # behave according to URI type
        case type
        when "track" # Return this track
                obj = Hallon::Track.new(sp_uri)
                SpotifyResolver.track(obj)
        when "album" # Return all tracks of the album to queue
                obj = Hallon::Album.new(sp_uri)
                SpotifyResolver.tracks_from_album(obj)
        when "artist" # Return 10 tracks for this artist
                obj = Hallon::Artist.new(sp_uri)
                SpotifyResolver.tracks_from_artist(obj)
        end
end