ampt 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -72,7 +72,7 @@ configuration.
72
72
 
73
73
  == INSTALL:
74
74
 
75
- $ sudo gem install ampt --pre
75
+ $ sudo gem install ampt
76
76
 
77
77
  == TODO:
78
78
  * Fix error handling when getting invalid data from the server.
data/ampt.gemspec CHANGED
@@ -5,7 +5,7 @@
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.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rich"]
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.1'
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
@@ -80,6 +80,18 @@ module Ampt
80
80
  song_list req 'random', 'amount' => amt || '20'
81
81
  end
82
82
 
83
+ # Brings song to the top.
84
+ def vote_to_top id
85
+ auth
86
+ player_status req 'vote_to_top', 'song_id' => id
87
+ end
88
+
89
+ # Shuffles your votes. Great for bogosort.
90
+ def shuffle_votes
91
+ auth
92
+ player_status req 'shuffle_votes'
93
+ end
94
+
83
95
  # Performs a request with given mode and params.
84
96
  def req mode=nil, params = nil
85
97
  c = Curl::Easy.new
@@ -91,6 +91,26 @@ def pp_time len
91
91
  str << format(":%02d", len % 60)
92
92
  end
93
93
 
94
+ def select_interactively l
95
+ s = []
96
+ Tempfile.open("ampt") do |tempfile|
97
+ songs_to_file(l, tempfile)
98
+ tempfile.fsync
99
+ tempfile.flush
100
+ path = tempfile.path
101
+ tempfile.close
102
+ system(ENV['EDITOR'], path)
103
+ File.open(path) do |f|
104
+ s = f.readlines
105
+ end
106
+ end
107
+ s.inject([]) do |a,line|
108
+ a + ((line.scan(/\s(\d+)\s/)[0] unless(line =~ /^\#/)) || [])
109
+ end
110
+ end
111
+
112
+ alias_cmd 'help' => '--help'
113
+
94
114
  alias_cmd 'st' => 'status'
95
115
  default 'status'
96
116
 
@@ -147,21 +167,9 @@ command 'remove' do
147
167
  l = st.playlist.select do |s|
148
168
  s.who.include? me
149
169
  end
150
- s = []
151
- Tempfile.open("ampt") do |tempfile|
152
- songs_to_file(l, tempfile)
153
- tempfile.fsync
154
- tempfile.flush
155
- path = tempfile.path
156
- tempfile.close
157
- system(ENV['EDITOR'], path)
158
- File.open(path) do |f|
159
- s = f.readlines
160
- end
161
- end
162
- arr = s.inject([]) do |a,line|
163
- a + ((line.scan(/\s(\d+)\s/)[0] unless(line =~ /^\#/)) || [])
164
- end
170
+
171
+ arr = select_interactively(l)
172
+
165
173
  unless arr.empty?
166
174
  arr.each_slice(40) do |a|
167
175
  unvote a
@@ -175,6 +183,7 @@ end
175
183
 
176
184
  alias_cmd 'up' => 'add'
177
185
  alias_cmd 'upvote' => 'add'
186
+ alias_cmd 'vote' => 'add'
178
187
  command 'add' do
179
188
  desc "Vote for a song. Provide a song id, or one of the flags."
180
189
  arg 'song_id'
@@ -209,21 +218,8 @@ command 'add' do
209
218
  end
210
219
  end
211
220
  l = l.flatten
212
- s = []
213
- Tempfile.open("ampt") do |tempfile|
214
- songs_to_file(l, tempfile)
215
- tempfile.fsync
216
- tempfile.flush
217
- path = tempfile.path
218
- tempfile.close
219
- system(ENV['EDITOR'], path)
220
- File.open(path) do |f|
221
- s = f.readlines
222
- end
223
- end
224
- arr = s.inject([]) do |a,line|
225
- a + ((line.scan(/\s(\d+)\s/)[0] unless(line =~ /^\#/)) || [])
226
- end
221
+
222
+ arr = select_interactively(l)
227
223
 
228
224
  unless arr.empty?
229
225
  if randomize
@@ -400,3 +396,32 @@ command 'history' do
400
396
  pp_songs_full history(args[0]), :show_all_voters => true
401
397
  end
402
398
  end
399
+
400
+ command 'shuffle' do
401
+ desc 'Shuffle your votes.'
402
+ on_run do |opts,args|
403
+ shuffle_votes
404
+ end
405
+ end
406
+
407
+ alias_cmd 'top' => 'votetotop'
408
+ command 'votetotop' do
409
+ desc 'Bring the song to the top of your list of voted songs'
410
+ opt :interactive, "Select interactively.", :short => '-i'
411
+ arg 'song_id'
412
+ on_run do |opts,args|
413
+ if opts[:interactive]
414
+ st = status
415
+ me = st.who
416
+ mine = st.playlist.select do |s|
417
+ s.who.include? me
418
+ end
419
+ arr = select_interactively mine
420
+ unless arr.empty?
421
+ vote_to_top arr
422
+ end
423
+ else
424
+ vote_to_top args
425
+ end
426
+ end
427
+ end
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rich