rdio-cli 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +49 -9
- data/lib/rdio.rb +71 -66
- data/lib/rdio/desktop_bridge.rb +71 -0
- data/lib/rdio/version.rb +1 -1
- data/rdio-cli.gemspec +1 -0
- metadata +19 -3
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Rdio CLI
|
2
2
|
|
3
|
-
A simple command line interface for [Rdio][].
|
3
|
+
A simple command line interface for [Rdio][]. Requires the desktop app to be
|
4
|
+
installed since playback controls talk to the app via AppleScript.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -22,12 +23,48 @@ $ rdio current "♫ %{track} ♫"
|
|
22
23
|
♫ All The Roadrunning ♫
|
23
24
|
```
|
24
25
|
|
25
|
-
###
|
26
|
+
### Lyrics
|
26
27
|
|
27
|
-
|
28
|
+
Plain text, terminal-friendly lyrics are served up via [makeitpersonal.co][]:
|
28
29
|
|
29
|
-
|
30
|
+
```
|
31
|
+
~ rdio current
|
32
|
+
Now playing: That Old Time Feeling / Rodney Crowell / This One's for Him: A Tribute to Guy Clark
|
33
|
+
|
34
|
+
~ rdio lyrics
|
35
|
+
Sorry, We don't have lyrics for this song yet.
|
36
|
+
|
37
|
+
~ rdio lyrics --artist="Guy Clark"
|
38
|
+
|
39
|
+
And that old time feeling goes sneakin' down the hall
|
40
|
+
Like an old gray cat in winter, keepin' close to the wall
|
41
|
+
And that old time feeling comes stumblin' up the street
|
42
|
+
Like an old salesman kickin' the papers from his feet
|
43
|
+
|
44
|
+
And that old time feeling draws circles around the block
|
45
|
+
Like old women with no children, holdin' hands with the clock
|
46
|
+
And that old time feeling falls on its face in the park
|
47
|
+
Like an old wino prayin' he can make it till it's dark
|
48
|
+
|
49
|
+
And that old time feeling comes and goes in the rain
|
50
|
+
Like an old man with his checkers, dyin' to find a game
|
51
|
+
And that old time feeling plays for beer in bars
|
52
|
+
Like an old blues-time picker who don't recall who you are
|
30
53
|
|
54
|
+
And that old time feeling limps through the night on a crutch
|
55
|
+
Like an old soldier wonderin' if he's paid too much
|
56
|
+
And that old time feeling rocks and spits and cries
|
57
|
+
Like an old lover rememberin' the girl with the clear blue eyes
|
58
|
+
|
59
|
+
And that old time feeling goes sneakin' down the hall
|
60
|
+
Like an old gray cat in winter, keepin' close to the wall
|
61
|
+
|
62
|
+
```
|
63
|
+
|
64
|
+
### Full usage help
|
65
|
+
|
66
|
+
```
|
67
|
+
$ rdio help
|
31
68
|
NAME
|
32
69
|
rdio - Simple CLI for Rdio
|
33
70
|
|
@@ -38,10 +75,10 @@ VERSION
|
|
38
75
|
0.0.1
|
39
76
|
|
40
77
|
GLOBAL OPTIONS
|
41
|
-
--access_secret=arg - (default:
|
42
|
-
--access_token=arg - (default:
|
43
|
-
--consumer_key=arg - (default:
|
44
|
-
--consumer_secret=arg - (default:
|
78
|
+
--access_secret=arg - (default: )
|
79
|
+
--access_token=arg - (default: )
|
80
|
+
--consumer_key=arg - (default: )
|
81
|
+
--consumer_secret=arg - (default: )
|
45
82
|
--help - Show this message
|
46
83
|
--version -
|
47
84
|
|
@@ -52,12 +89,14 @@ COMMANDS
|
|
52
89
|
help - Shows a list of commands or help for one command
|
53
90
|
initconfig - Initialize the config file using current global options
|
54
91
|
link - Get a shareable link for the current track
|
92
|
+
lyrics - Show lyrics for a track
|
55
93
|
mute - Mute the Rdio player
|
56
94
|
next - Skip to next track
|
57
95
|
pause - Pause the player
|
58
96
|
play - Plays the current track
|
59
97
|
previous, prev - Play previous track
|
60
98
|
quit, q - Quit Rdio
|
99
|
+
snag - Add the current track or album to your collection
|
61
100
|
toggle - Toggle playback
|
62
101
|
user - Show the current Rdio user
|
63
102
|
version, v - Get CLI and application version info
|
@@ -66,7 +105,7 @@ COMMANDS
|
|
66
105
|
|
67
106
|
## TODO
|
68
107
|
* `[✓]` <del>Snag current track to collection</del>
|
69
|
-
* `[
|
108
|
+
* `[✓]` <del>Snag current album to collection</del>
|
70
109
|
* `[ ]` Create a playlist
|
71
110
|
* `[ ]` Follow a user
|
72
111
|
* `[ ]` Tail a user?
|
@@ -85,3 +124,4 @@ Copyright (c) 2012 Wynn Netherland. See [LICENSE][] for details.
|
|
85
124
|
[Drew Stokes]: https://github.com/dstokes
|
86
125
|
[node-rdio]: https://github.com/dstokes/rdio-cli
|
87
126
|
[GLI]: https://github.com/davetron5000/gli
|
127
|
+
[makeitpersonal.co]: http://makeitpersonal.co
|
data/lib/rdio.rb
CHANGED
@@ -4,6 +4,7 @@ require 'launchy'
|
|
4
4
|
|
5
5
|
require 'api'
|
6
6
|
require 'rdio/version'
|
7
|
+
require 'rdio/desktop_bridge'
|
7
8
|
require 'highline/import'
|
8
9
|
|
9
10
|
module Rdio
|
@@ -13,6 +14,10 @@ module Rdio
|
|
13
14
|
|
14
15
|
version Rdio::VERSION
|
15
16
|
|
17
|
+
def self.bridge
|
18
|
+
@bridge ||= Rdio::DesktopBridge.new
|
19
|
+
end
|
20
|
+
|
16
21
|
def self.api
|
17
22
|
token = @access_token ? [@access_token, @access_secret] : nil
|
18
23
|
@api = Api.new \
|
@@ -32,6 +37,15 @@ module Rdio
|
|
32
37
|
say "You're all set. see `rdio help` for usage"
|
33
38
|
end
|
34
39
|
|
40
|
+
def self.lyrics_for(artist, title)
|
41
|
+
uri = URI('http://makeitpersonal.co/lyrics')
|
42
|
+
params = { :artist => artist, :title => title }
|
43
|
+
uri.query = URI.encode_www_form(params)
|
44
|
+
|
45
|
+
res = Net::HTTP.get_response(uri)
|
46
|
+
return res.body
|
47
|
+
end
|
48
|
+
|
35
49
|
def self.rdio_config
|
36
50
|
{
|
37
51
|
:consumer_key => @consumer_key,
|
@@ -48,48 +62,21 @@ module Rdio
|
|
48
62
|
end
|
49
63
|
end
|
50
64
|
|
51
|
-
def self.
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.tell_rdio(cmd)
|
56
|
-
apple_script "tell app \"Rdio\" to #{cmd}"
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.current_track
|
60
|
-
tell_rdio('name of the current track').gsub(/\n/, '')
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.current_artist
|
64
|
-
tell_rdio('artist of the current track').gsub(/\n/, '')
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.current_album
|
68
|
-
tell_rdio('album of the current track').gsub(/\n/, '')
|
65
|
+
def self.current_user
|
66
|
+
@current_user ||= api.call('currentUser', :extras => 'lastSongPlayed')['result']
|
69
67
|
end
|
70
68
|
|
71
|
-
def self.
|
72
|
-
|
73
|
-
say (text % {
|
74
|
-
:artist => current_artist,
|
75
|
-
:track => current_track,
|
76
|
-
:album => current_album
|
77
|
-
})
|
78
|
-
end
|
79
|
-
|
80
|
-
def self.set_volume(pct = 30)
|
81
|
-
tell_rdio "set the sound volume to #{pct}"
|
82
|
-
end
|
69
|
+
def self.current_track_key
|
70
|
+
data = api.call 'getObjectFromUrl', { :url => bridge.current_url }
|
83
71
|
|
84
|
-
|
85
|
-
path = tell_rdio 'rdio url of the current track'
|
86
|
-
"http://www.rdio.com#{path}"
|
72
|
+
data['result']['key']
|
87
73
|
end
|
88
74
|
|
89
|
-
def self.
|
90
|
-
|
75
|
+
def self.current_album_track_keys
|
76
|
+
current_album_url = current_user['lastSongPlayed']['albumUrl']
|
77
|
+
data = api.call 'getObjectFromUrl', { :url => current_album_url }
|
91
78
|
|
92
|
-
data['result']['
|
79
|
+
data['result']['trackKeys']
|
93
80
|
end
|
94
81
|
|
95
82
|
def self.add_to_collection(tracks)
|
@@ -100,34 +87,40 @@ module Rdio
|
|
100
87
|
|
101
88
|
config_file '.rdio'
|
102
89
|
|
103
|
-
|
104
|
-
flag :
|
105
|
-
|
106
|
-
flag :
|
90
|
+
desc 'Rdio API consumer key'
|
91
|
+
flag :consumer_key, :mask => true
|
92
|
+
desc 'Rdio API consumer secret'
|
93
|
+
flag :consumer_secret, :mask => true
|
94
|
+
desc 'Rdio API access token'
|
95
|
+
flag :access_token, :mask => true
|
96
|
+
desc 'Rdio API access secret'
|
97
|
+
flag :access_secret, :mask => true
|
107
98
|
|
99
|
+
skips_pre
|
108
100
|
desc 'Plays the current track'
|
109
101
|
command :play do |c|
|
110
102
|
c.action do |global_options,options,args|
|
111
|
-
|
103
|
+
bridge.play
|
112
104
|
end
|
113
105
|
end
|
114
106
|
|
115
|
-
desc 'Pause the player'
|
116
107
|
skips_pre
|
108
|
+
desc 'Pause the player'
|
117
109
|
command :pause do |c|
|
118
110
|
c.action do |global_options,options,args|
|
119
|
-
|
111
|
+
bridge.pause
|
120
112
|
end
|
121
113
|
end
|
122
114
|
|
123
|
-
desc 'Toggle playback'
|
124
115
|
skips_pre
|
116
|
+
desc 'Toggle playback'
|
125
117
|
command :toggle do |c|
|
126
118
|
c.action do |global_options,options,args|
|
127
|
-
|
119
|
+
bridge.toggle
|
128
120
|
end
|
129
121
|
end
|
130
122
|
|
123
|
+
skips_pre
|
131
124
|
desc 'Display the current track info'
|
132
125
|
long_desc %(
|
133
126
|
Display current track, artist, and album info. Pass
|
@@ -135,81 +128,81 @@ module Rdio
|
|
135
128
|
%{track}, %{artist}, and %{album} placeholders.
|
136
129
|
)
|
137
130
|
arg_name 'format'
|
138
|
-
skips_pre
|
139
131
|
command :current do |c|
|
140
132
|
c.action do |global_options,options,args|
|
141
|
-
|
133
|
+
say bridge.now_playing(args.first)
|
142
134
|
end
|
143
135
|
end
|
144
136
|
|
145
|
-
desc 'Skip to next track'
|
146
137
|
skips_pre
|
138
|
+
desc 'Skip to next track'
|
147
139
|
command :next do |c|
|
148
140
|
c.action do |global_options,options,args|
|
149
|
-
|
141
|
+
bridge.next_track
|
150
142
|
end
|
151
143
|
end
|
152
144
|
|
153
|
-
desc 'Play previous track'
|
154
145
|
skips_pre
|
146
|
+
desc 'Play previous track'
|
155
147
|
command :previous, :prev do |c|
|
156
148
|
c.action do |global_options,options,args|
|
157
|
-
|
149
|
+
bridge.previous_track
|
158
150
|
end
|
159
151
|
end
|
160
152
|
|
161
|
-
desc 'Open the current track in Rdio player'
|
162
153
|
skips_pre
|
154
|
+
desc 'Open the current track in Rdio player'
|
163
155
|
command :browse do |c|
|
164
156
|
c.action do |global_options,options,args|
|
165
|
-
|
157
|
+
protocol = args.first == 'app' ? 'rdio' : 'http'
|
158
|
+
exec "open '#{bridge.current_url protocol}'"
|
166
159
|
end
|
167
160
|
end
|
168
161
|
|
169
|
-
desc 'Set volume for player'
|
170
162
|
skips_pre
|
163
|
+
desc 'Set volume for player'
|
171
164
|
arg_name 'level'
|
172
165
|
command :volume, :vol do |c|
|
173
166
|
c.action do |global_options,options,args|
|
174
167
|
level = args.shift.to_i
|
175
|
-
set_volume level
|
168
|
+
bridge.set_volume level
|
176
169
|
end
|
177
170
|
end
|
178
171
|
|
179
|
-
desc 'Mute the Rdio player'
|
180
172
|
skips_pre
|
173
|
+
desc 'Mute the Rdio player'
|
181
174
|
command :mute do |c|
|
182
175
|
c.action do |global_options,options,args|
|
183
|
-
set_volume 0
|
176
|
+
brdige.set_volume 0
|
184
177
|
end
|
185
178
|
end
|
186
179
|
|
187
|
-
desc 'Get a shareable link for the current track'
|
188
180
|
skips_pre
|
181
|
+
desc 'Get a shareable link for the current track'
|
189
182
|
command :link do |c|
|
190
183
|
c.action do |global_options,options,args|
|
191
|
-
say
|
184
|
+
say bridge.current_url
|
192
185
|
end
|
193
186
|
end
|
194
187
|
|
195
|
-
desc "Get CLI and application version info"
|
196
188
|
skips_pre
|
189
|
+
desc "Get CLI and application version info"
|
197
190
|
command :version, :v do |c|
|
198
191
|
c.action do |global_options,options,args|
|
199
192
|
say "rdio-cli #{Rdio::VERSION} / Rdio #{apple_script('get version of application "Rdio"')}"
|
200
193
|
end
|
201
194
|
end
|
202
195
|
|
203
|
-
desc "Quit Rdio"
|
204
196
|
skips_pre
|
197
|
+
desc "Quit Rdio"
|
205
198
|
command :quit, :q do |c|
|
206
199
|
c.action do |global_options,options,args|
|
207
|
-
|
200
|
+
bridge.quit
|
208
201
|
end
|
209
202
|
end
|
210
203
|
|
211
|
-
desc "Authorize Rdio account"
|
212
204
|
skips_pre
|
205
|
+
desc "Authorize Rdio account"
|
213
206
|
command :authorize, :auth do |c|
|
214
207
|
c.action do |global_options,options,args|
|
215
208
|
require 'highline/import'
|
@@ -224,12 +217,24 @@ module Rdio
|
|
224
217
|
end
|
225
218
|
end
|
226
219
|
|
220
|
+
skips_pre
|
221
|
+
desc 'Show lyrics for a track'
|
222
|
+
command :lyrics do |c|
|
223
|
+
c.flag :artist
|
224
|
+
c.flag :title
|
225
|
+
c.action do |global_options,options,args|
|
226
|
+
artist = options[:artist] || bridge.current_artist
|
227
|
+
title = options[:title] || bridge.current_track
|
228
|
+
say lyrics_for(artist, title)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
227
232
|
### Authenticated methods
|
228
233
|
|
229
234
|
desc 'Show the current Rdio user'
|
230
235
|
command :user do |c|
|
231
236
|
c.action do |global_options,options,args|
|
232
|
-
user =
|
237
|
+
user = current_user
|
233
238
|
say "#{user['firstName']} #{user['lastName']}"
|
234
239
|
end
|
235
240
|
end
|
@@ -239,7 +244,7 @@ module Rdio
|
|
239
244
|
c.action do |global_options,options,args|
|
240
245
|
case args.shift
|
241
246
|
when 'album'
|
242
|
-
|
247
|
+
add_to_collection current_album_track_keys
|
243
248
|
when nil
|
244
249
|
add_to_collection current_track_key
|
245
250
|
end
|
@@ -256,7 +261,7 @@ module Rdio
|
|
256
261
|
@consumer_secret = global[:consumer_secret]
|
257
262
|
@access_token = global[:access_token]
|
258
263
|
@access_secret = global[:access_secret]
|
259
|
-
if api.token.compact.empty?
|
264
|
+
if api.token.nil? || api.token.compact.empty?
|
260
265
|
say 'Rdio credentials not found. Please run: rdio authorize'
|
261
266
|
|
262
267
|
false
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Rdio
|
2
|
+
class DesktopBridge
|
3
|
+
|
4
|
+
def apple_script(cmd)
|
5
|
+
`osascript -e '#{cmd}'`
|
6
|
+
end
|
7
|
+
|
8
|
+
def tell_rdio(cmd)
|
9
|
+
apple_script "tell app \"Rdio\" to #{cmd}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def quit
|
13
|
+
# apple_script "tell application \"Rdio\" to quit"
|
14
|
+
tell_rdio "quit"
|
15
|
+
end
|
16
|
+
|
17
|
+
def play
|
18
|
+
tell_rdio "play"
|
19
|
+
end
|
20
|
+
|
21
|
+
def pause
|
22
|
+
tell_rdio "pause"
|
23
|
+
end
|
24
|
+
|
25
|
+
def toggle
|
26
|
+
tell_rdio "playpause"
|
27
|
+
end
|
28
|
+
|
29
|
+
def next_track
|
30
|
+
tell_rdio "next track"
|
31
|
+
end
|
32
|
+
|
33
|
+
def previous_track
|
34
|
+
tell_rdio "previous track"
|
35
|
+
end
|
36
|
+
|
37
|
+
def current_track
|
38
|
+
tell_rdio('name of the current track').chomp
|
39
|
+
end
|
40
|
+
|
41
|
+
def current_artist
|
42
|
+
tell_rdio('artist of the current track').chomp
|
43
|
+
end
|
44
|
+
|
45
|
+
def current_album
|
46
|
+
tell_rdio('album of the current track').chomp
|
47
|
+
end
|
48
|
+
|
49
|
+
def now_playing(text=nil)
|
50
|
+
return "Nothing playing" if current_track.empty?
|
51
|
+
|
52
|
+
text ||= "Now playing: %{track} / %{artist} / %{album}"
|
53
|
+
text % {
|
54
|
+
:artist => current_artist,
|
55
|
+
:track => current_track,
|
56
|
+
:album => current_album
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def set_volume(pct = 30)
|
61
|
+
tell_rdio "set the sound volume to #{pct}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def current_url(protocol = 'http')
|
65
|
+
path = tell_rdio('rdio url of the current track').chomp
|
66
|
+
|
67
|
+
path.empty? ? nil : "#{protocol}://www.rdio.com#{path}"
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
data/lib/rdio/version.rb
CHANGED
data/rdio-cli.gemspec
CHANGED
@@ -23,5 +23,6 @@ spec = Gem::Specification.new do |s|
|
|
23
23
|
s.add_development_dependency('rdoc')
|
24
24
|
s.add_development_dependency('rspec', '~> 2.12.0')
|
25
25
|
s.add_development_dependency('rspec-mocks', '~> 2.12.0')
|
26
|
+
s.add_development_dependency 'webmock'
|
26
27
|
s.add_runtime_dependency('gli','2.5.2')
|
27
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdio-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: highline
|
@@ -107,6 +107,22 @@ dependencies:
|
|
107
107
|
- - ~>
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: 2.12.0
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: webmock
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
110
126
|
- !ruby/object:Gem::Dependency
|
111
127
|
name: gli
|
112
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,6 +153,7 @@ files:
|
|
137
153
|
- rdio-cli.gemspec
|
138
154
|
- lib/api.rb
|
139
155
|
- lib/om.rb
|
156
|
+
- lib/rdio/desktop_bridge.rb
|
140
157
|
- lib/rdio/version.rb
|
141
158
|
- lib/rdio.rb
|
142
159
|
- bin/rdio
|
@@ -171,4 +188,3 @@ signing_key:
|
|
171
188
|
specification_version: 3
|
172
189
|
summary: CLI for Rdio for Mac
|
173
190
|
test_files: []
|
174
|
-
has_rdoc: false
|