ipod_db 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +5 -2
  2. data/bin/ipod +27 -13
  3. data/lib/ipod_db/version.rb +1 -1
  4. metadata +8 -2
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  NAME
5
5
  ====
6
6
 
7
- ipod_db v0.2.6
7
+ ipod_db v0.2.8
8
8
 
9
9
  SYNOPSIS
10
10
  ========
@@ -122,13 +122,16 @@ PARAMETERS
122
122
 
123
123
  track (-2 -> track)
124
124
  track numbers to delete from device (ranges like 2-5 are accepted
125
- too).
125
+ too). As a special case, the word 'done' means all finished tracks,
126
+ i.e. with play count above zero or progress above 97%
126
127
  --books=books, -b (0 ~> books=books)
127
128
  subdirectory of ipod with bookmarkable media
128
129
  --songs=songs, -s (0 ~> songs=songs)
129
130
  subdirectory of ipod with non-bookmarkable media
130
131
  --version, -v
131
132
  show package version and exit
133
+ --pretend, -n
134
+ don't delete, just list what would be deleted
132
135
  --help, -h
133
136
 
134
137
  HISTORY
data/bin/ipod CHANGED
@@ -33,6 +33,7 @@ Main {
33
33
  }
34
34
  IgnorePlaybackPosUnder = 10
35
35
  IgnoreProgressUnder = 0.01
36
+ FinishedProgress = 0.97
36
37
 
37
38
  def run
38
39
  if param['version'].given?
@@ -93,10 +94,16 @@ Main {
93
94
  arity -2
94
95
  description <<-__
95
96
  track numbers to delete from device (ranges like
96
- 2-5 are accepted too).
97
+ 2-5 are accepted too). As a special case, the word
98
+ 'done' means all finished tracks, i.e. with play count
99
+ above zero or progress above #{ (100*FinishedProgress).floor }%
97
100
  __
98
101
  }
102
+ option('pretend','n') {
103
+ description "don't delete, just list what would be deleted"
104
+ }
99
105
  def run
106
+ @pretend = params['pretend'].value
100
107
  load_ipod_db
101
108
  rm
102
109
  end
@@ -123,10 +130,12 @@ Main {
123
130
  tracks = parse_track_list(params['track'].values).map{|i,t| [i,t.filename]}
124
131
  puts "The following tracks are selected for removal:"
125
132
  tracks.each { |i,path| puts " %2d. %s" % [i,path.green] }
126
- if agree "Are you sure you want them gone (Y/n)?", true
127
- FileUtils.rm tracks.map{|i,path|resolve_ipod_path path}
133
+ unless @pretend
134
+ if agree "Are you sure you want them gone (Y/n)?", true
135
+ FileUtils.rm tracks.map{|i,path|resolve_ipod_path path}
136
+ end
137
+ sync
128
138
  end
129
- sync
130
139
  end
131
140
 
132
141
  def ipod_path path
@@ -189,12 +198,11 @@ Main {
189
198
  total_time = track_length(abs_path)
190
199
  # ipod keeps time in 256 ms increments
191
200
  pos = [total_time, track.bookmarktime * 0.256].min
192
- if pos > IgnorePlaybackPosUnder && pos / total_time >= IgnoreProgressUnder
201
+ progress = pos / total_time
202
+ if pos > IgnorePlaybackPosUnder && progress >= IgnoreProgressUnder
193
203
  info['pos'] = Pretty.seconds pos
194
204
  info['total'] = Pretty.seconds total_time
195
- # and cache seconds
196
- track['pos'] = pos
197
- track['total_time'] = total_time
205
+ info['progress'] = progress
198
206
  end
199
207
  end
200
208
  info
@@ -212,16 +220,14 @@ Main {
212
220
  return unless exists
213
221
 
214
222
  info = track_info(track)
215
- if track.include? 'pos'
223
+ if info.include? 'progress'
216
224
  progress = ProgressBar.create(
217
225
  format: " [%b #{info.pos.yellow} %P%%%i] #{info.total.yellow}",
218
- starting_at: track.pos,
219
- total: track.total_time,
226
+ starting_at: (100*info.progress),
220
227
  )
221
228
  puts
222
- info.delete :pos
223
- info.delete :total
224
229
  end
230
+ ['pos','total','progress'].each{|f| info.delete(f)}
225
231
  if info.count > 0
226
232
  puts " " + info.map{|label,value| "#{label}: #{value.to_s.yellow}"}.join(" ")
227
233
  end
@@ -239,11 +245,19 @@ Main {
239
245
  n = n_str.to_i
240
246
  tracks[n] = @ipod_db[n]
241
247
  end
248
+ when 'done'
249
+ @ipod_db.each_track_with_index do |track,n|
250
+ tracks[n] = track if finished? track
251
+ end
242
252
  end
243
253
  end
244
254
  tracks
245
255
  end
246
256
 
257
+ def finished? track
258
+ track.fetch('playcount',0) > 0 || track_info(track).fetch('progress',0) >= FinishedProgress
259
+ end
260
+
247
261
  def spread paths, group_lambda = lambda {|path| track_group(path)}
248
262
  bins = paths.group_by &group_lambda
249
263
  bins.each do |key, bin|
@@ -1,3 +1,3 @@
1
1
  class IpodDB
2
- VERSION = '0.2.7'
2
+ VERSION = '0.2.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipod_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
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: 2013-03-27 00:00:00.000000000 Z
12
+ date: 2013-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bindata
@@ -330,12 +330,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
330
330
  - - ! '>='
331
331
  - !ruby/object:Gem::Version
332
332
  version: '0'
333
+ segments:
334
+ - 0
335
+ hash: 1960172244731333251
333
336
  required_rubygems_version: !ruby/object:Gem::Requirement
334
337
  none: false
335
338
  requirements:
336
339
  - - ! '>='
337
340
  - !ruby/object:Gem::Version
338
341
  version: '0'
342
+ segments:
343
+ - 0
344
+ hash: 1960172244731333251
339
345
  requirements: []
340
346
  rubyforge_project:
341
347
  rubygems_version: 1.8.23