ampt 0.2.0.pre3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ampt.gemspec +3 -3
- data/lib/ampt.rb +1 -70
- data/lib/ampt_api/acoustics.rb +74 -4
- data/lib/ampt_cfg/default.rb +5 -5
- metadata +4 -4
data/ampt.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ampt}
|
8
|
-
s.version = "0.2.0
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Rich"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-22}
|
13
13
|
s.default_executable = %q{ampt}
|
14
14
|
s.description = %q{This is a command line client for the Acoustics Media Player (amp).}
|
15
15
|
s.email = %q{rich@interhacktive.com}
|
data/lib/ampt.rb
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'trollop'
|
3
3
|
|
4
4
|
module Ampt
|
5
|
-
VERSION = '0.2.0
|
5
|
+
VERSION = '0.2.0'
|
6
6
|
# This is the module that holds the API for the current music player. Defined in
|
7
7
|
# ampt_api/acoustics.rb
|
8
8
|
module API
|
@@ -301,73 +301,4 @@ module Ampt
|
|
301
301
|
end
|
302
302
|
end
|
303
303
|
end
|
304
|
-
class Song
|
305
|
-
# Create from json
|
306
|
-
def self.json_create o
|
307
|
-
new o['data'] if o['data']
|
308
|
-
end
|
309
|
-
# Serialize to json
|
310
|
-
def to_json(*a)
|
311
|
-
{
|
312
|
-
'json_class' => self.class.name,
|
313
|
-
'data' => [self.instance_variables.reduce({}) do |d,v|
|
314
|
-
d[v[1..-1]] = self.instance_variable_get v
|
315
|
-
d
|
316
|
-
end]
|
317
|
-
}.to_json(*a)
|
318
|
-
end
|
319
|
-
|
320
|
-
# Takes a hash to set up the object
|
321
|
-
def initialize h
|
322
|
-
h.each do |k,v|
|
323
|
-
(class << self; self; end).instance_eval do
|
324
|
-
attr_reader k
|
325
|
-
end
|
326
|
-
instance_variable_set '@'+k, v
|
327
|
-
end
|
328
|
-
end
|
329
|
-
end
|
330
|
-
|
331
|
-
class Status
|
332
|
-
attr_reader :playlist, :now_playing, :who
|
333
|
-
def self.json_create(o)
|
334
|
-
o = o['data']
|
335
|
-
playlist = if o['playlist']
|
336
|
-
playlist = o['playlist'].collect do |s|
|
337
|
-
Song.json_create('data' => s)
|
338
|
-
end
|
339
|
-
else
|
340
|
-
[]
|
341
|
-
end
|
342
|
-
now_playing= Song.json_create('data' => o['now_playing'])
|
343
|
-
new o['player'], o['can_skip'], o['who'], now_playing, playlist
|
344
|
-
end
|
345
|
-
|
346
|
-
def initialize player, can_skip, whoami, now_playing, playlist
|
347
|
-
if player
|
348
|
-
player.each do |k,v|
|
349
|
-
meta_eval do
|
350
|
-
attr_reader k
|
351
|
-
end
|
352
|
-
instance_variable_set '@'+k, v
|
353
|
-
end
|
354
|
-
end
|
355
|
-
@can_skip = can_skip
|
356
|
-
@who = whoami
|
357
|
-
@playlist = playlist
|
358
|
-
@now_playing = now_playing
|
359
|
-
end
|
360
|
-
|
361
|
-
def can_skip?
|
362
|
-
@can_skip
|
363
|
-
end
|
364
|
-
|
365
|
-
private
|
366
|
-
def metaclass
|
367
|
-
(class << self; self; end)
|
368
|
-
end
|
369
|
-
def meta_eval &b
|
370
|
-
metaclass.instance_eval &b
|
371
|
-
end
|
372
|
-
end
|
373
304
|
end
|
data/lib/ampt_api/acoustics.rb
CHANGED
@@ -8,7 +8,7 @@ module Ampt
|
|
8
8
|
# Request the player's status. gets the session first so we can tell
|
9
9
|
# whether or not we can skip the current song, which songs are ours, etc.
|
10
10
|
def status
|
11
|
-
auth
|
11
|
+
auth false
|
12
12
|
player_status req
|
13
13
|
end
|
14
14
|
|
@@ -31,7 +31,7 @@ module Ampt
|
|
31
31
|
|
32
32
|
# Clears all of your votes.
|
33
33
|
def reset
|
34
|
-
|
34
|
+
unvote '0'
|
35
35
|
end
|
36
36
|
|
37
37
|
# Gets the most recently added songs. Takes a string count.
|
@@ -125,7 +125,7 @@ module Ampt
|
|
125
125
|
end
|
126
126
|
|
127
127
|
# Perform an authenticated request
|
128
|
-
def auth
|
128
|
+
def auth fatal = true
|
129
129
|
unless @sess
|
130
130
|
c = Curl::Easy.new
|
131
131
|
c.http_auth_types = Curl::CURLAUTH_GSSNEGOTIATE
|
@@ -135,10 +135,80 @@ module Ampt
|
|
135
135
|
sessid = c.header_str[/CGISESSID=(.+);/]
|
136
136
|
if sessid.nil?
|
137
137
|
puts "Could not authenticate -- maybe you should kinit?"
|
138
|
-
abort
|
138
|
+
abort if fatal
|
139
|
+
return
|
139
140
|
end
|
140
141
|
@sess = sessid.chop
|
141
142
|
end
|
142
143
|
end
|
143
144
|
end
|
145
|
+
class Song
|
146
|
+
# Create from json
|
147
|
+
def self.json_create o
|
148
|
+
new o['data'] if o['data']
|
149
|
+
end
|
150
|
+
# Serialize to json
|
151
|
+
def to_json(*a)
|
152
|
+
{
|
153
|
+
'json_class' => self.class.name,
|
154
|
+
'data' => [self.instance_variables.reduce({}) do |d,v|
|
155
|
+
d[v[1..-1]] = self.instance_variable_get v
|
156
|
+
d
|
157
|
+
end]
|
158
|
+
}.to_json(*a)
|
159
|
+
end
|
160
|
+
|
161
|
+
# Takes a hash to set up the object
|
162
|
+
def initialize h
|
163
|
+
h.each do |k,v|
|
164
|
+
(class << self; self; end).instance_eval do
|
165
|
+
attr_reader k
|
166
|
+
end
|
167
|
+
instance_variable_set '@'+k, v
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
class Status
|
173
|
+
attr_reader :playlist, :now_playing, :who
|
174
|
+
def self.json_create(o)
|
175
|
+
o = o['data']
|
176
|
+
playlist = if o['playlist']
|
177
|
+
playlist = o['playlist'].collect do |s|
|
178
|
+
Song.json_create('data' => s)
|
179
|
+
end
|
180
|
+
else
|
181
|
+
[]
|
182
|
+
end
|
183
|
+
now_playing= Song.json_create('data' => o['now_playing'])
|
184
|
+
new o['player'], o['can_skip'], o['who'], now_playing, playlist
|
185
|
+
end
|
186
|
+
|
187
|
+
def initialize player, can_skip, whoami, now_playing, playlist
|
188
|
+
if player
|
189
|
+
player.each do |k,v|
|
190
|
+
meta_eval do
|
191
|
+
attr_reader k
|
192
|
+
end
|
193
|
+
instance_variable_set '@'+k, v
|
194
|
+
end
|
195
|
+
end
|
196
|
+
@can_skip = can_skip
|
197
|
+
@who = whoami
|
198
|
+
@playlist = playlist
|
199
|
+
@now_playing = now_playing
|
200
|
+
end
|
201
|
+
|
202
|
+
def can_skip?
|
203
|
+
@can_skip
|
204
|
+
end
|
205
|
+
|
206
|
+
private
|
207
|
+
def metaclass
|
208
|
+
(class << self; self; end)
|
209
|
+
end
|
210
|
+
def meta_eval &b
|
211
|
+
metaclass.instance_eval &b
|
212
|
+
end
|
213
|
+
end
|
144
214
|
end
|
data/lib/ampt_cfg/default.rb
CHANGED
@@ -144,12 +144,12 @@ command 'remove' do
|
|
144
144
|
elsif opts[:interactive]
|
145
145
|
st = status
|
146
146
|
me = st.who
|
147
|
-
|
147
|
+
l = st.playlist.select do |s|
|
148
148
|
s.who.include? me
|
149
149
|
end
|
150
150
|
s = []
|
151
151
|
Tempfile.open("ampt") do |tempfile|
|
152
|
-
songs_to_file(
|
152
|
+
songs_to_file(l, tempfile)
|
153
153
|
tempfile.fsync
|
154
154
|
tempfile.flush
|
155
155
|
path = tempfile.path
|
@@ -195,7 +195,7 @@ command 'add' do
|
|
195
195
|
list_of[:album] = opts[:album]
|
196
196
|
list_of[:title] = opts[:title]
|
197
197
|
list_of[:search] = opts[:search]
|
198
|
-
|
198
|
+
l = if opts[:search_given]
|
199
199
|
list_of.collect do |k,v|
|
200
200
|
v.collect do |v|
|
201
201
|
search(v)
|
@@ -208,10 +208,10 @@ command 'add' do
|
|
208
208
|
end
|
209
209
|
end
|
210
210
|
end
|
211
|
-
|
211
|
+
l = l.flatten
|
212
212
|
s = []
|
213
213
|
Tempfile.open("ampt") do |tempfile|
|
214
|
-
songs_to_file(
|
214
|
+
songs_to_file(l, tempfile)
|
215
215
|
tempfile.fsync
|
216
216
|
tempfile.flush
|
217
217
|
path = tempfile.path
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ampt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rich
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-22 00:00:00 -06:00
|
13
13
|
default_executable: ampt
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -81,9 +81,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
81
|
version:
|
82
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
|
-
- - "
|
84
|
+
- - ">="
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
86
|
+
version: "0"
|
87
87
|
version:
|
88
88
|
requirements: []
|
89
89
|
|