Class: Mumbletune::Resolvers::SpotifyURIResolver
- Defined in:
- lib/mumbletune/resolver.rb
Instance Method Summary collapse
Methods inherited from Resolver
Instance Method Details
#matches?(uri) ⇒ Boolean
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# 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 |