ipod_db 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  NAME
2
2
  ====
3
3
 
4
- ipod_db v0.2.4
4
+ ipod_db v0.2.5
5
5
 
6
6
  SYNOPSIS
7
7
  ========
@@ -17,6 +17,10 @@ DESCRIPTION
17
17
  PARAMETERS
18
18
  ==========
19
19
 
20
+ --books=books, -b (0 ~> books=books)
21
+ subdirectory of ipod with bookmarkable media
22
+ --songs=songs, -s (0 ~> songs=songs)
23
+ subdirectory of ipod with non-bookmarkable media
20
24
  --version, -v
21
25
  show package version and exit
22
26
  --help, -h
@@ -29,6 +33,8 @@ AUTHOR
29
33
 
30
34
  [![Build Status](https://travis-ci.org/artm/ipod_db.png)](https://travis-ci.org/artm/ipod_db)
31
35
 
36
+ [![Code Climate](https://codeclimate.com/github/artm/ipod_db.png)](https://codeclimate.com/github/artm/ipod_db)
37
+
32
38
 
33
39
  SUBCOMMAND: sync
34
40
  ================
@@ -67,12 +73,12 @@ DESCRIPTION
67
73
  PARAMETERS
68
74
  ==========
69
75
 
70
- --version, -v
71
- show package version and exit
72
76
  --books=books, -b (0 ~> books=books)
73
77
  subdirectory of ipod with bookmarkable media
74
78
  --songs=songs, -s (0 ~> songs=songs)
75
79
  subdirectory of ipod with non-bookmarkable media
80
+ --version, -v
81
+ show package version and exit
76
82
  --help, -h
77
83
 
78
84
  SUBCOMMAND: ls
@@ -91,6 +97,10 @@ DESCRIPTION
91
97
  PARAMETERS
92
98
  ==========
93
99
 
100
+ --books=books, -b (0 ~> books=books)
101
+ subdirectory of ipod with bookmarkable media
102
+ --songs=songs, -s (0 ~> songs=songs)
103
+ subdirectory of ipod with non-bookmarkable media
94
104
  --version, -v
95
105
  show package version and exit
96
106
  --help, -h
@@ -115,6 +125,10 @@ PARAMETERS
115
125
  track (-2 -> track)
116
126
  track numbers to delete from device (ranges like 2-5 are accepted
117
127
  too).
128
+ --books=books, -b (0 ~> books=books)
129
+ subdirectory of ipod with bookmarkable media
130
+ --songs=songs, -s (0 ~> songs=songs)
131
+ subdirectory of ipod with non-bookmarkable media
118
132
  --version, -v
119
133
  show package version and exit
120
134
  --help, -h
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  task :default => [:test, :build]
2
+
2
3
  task :readme do
3
4
  readme = `bin/ipod help`
4
5
 
@@ -6,6 +7,8 @@ task :readme do
6
7
 
7
8
  [![Build Status](https://travis-ci.org/artm/ipod_db.png)](https://travis-ci.org/artm/ipod_db)
8
9
 
10
+ [![Code Climate](https://codeclimate.com/github/artm/ipod_db.png)](https://codeclimate.com/github/artm/ipod_db)
11
+
9
12
  __
10
13
 
11
14
  %w(sync ls rm).each do |subcommand|
data/bin/ipod CHANGED
@@ -105,6 +105,8 @@ Main {
105
105
  def sync
106
106
  books_path = params['books'].value
107
107
  songs_path = params['songs'].value
108
+ sanitize_filenames books_path
109
+ sanitize_filenames songs_path
108
110
  books = collect_tracks books_path
109
111
  books = spread(books)
110
112
  songs = collect_tracks songs_path
@@ -149,14 +151,28 @@ Main {
149
151
  end
150
152
 
151
153
  def collect_tracks path
152
- begin
153
- tracks = []
154
- Find.find(resolve_ipod_path path) do |filepath|
155
- tracks << ipod_path(filepath) if track? filepath
154
+ tracks = []
155
+ Find.find(resolve_ipod_path path) do |filepath|
156
+ tracks << ipod_path(filepath) if track? filepath
157
+ end
158
+ tracks
159
+ rescue Errno::ENOENT
160
+ []
161
+ end
162
+
163
+ def sanitize_filenames path
164
+ rename_us = []
165
+ Find.find(resolve_ipod_path path) do |filepath|
166
+ base_name = File.basename filepath
167
+ sane_name = IpodDB.sanitize_filename base_name
168
+ unless base_name == sane_name
169
+ dir = File.dirname filepath
170
+ rename_us << [ filepath, "#{dir}/#{sane_name}" ]
156
171
  end
157
- tracks
158
- rescue Errno::ENOENT
159
- []
172
+ end
173
+ rename_us.reverse_each do |from,to|
174
+ info "renaming #{from} to #{to}"
175
+ File.rename from, to
160
176
  end
161
177
  end
162
178
 
@@ -166,12 +182,13 @@ Main {
166
182
 
167
183
  def track_info track
168
184
  info = Map.new
169
- info['playcount'] = track.playcount if track.playcount > 0
170
- info['skipcount'] = track.skippedcount if track.skippedcount > 0
171
- if track.bookmarkflag && track.bookmarktime > 0
172
- pos = track.bookmarktime * 0.256 # ipod keeps time in 256 ms increments
185
+ info['playcount'] = track.playcount if track.fetch('playcount',0) > 0
186
+ info['skipcount'] = track.skippedcount if track.fetch('skippedcount',0) > 0
187
+ if track.fetch('bookmarktime',0) > 0
173
188
  abs_path = resolve_ipod_path track.filename
174
189
  total_time = track_length(abs_path)
190
+ # ipod keeps time in 256 ms increments
191
+ pos = [total_time, track.bookmarktime * 0.256].min
175
192
  if pos > IgnorePlaybackPosUnder && pos / total_time >= IgnoreProgressUnder
176
193
  info['pos'] = Pretty.seconds pos
177
194
  info['total'] = Pretty.seconds total_time
data/ipod_db.gemspec CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
24
24
  s.add_runtime_dependency 'taglib-ruby'
25
25
  s.add_runtime_dependency 'ruby-progressbar'
26
26
  s.add_runtime_dependency 'highline'
27
+ s.add_runtime_dependency 'activesupport'
27
28
 
28
29
  s.add_development_dependency 'rake'
29
30
  s.add_development_dependency 'bundler', '~> 1.3'
@@ -1,15 +1,16 @@
1
1
  require 'bindata'
2
2
 
3
- class Bool24 < BinData::Primitive
4
- uint24le :int
3
+ class IntBool < BinData::Primitive
5
4
  def get; self.int==0 ? false : true ; end
6
5
  def set(v) self.int = v ? 1 : 0 ; end
7
6
  end
8
7
 
9
- class Bool8 < BinData::Primitive
8
+ class Bool24 < IntBool
9
+ uint24le :int
10
+ end
11
+
12
+ class Bool8 < IntBool
10
13
  uint8 :int
11
- def get; self.int==0 ? false : true ; end
12
- def set(v) self.int = v ? 1 : 0 ; end
13
14
  end
14
15
 
15
16
  class EncodedString < BinData::Primitive
@@ -1,3 +1,3 @@
1
1
  class IpodDB
2
- VERSION = '0.2.5'
2
+ VERSION = '0.2.6'
3
3
  end
data/lib/ipod_db.rb CHANGED
@@ -3,6 +3,7 @@ require 'bindata'
3
3
  require 'bindata/itypes'
4
4
  require 'map'
5
5
  require 'pathname'
6
+ require 'active_support/inflector'
6
7
 
7
8
  require 'ipod_db/version'
8
9
 
@@ -155,6 +156,10 @@ class IpodDB
155
156
  "#{@root_dir}/iPod_Control/iTunes/iTunes#{suffix}"
156
157
  end
157
158
 
159
+ def self.sanitize_filename filename
160
+ ActiveSupport::Inflector.transliterate(filename, '_')
161
+ end
162
+
158
163
  class PState < BinData::Record
159
164
  endian :little
160
165
  uint8 :volume, initial_value: 29
data/lib/pretty.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module Pretty
2
2
  def Pretty.seconds seconds
3
+ seconds = seconds.to_i
3
4
  if seconds < 60
4
5
  "#{seconds} sec"
5
6
  else
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.5
4
+ version: 0.2.6
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-17 00:00:00.000000000 Z
12
+ date: 2013-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bindata
@@ -123,6 +123,22 @@ dependencies:
123
123
  - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: activesupport
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
126
142
  - !ruby/object:Gem::Dependency
127
143
  name: rake
128
144
  requirement: !ruby/object:Gem::Requirement