Class: Mumbletune::SpotifyResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/mumbletune/spotify_resolver.rb

Class Method Summary collapse

Class Method Details

.track(track) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/mumbletune/spotify_resolver.rb', line 5

def self.track(track)
	track.load

	raise "#{track.name}: Not available in this region." unless track.available?

	# Technically, a collection of one.
	Collection.new(
		:TRACK,
		track,
		"<b>#{track.name}</b> by <b>#{track.artist.name}</b>"
		)
end

.tracks_from_album(album) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mumbletune/spotify_resolver.rb', line 18

def self.tracks_from_album(album)	
	album.load

	raise "#{album.name}: Not available in this region." unless album.available?

	browse = album.browse
	browse.load

	Collection.new(
		:ALBUM,
		browse.tracks.to_a,
		"the album <b>#{album.name}</b> by <b>#{album.artist.name}</b>"
		)
end

.tracks_from_artist(artist) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mumbletune/spotify_resolver.rb', line 33

def self.tracks_from_artist(artist)
	artist.load

	tracks_needed = Mumbletune.config["player"]["tracks_for_artist"] || 5

	search = Hallon::Search.new("artist:\"#{artist.name}\"",
		tracks: tracks_needed,
		artists: 0,
		albums: 0,
		playlists: 0).load

	Collection.new(
		:ARTIST_TOP,
		search.tracks.to_a,
		"#{search.tracks.size} tracks by <b>#{artist.name}</b>"
		)
end