Class: Hallon::Track
- Defined in:
- lib/hallon/track.rb
Overview
Tracks are an essential part to the Spotify service. They are browsable entities that can also be played by streaming.
Direct Known Subclasses
Defined Under Namespace
Classes: Artists
Instance Attribute Summary collapse
-
#offset ⇒ Rational
readonly
Offset into track in seconds this track was created with.
Attributes inherited from Base
Class Method Summary collapse
-
.local(title, artist, album = nil, length = nil) ⇒ Track
Create a new local track.
Instance Method Summary collapse
-
#_to_link ⇒ Hallon::Link
Overriden to use default parameter.
-
#album ⇒ Hallon::Album
Album this track belongs to.
-
#artist ⇒ Hallon::Artist?
Artist who performed this track.
-
#artists ⇒ Artists
All Artists who performed this Track.
-
#autolinked? ⇒ Boolean
True if the track is autolinked.
-
#availability ⇒ Symbol
Track availability.
-
#available? ⇒ Boolean
True if #availability is available.
-
#disc ⇒ Integer
Disc number this track appears in.
-
#duration ⇒ Rational
Duration of the track in seconds.
-
#from_link ⇒ Spotify::Link
private
Pointer representation of given link.
-
#index ⇒ Integer
Position of track on its’ disc.
-
#initialize(link) ⇒ Track
constructor
Construct a new Track instance.
-
#loaded? ⇒ Boolean
True if track is loaded.
-
#local? ⇒ Boolean
True if the track is a local track.
- #name ⇒ String
-
#offline_status ⇒ Symbol
Track offline status.
-
#placeholder? ⇒ Boolean
for other objects to allow storing them in playlists such as the inbox.
-
#playable_track ⇒ Track
The track this track is autolinked to for audio playback.
-
#popularity ⇒ Rational
Track popularity, between 0 and 100.
-
#starred=(starred) ⇒ Object
Set #starred? status of current track.
-
#starred? ⇒ Boolean
True if the track is starred.
-
#status ⇒ Symbol
Track error status.
-
#to_link(offset = offset) ⇒ Hallon::Link
Create a Link to the current track and offset in seconds.
-
#unwrap ⇒ Track, ...
Unwraps a #placeholder? Track into its’ real object.
Methods included from Loadable
Methods included from Linkable
Methods inherited from Base
#==, from, from_link, #is_linkable?, #session, to_link, #to_pointer, #to_s
Constructor Details
Instance Attribute Details
#offset ⇒ Rational (readonly)
Offset into track in seconds this track was created with.
39 40 41 |
# File 'lib/hallon/track.rb', line 39 def offset @offset end |
Class Method Details
.local(title, artist, album = nil, length = nil) ⇒ Track
I’ve been unable to get local tracks to get matched up in libspotify v11, it’s possible this function does not work properly in libspotify v11.
Create a new local track.
Local tracks in Spotify allows you to specify title, artist, and optionally also album and length. This will create a local track (meaning #local? returns true) that libspotify will try to match up with an actual track in the Spotify database.
If the track is successfully matched, once loaded, #available? will return true and you’ll be able to inspect the track’s #artist and #album, as well as the information in the track itself. If the track is playable you’ll also be able to play it!
76 77 78 79 |
# File 'lib/hallon/track.rb', line 76 def self.local(title, artist, album = nil, length = nil) track = Spotify.localtrack_create(artist, title, album || "", length || -1) new(track) end |
Instance Method Details
#_to_link ⇒ Hallon::Link
Overriden to use default parameter.
26 |
# File 'lib/hallon/track.rb', line 26 to_link :from_track |
#album ⇒ Hallon::Album
Returns album this track belongs to.
159 160 161 162 |
# File 'lib/hallon/track.rb', line 159 def album album = Spotify.track_album(pointer) Album.from(album) end |
#artist ⇒ Hallon::Artist?
There may be more than one artist, see #artists for retrieving them all!
Returns artist who performed this track.
167 168 169 |
# File 'lib/hallon/track.rb', line 167 def artist artists.first end |
#artists ⇒ Artists
Returns all Artists who performed this Track.
172 173 174 |
# File 'lib/hallon/track.rb', line 172 def artists Artists.new(self) end |
#autolinked? ⇒ Boolean
Returns true if the track is autolinked.
201 202 203 |
# File 'lib/hallon/track.rb', line 201 def autolinked? Spotify.track_is_autolinked(session.pointer, pointer) end |
#availability ⇒ Symbol
Track availability.
184 185 186 |
# File 'lib/hallon/track.rb', line 184 def availability Spotify.track_get_availability(session.pointer, pointer) end |
#available? ⇒ Boolean
Returns true if #availability is available.
177 178 179 |
# File 'lib/hallon/track.rb', line 177 def available? availability == :available end |
#disc ⇒ Integer
This function is a bit special. See libspotify docs for details.
Disc number this track appears in.
104 105 106 |
# File 'lib/hallon/track.rb', line 104 def disc Spotify.track_disc(pointer) end |
#duration ⇒ Rational
Duration of the track in seconds.
89 90 91 |
# File 'lib/hallon/track.rb', line 89 def duration Rational(Spotify.track_duration(pointer), 1000) end |
#from_link ⇒ Spotify::Link (private)
Returns pointer representation of given link.
21 |
# File 'lib/hallon/track.rb', line 21 from_link :as_track_and_offset |
#index ⇒ Integer
This function is a bit special. See libspotify docs for details.
Returns position of track on its’ disc.
110 111 112 |
# File 'lib/hallon/track.rb', line 110 def index Spotify.track_index(pointer) end |
#loaded? ⇒ Boolean
Returns true if track is loaded.
121 122 123 |
# File 'lib/hallon/track.rb', line 121 def loaded? Spotify.track_is_loaded(pointer) end |
#local? ⇒ Boolean
Returns true if the track is a local track.
196 197 198 |
# File 'lib/hallon/track.rb', line 196 def local? Spotify.track_is_local(session.pointer, pointer) end |
#name ⇒ String
82 83 84 |
# File 'lib/hallon/track.rb', line 82 def name Spotify.track_name(pointer) end |
#offline_status ⇒ Symbol
Returns track offline status.
154 155 156 |
# File 'lib/hallon/track.rb', line 154 def offline_status Spotify.track_offline_get_status(pointer) end |
#placeholder? ⇒ Boolean
Track does not have to be loaded for this to return a useful value.
Placeholder tracks are not really tracks, but merely containers
for other objects to allow storing them in playlists such as the inbox.
132 133 134 |
# File 'lib/hallon/track.rb', line 132 def placeholder? Spotify.track_is_placeholder(pointer) end |
#playable_track ⇒ Track
Returns the track this track is autolinked to for audio playback.
190 191 192 193 |
# File 'lib/hallon/track.rb', line 190 def playable_track track = Spotify.track_get_playable(session.pointer, pointer) Track.from(track) end |
#popularity ⇒ Rational
Track popularity, between 0 and 100.
96 97 98 |
# File 'lib/hallon/track.rb', line 96 def popularity Spotify.track_popularity(pointer) end |
#starred=(starred) ⇒ Object
this method might raise a Spotify::Error, however when this might occur is not documented in libspotify (and I have yet to find any way to trigger it myself). it’s entirely possible that this method never returns an error, but we can’t know for sure.
Set #starred? status of current track.
216 217 218 |
# File 'lib/hallon/track.rb', line 216 def starred=(starred) starred ? session.star(self) : session.unstar(self) end |
#starred? ⇒ Boolean
This’ll always return false unless the track is loaded.
Returns true if the track is starred.
207 208 209 |
# File 'lib/hallon/track.rb', line 207 def starred? Spotify.track_is_starred(session.pointer, pointer) end |
#status ⇒ Symbol
Returns track error status.
116 117 118 |
# File 'lib/hallon/track.rb', line 116 def status Spotify.track_error(pointer) end |
#to_link(offset = offset) ⇒ Hallon::Link
Create a Link to the current track and offset in seconds.
32 |
# File 'lib/hallon/track.rb', line 32 to_link :from_track |
#unwrap ⇒ Track, ...
Unwraps a #placeholder? Track into its’ real object.
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/hallon/track.rb', line 140 def unwrap return self unless placeholder? case (link = to_link).type when :playlist Playlist.new(link) when :album Album.new(link) when :artist Artist.new(link) end end |