rjl-itunes 0.1.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4fb59ab8673076305fb0813d5d13f0b075d831c6
4
- data.tar.gz: c817756e947c2a24757e8d2a0024d199b188c246
3
+ metadata.gz: 6b51f6db257d91c3da935e318c1023569e9f6a4c
4
+ data.tar.gz: d7e51904c214d5d5d48e10e9e8fcc43e79dceb20
5
5
  SHA512:
6
- metadata.gz: db5ad5e51298f53168feac23361abd9e7e75874626675573e6c472ad9f8e56b6140a382d7c904b886e94b147ee4a060835710911122cdf3cd595e67fd1c5491b
7
- data.tar.gz: 7a93638d0ecc070c885d70b7977dff897170757dbe2b64fce0eb0ec352763c5f016530ea73ebcd74811d6175121e7d6b179931eb60febaf2a879325e2914b4a3
6
+ metadata.gz: 74fb04c7e769fea3550fcecac0285f31acfc9ae0a94dce4aba2ce77ec5e0bd60218c52ef0fd24cd0d6222553579f2ec349c74337ad70c115a44e5c97f6c4de86
7
+ data.tar.gz: 2e78d219f048f10fae412016e85067348f07f2f442ecff65a95452d49fd162914f5123ce6a5b03d2ef6c2c37a50dc4473d9814a67b29957b2ae2f514c2c57a27
data/.gitignore CHANGED
@@ -13,5 +13,5 @@
13
13
  /pkg/
14
14
  /spec/reports/
15
15
  /tmp/
16
- rjl-itunes-0.1.gem
16
+ *.gem
17
17
  Gemfile.lock
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
2
 
4
- RSpec::Core::RakeTask.new(:spec)
3
+ Dir.glob('tasks/**/*.rake').each(&method(:import))
4
+
5
5
 
6
6
  task :default => :spec
@@ -9,11 +9,15 @@
9
9
  # (c) Richard Lyon 15 March, 2016
10
10
 
11
11
  $: << File.join(File.dirname(__FILE__), '..', 'lib')
12
- require 'rjl/itunes'
12
+ require 'rjl'
13
+
14
+ logger = get_logger
15
+ logger.info "fix_genres: " "#{"="*80}"
13
16
 
14
17
  # require 'metadata'
15
18
  require 'ruby-progressbar' # https://github.com/jfelchner/ruby-progressbar/wiki
16
19
 
20
+ puts "\n> Updating iTunes library genres from Allmusic.com...\n\n"
17
21
  itunes = RJL::Itunes.new
18
22
 
