Class: SpotifyCli::App
- Inherits:
-
Object
- Object
- SpotifyCli::App
- Defined in:
- lib/spotify_cli/app.rb
Class Method Summary collapse
-
.next! ⇒ Object
Change to the next song.
-
.pause! ⇒ Object
Pause Spotify.
-
.play_pause! ⇒ Object
Play or Pause Spotify.
-
.play_uri!(uri) ⇒ Object
Pause a given URI.
-
.previous! ⇒ Object
Change to the previous song.
-
.replay! ⇒ Object
Replay the current song from the beginning.
-
.set_pos!(pos) ⇒ Object
Set position in song to the given point.
-
.state ⇒ Object
Return the state Spotify is in.
-
.status ⇒ Object
Return a hash representing the current status of Spotify Contains state, current artist, current album, current track, duration of the current track, position in the current track, percent of the track complete.
Class Method Details
.next! ⇒ Object
Change to the next song
84 85 86 |
# File 'lib/spotify_cli/app.rb', line 84 def next! oascript('tell application "Spotify" to next track') end |
.pause! ⇒ Object
Pause Spotify
70 71 72 |
# File 'lib/spotify_cli/app.rb', line 70 def pause! oascript('tell application "Spotify" to pause') end |
.play_pause! ⇒ Object
Play or Pause Spotify
64 65 66 |
# File 'lib/spotify_cli/app.rb', line 64 def play_pause! oascript('tell application "Spotify" to playpause') end |
.play_uri!(uri) ⇒ Object
Pause a given URI
78 79 80 |
# File 'lib/spotify_cli/app.rb', line 78 def play_uri!(uri) oascript("tell application \"Spotify\" to play track \"#{uri}\"") end |
.previous! ⇒ Object
Change to the previous song
90 91 92 93 94 95 96 97 |
# File 'lib/spotify_cli/app.rb', line 90 def previous! oascript(<<-EOF) tell application "Spotify" set player position to 0 previous track end tell EOF end |
.replay! ⇒ Object
Replay the current song from the beginning
109 110 111 |
# File 'lib/spotify_cli/app.rb', line 109 def replay! oascript('tell application "Spotify" to set player position to 0') end |
.set_pos!(pos) ⇒ Object
Set position in song to the given point
103 104 105 |
# File 'lib/spotify_cli/app.rb', line 103 def set_pos!(pos) oascript("tell application \"Spotify\" to set player position to #{pos}") end |
.state ⇒ Object
Return the state Spotify is in. Either “playing” or “paused”
9 10 11 |
# File 'lib/spotify_cli/app.rb', line 9 def state oascript('tell application "Spotify" to player state as string') end |
.status ⇒ Object
Return a hash representing the current status of Spotify Contains state, current artist, current album, current track, duration of the current track, position in the current track, percent of the track complete
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/spotify_cli/app.rb', line 20 def status artist = oascript('tell application "Spotify" to artist of current track as string') album = oascript('tell application "Spotify" to album of current track as string') track = oascript('tell application "Spotify" to name of current track as string') duration = oascript(<<-EOF) tell application "Spotify" set durSec to (duration of current track / 1000) as text set tM to (round (durSec / 60) rounding down) as text if length of ((durSec mod 60 div 1) as text) is greater than 1 then set tS to (durSec mod 60 div 1) as text else set tS to ("0" & (durSec mod 60 div 1)) as text end if set myTime to tM as text & ":" & tS as text end tell return myTime EOF position = oascript(<<-EOF) tell application "Spotify" set pos to player position set nM to (round (pos / 60) rounding down) as text if length of ((round (pos mod 60) rounding down) as text) is greater than 1 then set nS to (round (pos mod 60) rounding down) as text else set nS to ("0" & (round (pos mod 60) rounding down)) as text end if set nowAt to nM as text & ":" & nS as text end tell return nowAt EOF { state: state, artist: artist, album: album, track: track, duration: duration, position: position, percent_done: percent_done(position, duration) } end |