19
23
  progressbar = ProgressBar.create(
@@ -22,14 +26,22 @@ progressbar = ProgressBar.create(
22
26
  :total => itunes.albums.count)
23
27
 
24
28
  # main loop - fix album genre unless tagged 'proteected'
29
+ count = 0
25
30
  itunes.albums.each do |album|
26
31
  metadata = RJL::Metadata.new( album: album )
27
- progressbar.increment
28
32
  unless album.protected?
33
+ current_genre = album.genre
29
34
  new_genre = metadata.genre( album )
30
- unless new_genre == ""
35
+
36
+ unless new_genre == "" || (current_genre == new_genre )
31
37
  album.genre = metadata.genre( album )
32
38
  progressbar.log "#{album.album_artist}, '#{album.title}' -> #{new_genre}"
39
+ logger.info "fix_genres: " "#{album.album_artist}, '#{album.title}' -> #{new_genre}"
40
+ count += 1
33
41
  end
34
42
  end
43
+ progressbar.increment
35
44
  end
45
+
46
+ puts "\n> Attempted to updated genres for #{count} tracks (iCloud tracks not modified)"
47
+ puts "> See '/lib/logs/log.log' for details"
@@ -4,8 +4,12 @@ include Appscript
4
4
 
5
5
  module RJL
6
6
  # RJL_itunes::Itunes contains the public api for Itunes.
7
+ # @example
8
+ # require 'rjl/itunes'
9
+ #
10
+ # itunes = RJL::Itunes.new
11
+ # albums = itunes.albums
7
12
  # @api public
8
- # @example itunes = Itunes.new
9
13
 
10
14
  class Itunes
11
15
 
@@ -5,7 +5,7 @@ module RJL
5
5
  # Gets metadata for an album from allmusic.com, caching the results. See
6
6
  # [rjl-music](https://github.com/richardjlyon/allmusic) for details. Computes
7
7
  # a simplified genre by selecting the highest frequency genre and style in the
8
- # library and combining them in a string.
8
+ # library and combining them in a string. Creates a cache file `lib/cache/cache.db`
9
9
  class Metadata
10
10
 
11
11
  attr_reader :genres
@@ -17,7 +17,9 @@ module RJL
17
17
  # closes it on exit.
18
18
  # @param [Itunes] itunes the itunes client to generate metadata for
19
19
  def initialize( itunes )
20
- @db = Daybreak::DB.new 'cache.db', :default => {}
20
+
21
+ cache_path = File.join((File.dirname __dir__), 'cache/cache.db')
22
+ @db = Daybreak::DB.new cache_path, :default => {}
21
23
  @itunes = itunes
22
24
  at_exit { @db.close }
23
25
  end
@@ -1,3 +1,5 @@
1
+ require 'logger'
2
+
1
3
  # return true if tracks have only one value for 'parameter_name'
2
4
  def unique?( tracks, parameter_name )
3
5
  values = []
@@ -6,3 +8,12 @@ def unique?( tracks, parameter_name )
6
8
  end
7
9
  return values.uniq.length == 1
8
10
  end
11
+
12
+
13
+ # a logger
14
+ def get_logger
15
+ log_path = File.join((File.dirname __dir__), 'logs/log.log')
16
+ logger = Logger.new(log_path, 'daily')
17
+ logger.datetime_format = "%Y-%m-%d"
18
+ return logger
19
+ end
@@ -1,4 +1,4 @@
1
1
  module RJL
2
2
  # Version string
3
- VERSION = '0.1.1'
3
+ VERSION = '0.2'
4
4
  end
@@ -17,10 +17,13 @@ Gem::Specification.new do |spec|
17
17
  spec.version = RJL::VERSION
18
18
  spec.license = 'MIT'
19
19
 
20
- spec.add_development_dependency 'rake', '~> 10.4', '>= 10.4.2'
20
+ spec.add_development_dependency 'rake'
21
+ spec.add_development_dependency 'rspec'
22
+ spec.add_runtime_dependency 'nokogiri', '~> 1.6', '>= 1.6.7.2'
21
23
  spec.add_runtime_dependency 'rjl-allmusic', '~> 0.5', '>= 0.5'
22
24
  spec.add_runtime_dependency 'rb-scpt', '~> 1.0', '>= 1.0.1'
23
25
  spec.add_runtime_dependency 'ruby-progressbar', '~> 1.7', '>= 1.7.5'
24
26
  spec.add_runtime_dependency 'daybreak', '~> 0.3', '>= 0.3.0'
27
+ spec.add_runtime_dependency 'fuzzy-string-match', '~> 0.9', '>= 0.9.7'
25
28
 
26
29
  end
@@ -0,0 +1,3 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rjl-itunes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Lyon
@@ -14,22 +14,50 @@ dependencies:
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
18
25
  - !ruby/object:Gem::Version
19
- version: '10.4'
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
20
31
  - - ">="
21
32
  - !ruby/object:Gem::Version
22
- version: 10.4.2
33
+ version: '0'
23
34
  type: :development
24
35
  prerelease: false
25
36
  version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
26
44
  requirements:
27
45
  - - "~>"
28
46
  - !ruby/object:Gem::Version
29
- version: '10.4'
47
+ version: '1.6'
30
48
  - - ">="
31
49
  - !ruby/object:Gem::Version
32
- version: 10.4.2
50
+ version: 1.6.7.2
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.6'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.6.7.2
33
61
  - !ruby/object:Gem::Dependency
34
62
  name: rjl-allmusic
35
63
  requirement: !ruby/object:Gem::Requirement
@@ -110,11 +138,31 @@ dependencies:
110
138
  - - ">="
111
139
  - !ruby/object:Gem::Version
112
140
  version: 0.3.0
141
+ - !ruby/object:Gem::Dependency
142
+ name: fuzzy-string-match
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - "~>"
146
+ - !ruby/object:Gem::Version
147
+ version: '0.9'
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: 0.9.7
151
+ type: :runtime
152
+ prerelease: false
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: '0.9'
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: 0.9.7
113
161
  description: Manage album track genre in the library using data from allmusic.com
114
162
  email: richard@richardlyon.net
115
163
  executables:
116
164
  - console
117
- - fix_genres.rb
165
+ - fix_genres
118
166
  - setup
119
167
  extensions: []
120
168
  extra_rdoc_files: []
@@ -128,7 +176,7 @@ files:
128
176
  - README.md
129
177
  - Rakefile
130
178
  - bin/console
131
- - bin/fix_genres.rb
179
+ - bin/fix_genres
132
180
  - bin/setup
133
181
  - lib/rjl.rb
134
182
  - lib/rjl/album.rb
@@ -144,6 +192,7 @@ files:
144
192
  - spec/playlist.rb
145
193
  - spec/spec_helper.rb
146
194
  - spec/track_spec.rb
195
+ - tasks/rspec.rake
147
196
  homepage: https://github.com/richardjlyon/rjl-itunes
148
197
  licenses:
149
198
  - MIT
@@ -174,4 +223,3 @@ test_files:
174
223
  - spec/playlist.rb
175
224
  - spec/spec_helper.rb
176
225
  - spec/track_spec.rb
177
- has_rdoc: