autotune 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b96bb0565047eb7e7e1742a16db9ee3077fe6e1
4
+ data.tar.gz: 356cb428a62f23eccc3acaa105ff382fea4d2862
5
+ SHA512:
6
+ metadata.gz: '06099031c410c4fe7857dcef7663a35ed158072c2344484826729730e89ca34160bc4b04d5afc56bf4c468f019dc5e31ae81ed8a4ecbd920e88062051c373bf1'
7
+ data.tar.gz: a99bce17579166142e012258cd9b95c3c12aa938175215f3133ea362ab960ceaab06ae5dff4c56c3b13f61b6637609d47a3a0f14c5b29f6cddcd3e3379c5f36d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4.1
4
+ before_install:
5
+ - gem update
6
+ - gem install bundler
7
+ install:
8
+ - bundle install --retry=3
9
+ script:
10
+ - gem build autotune.gemspec
11
+ - gem install autotune*.gem
12
+ addons:
13
+ apt:
14
+ packages:
15
+ - libtag1-dev
@@ -0,0 +1,19 @@
1
+ FROM ruby:2.4
2
+
3
+ MAINTAINER Dominic Philip <domi.a.philip@gmail.com>
4
+
5
+ RUN apt-get update && apt-get -y install cmake
6
+ RUN mkdir temp && cd temp && curl http://taglib.org/releases/taglib-1.11.1.tar.gz > /temp/taglib.tar.gz
7
+ RUN cd /temp && tar -xzvf taglib*
8
+ RUN cd /temp/taglib* && cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Release . -DBUILD_SHARED_LIBS=ON
9
+ RUN cd /temp/taglib* && make && make install
10
+ RUN gem install taglib-ruby
11
+ RUN rm -rf /temp
12
+ RUN apt-get autoremove && apt-get clean
13
+
14
+ RUN mkdir resources/
15
+ COPY . resources/
16
+ RUN cd /resources && gem build autotune.gemspec && gem install ./*.gem
17
+ RUN rm -rf /resources
18
+
19
+ CMD ["/bin/bash"]
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in AutoTune.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Dominic Philip
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # AutoTune [![Build Status](https://travis-ci.org/dominicap/auto-tune.svg?branch=master)](https://travis-ci.org/dominicap/auto-tune)
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/autotune`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'autotune'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install autotune
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dominicap/auto-tune.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'autotune/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "autotune"
7
+ spec.version = AutoTune::VERSION
8
+ spec.authors = ["Dominic Antony Philip"]
9
+ spec.email = ["domi.a.philip@gmail.com"]
10
+
11
+ spec.summary = "A music auto-tagging library using the iTunes API"
12
+ spec.description = "AutoTune is a library that automates the task of adding metadata to music with the help of the iTunes Affiliates Search API."
13
+ spec.homepage = "https://github.com/dominicap/auto-tune"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.13"
24
+ spec.add_development_dependency "rake", "~> 12.0"
25
+ spec.add_development_dependency "rspec", "~> 3.4"
26
+
27
+ spec.add_runtime_dependency "taglib-ruby", "~> 0.7.0", ">= 0.7.0"
28
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "autotune"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'autotune'
5
+
6
+ options = { album: nil, artist: nil, directory: nil, deluxe: false, clean: false, single: false }
7
+ ARGV << '--help' if ARGV.empty?
8
+
9
+ overview_msg = 'OVERVIEW: A music auto-tagging library using the iTunes API'
10
+ usage_msg = 'USAGE: autotune [options] <inputs>'
11
+ options_msg = 'OPTIONS:'
12
+
13
+ option_parser = OptionParser.new do |opts|
14
+ opts.banner = overview_msg + "\n\n" + usage_msg + "\n\n" + options_msg + "\n"
15
+
16
+ album_help_msg = 'Pass in album name as argument'
17
+ opts.on('-a', '--album <album>', album_help_msg) do |album|
18
+ options[:album] = album.to_s
19
+ end
20
+
21
+ artist_help_msg = 'Pass in artist name as argument'
22
+ opts.on('-s', '--artist <artist>', artist_help_msg) do |artist|
23
+ options[:artist] = artist.to_s
24
+ end
25
+
26
+ directory_help_msg = 'Pass in the directory path as argument'
27
+ opts.on('-d', '--directory <directory>', directory_help_msg) do |directory|
28
+ unless File.exist?(File.expand_path(directory.to_s))
29
+ abort 'autotune: error: directory path given does not exist'
30
+ end
31
+ options[:directory] = File.expand_path(directory.to_s)
32
+ end
33
+
34
+ clean_help_msg = 'Use clean version of album, if applicable'
35
+ opts.on('-c', '--clean', clean_help_msg) do |clean|
36
+ options[:clean] = true unless clean.nil?
37
+ end
38
+
39
+ deluxe_help_msg = 'Use deluxe version of album, if applicable'
40
+ opts.on('-x', '--deluxe', deluxe_help_msg) do |deluxe|
41
+ options[:deluxe] = true unless deluxe.nil?
42
+ end
43
+
44
+ single_help_msg = 'Use single version of album, if applicable'
45
+ opts.on('-l', '--single', single_help_msg) do |single|
46
+ options[:single] = true unless single.nil?
47
+ end
48
+
49
+ opts.on('-h', '--help', 'Displays available options') do
50
+ puts opts
51
+ exit
52
+ end
53
+
54
+ opts.on('-v', '--version', 'Displays the version number') do
55
+ puts 'autotune version ' + AutoTune::VERSION
56
+ exit
57
+ end
58
+ end
59
+
60
+ begin
61
+ option_parser.parse!
62
+ rescue OptionParser::InvalidOption
63
+ abort 'autotune: error: invalid option(s)'
64
+ rescue OptionParser::MissingArgument
65
+ abort 'autotune: error: too few arguments'
66
+ end
67
+
68
+ options.each do |_option, argument|
69
+ abort 'autotune: error: too few arguments' if argument.nil?
70
+ end
71
+
72
+ unless AutoTune::Util.os == 'macos'
73
+ abort 'autotune: error: operating system not compatible'
74
+ end
75
+
76
+ paths = AutoTune::Util.paths(options[:directory])
77
+ album_tags = AutoTune::Obtainer.get_tags(options[:album], options[:artist], options[:clean], options[:deluxe])
78
+
79
+ album_details = AutoTune::Obtainer.get_album_details(options[:album], options[:artist], options[:clean], options[:deluxe])
80
+
81
+ if album_tags['resultCount'].to_i.zero?
82
+ abort "autotune: error: no results from iTunes with given arguments"
83
+ end
84
+
85
+ AutoTune::Obtainer.get_artwork(album_tags)
86
+
87
+ album_artist = AutoTune::Obtainer.get_album_artist(album_details)
88
+ genre_id = AutoTune::Obtainer.get_genre_id(album_details)
89
+ copyright = AutoTune::Obtainer.get_copyright(album_details)
90
+
91
+ paths.each do |path|
92
+ track_number = AutoTune::Obtainer.get_track_number(path)
93
+
94
+ until track_number > 0
95
+ print "Please enter the track number for #{File.basename(path)}: "
96
+ track_number = STDIN.gets.chomp.to_i
97
+ end
98
+
99
+ tune_tags = AutoTune::Util.parse(album_tags, track_number).push(album_artist, genre_id, copyright)
100
+
101
+ AutoTune::Designator.set_all(tune_tags, path)
102
+
103
+ end
104
+
105
+ system('rm /var/tmp/artwork.jpg')
@@ -0,0 +1,6 @@
1
+ module AutoTune
2
+ require "autotune/designator"
3
+ require "autotune/obtainer"
4
+ require "autotune/util"
5
+ require "autotune/version"
6
+ end
@@ -0,0 +1,319 @@
1
+ require 'taglib'
2
+
3
+ module AutoTune
4
+ class Designator
5
+ def self.set_artist_id(artist_id, song)
6
+ if File.exists? song
7
+ if song =~ /.*\.M4A$/i
8
+ TagLib::MP4::File.open(song) do |tune|
9
+ unless artist_id.nil?
10
+ item = TagLib::MP4::Item.from_int(artist_id)
11
+ tune.tag.item_list_map.insert('atID', item)
12
+ tune.save
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ def self.set_playlist_id(playlist_id, song)
20
+ if File.exists? song
21
+ if song =~ /.*\.M4A$/i
22
+ TagLib::MP4::File.open(song) do |tune|
23
+ unless playlist_id.nil?
24
+ item = TagLib::MP4::Item.from_int(playlist_id)
25
+ tune.tag.item_list_map.insert('plID', item)
26
+ tune.save
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ def self.set_catalogue_id(catalogue_id, song)
34
+ if File.exists? song
35
+ if song =~ /.*\.M4A$/i
36
+ TagLib::MP4::File.open(song) do |tune|
37
+ unless catalogue_id.nil?
38
+ item = TagLib::MP4::Item.from_int(catalogue_id)
39
+ tune.tag.item_list_map.insert('cnID', item)
40
+ tune.save
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ def self.set_artist(artist, song)
48
+ if File.exists? song
49
+ TagLib::FileRef.open(song) do |tune|
50
+ unless tune.null?
51
+ tune.tag.artist = artist unless artist.nil?
52
+ tune.save
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ def self.set_album(album, song)
59
+ if File.exists? song
60
+ TagLib::FileRef.open(song) do |tune|
61
+ unless tune.null?
62
+ tune.tag.album = album unless album.nil?
63
+ tune.save
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ def self.set_title(title, song)
70
+ if File.exists? song
71
+ TagLib::FileRef.open(song) do |tune|
72
+ unless tune.null?
73
+ tune.tag.title = title unless title.nil?
74
+ tune.save
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ def self.set_release_date(release_date, song)
81
+ if File.exists? song
82
+ if song =~ /.*\.M4A$/i
83
+ TagLib::MP4::File.open(song) do |tune|
84
+ unless release_date.nil?
85
+ item = TagLib::MP4::Item.from_string_list([release_date])
86
+ tune.tag.item_list_map.insert('©day', item)
87
+ tune.save
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ def self.set_rating(rating, song)
95
+ if File.exists? song
96
+ if song =~ /.*\.M4A$/i
97
+ TagLib::MP4::File.open(song) do |tune|
98
+ unless rating.nil?
99
+ if rating.include? 'clean'
100
+ item = TagLib::MP4::Item.from_int(2)
101
+ tune.tag.item_list_map.insert('rtng', item)
102
+ tune.save
103
+ elsif rating.include? 'explicit'
104
+ item = TagLib::MP4::Item.from_int(1)
105
+ tune.tag.item_list_map.insert('rtng', item)
106
+ tune.save
107
+ elsif rating.include? 'notExplicit'
108
+ item = TagLib::MP4::Item.from_int(0)
109
+ tune.tag.item_list_map.insert('rtng', item)
110
+ tune.save
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ def self.set_genre(genre, song)
119
+ if File.exists? song
120
+ TagLib::FileRef.open(song) do |tune|
121
+ unless tune.null?
122
+ tune.tag.genre = genre unless genre.nil?
123
+ tune.save
124
+ end
125
+ end
126
+ end
127
+ end
128
+
129
+ def self.track_number(track_number, song)
130
+ if File.exists? song
131
+ TagLib::FileRef.open(song) do |tune|
132
+ unless tune.null?
133
+ tune.tag.track = track_number unless track_number.nil?
134
+ tune.save
135
+ end
136
+ end
137
+ end
138
+ end
139
+
140
+ def self.set_artwork(artwork, song)
141
+ if File.exists? song
142
+ if song =~ /.*\.M4A$/i
143
+ TagLib::MP4::File.open(song) do |tune|
144
+ unless artwork.nil?
145
+ image_data = File.open(artwork, 'rb') { |f| f.read }
146
+ cover_art = TagLib::MP4::CoverArt.new(TagLib::MP4::CoverArt::JPEG, image_data)
147
+ item = TagLib::MP4::Item.from_cover_art_list([cover_art])
148
+ tune.tag.item_list_map.insert('covr', item)
149
+ tune.save
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
155
+
156
+ def self.set_copyright(copyright, song)
157
+ if File.exists? song
158
+ if song =~ /.*\.M4A$/i
159
+ TagLib::MP4::File.open(song) do |tune|
160
+ unless copyright.nil?
161
+ item = TagLib::MP4::Item.from_string_list([copyright])
162
+ tune.tag.item_list_map.insert('cprt', item)
163
+ tune.save
164
+ end
165
+ end
166
+ end
167
+ end
168
+ end
169
+
170
+ def self.set_album_artist_name(album_artist, song)
171
+ if File.exists? song
172
+ if song =~ /.*\.M4A$/i
173
+ TagLib::MP4::File.open(song) do |tune|
174
+ unless album_artist.nil?
175
+ item = TagLib::MP4::Item.from_string_list([album_artist])
176
+ tune.tag.item_list_map.insert('aART', item)
177
+ tune.save
178
+ end
179
+ end
180
+ end
181
+ end
182
+ end
183
+
184
+ def self.set_catalogue_id(catalogue_id, song)
185
+ if File.exists? song
186
+ if song =~ /.*\.M4A$/i
187
+ TagLib::MP4::File.open(song) do |tune|
188
+ unless catalogue_id.nil?
189
+ item = TagLib::MP4::Item.from_int(catalogue_id)
190
+ tune.tag.item_list_map.insert('cnID', item)
191
+ tune.save
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+
198
+ def self.set_track_number(track_number, total_tracks, song)
199
+ if File.exists? song
200
+ if song =~ /.*\.M4A$/i
201
+ TagLib::MP4::File.open(song) do |tune|
202
+ unless track_number.nil? || total_tracks.nil?
203
+ item = TagLib::MP4::Item.from_int_pair([track_number, total_tracks])
204
+ tune.tag.item_list_map.insert('trkn', item)
205
+ tune.save
206
+ end
207
+ end
208
+ end
209
+ end
210
+ end
211
+
212
+ def self.set_disk_number(disk_number, total_disks, song)
213
+ if File.exists? song
214
+ if song =~ /.*\.M4A$/i
215
+ TagLib::MP4::File.open(song) do |tune|
216
+ unless disk_number.nil? || total_disks.nil?
217
+ item = TagLib::MP4::Item.from_int_pair([disk_number, total_disks])
218
+ tune.tag.item_list_map.insert('disk', item)
219
+ tune.save
220
+ end
221
+ end
222
+ end
223
+ end
224
+ end
225
+
226
+ def self.set_playlist_id(playlist_id, song)
227
+ if File.exists? song
228
+ if song =~ /.*\.M4A$/i
229
+ TagLib::MP4::File.open(song) do |tune|
230
+ unless playlist_id.nil?
231
+ item = TagLib::MP4::Item.from_int(playlist_id)
232
+ tune.tag.item_list_map.insert('plID', item)
233
+ tune.save
234
+ end
235
+ end
236
+ end
237
+ end
238
+ end
239
+
240
+ def self.set_composer_id(composer_id, song)
241
+ if File.exists? song
242
+ if song =~ /.*\.M4A$/i
243
+ TagLib::MP4::File.open(song) do |tune|
244
+ unless composer_id.nil?
245
+ item = TagLib::MP4::Item.from_int(composer_id)
246
+ tune.tag.item_list_map.insert('cmID', item)
247
+ tune.save
248
+ end
249
+ end
250
+ end
251
+ end
252
+ end
253
+
254
+ def self.set_genre_id(genre_id, song)
255
+ if File.exists? song
256
+ if song =~ /.*\.M4A$/i
257
+ TagLib::MP4::File.open(song) do |tune|
258
+ unless genre_id.nil?
259
+ item = TagLib::MP4::Item.from_int(genre_id)
260
+ tune.tag.item_list_map.insert('geID', item)
261
+ tune.save
262
+ end
263
+ end
264
+ end
265
+ end
266
+ end
267
+
268
+ def self.set_tempo(tempo, song)
269
+ if File.exists? song
270
+ if song =~ /.*\.M4A$/i
271
+ TagLib::MP4::File.open(song) do |tune|
272
+ unless tempo.nil?
273
+ item = TagLib::MP4::Item.from_int(tempo)
274
+ tune.tag.item_list_map.insert('tmpo', item)
275
+ tune.save
276
+ end
277
+ end
278
+ end
279
+ end
280
+ end
281
+
282
+ def self.set_composer(composer, song)
283
+ if File.exists? song
284
+ if song =~ /.*\.M4A$/i
285
+ TagLib::MP4::File.open(song) do |tune|
286
+ unless composer.nil?
287
+ item = TagLib::MP4::Item.from_string_list([composer])
288
+ tune.tag.item_list_map.insert('©wrt', item)
289
+ tune.save
290
+ end
291
+ end
292
+ end
293
+ end
294
+ end
295
+
296
+ def self.set_all(tune_tags, song)
297
+
298
+
299
+
300
+
301
+ set_artist_id(tune_tags.at(0), song)
302
+ set_playlist_id(tune_tags.at(1), song)
303
+ set_catalogue_id(tune_tags.at(2), song)
304
+ set_artist(tune_tags.at(3), song)
305
+ set_album(tune_tags.at(4), song)
306
+ set_title(tune_tags.at(5), song)
307
+ set_release_date(tune_tags.at(7), song)
308
+ set_rating(tune_tags.at(9), song)
309
+ set_disk_number(tune_tags.at(11), tune_tags.at(10), song)
310
+ set_track_number(tune_tags.at(13), tune_tags.at(12), song)
311
+ set_genre(tune_tags.at(17), song)
312
+ set_album_artist_name(tune_tags.at(19), song)
313
+ set_genre_id(tune_tags.at(20), song)
314
+ set_copyright(tune_tags.at(21), song)
315
+ set_composer('', song)
316
+ set_artwork('/var/tmp/artwork.jpg', song)
317
+ end
318
+ end
319
+ end
@@ -0,0 +1,85 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'taglib'
4
+
5
+ module AutoTune
6
+ class Obtainer
7
+ def self.get_tags(album, artist, clean, deluxe)
8
+ album_id = get_album_id(album, artist, clean, deluxe)
9
+ lookup = "https://itunes.apple.com/lookup?id=#{album_id}&entity=song"
10
+ return JSON.parse(Net::HTTP.get(URI.parse(lookup)))
11
+ end
12
+
13
+ def self.get_album_details(album, artist, clean, deluxe)
14
+ album_id = get_album_id(album, artist, clean, deluxe)
15
+ lookup = "https://itunes.apple.com/lookup?id=#{album_id}"
16
+ return JSON.parse(Net::HTTP.get(URI.parse(lookup)))
17
+ end
18
+
19
+ def self.get_artwork(album_details)
20
+ artwork_url = album_details.dig('results', 0, 'artworkUrl100')
21
+ artwork_url = artwork_url.gsub!(/100x100bb.jpg/, '1000000000x1000000000bb.jpg')
22
+ File.write('/var/tmp/artwork.jpg', Net::HTTP.get(URI.parse(URI.encode(artwork_url.to_s))))
23
+ end
24
+
25
+ def self.get_track_number(song)
26
+ TagLib::FileRef.open(song) do |tune|
27
+ return tune.tag.track unless tune.nil?
28
+ end
29
+ end
30
+
31
+ def self.get_genre_id(album_details)
32
+ genre_name = album_details.dig('results', 0, 'primaryGenreName')
33
+ genre_appendix_lookup =
34
+ 'http://itunes.apple.com/WebObjects/MZStoreServices.woa/ws/genres'
35
+ unless genre_name.nil?
36
+ genre_appendix = JSON.parse(Net::HTTP.get(URI.parse(genre_appendix_lookup)))
37
+ genre_appendix['34']['subgenres'].each { |genres|
38
+ genres.each { |genre|
39
+ unless genre.nil?
40
+ if genre['name'].to_s.include? genre_name
41
+ return genre['id'].to_i
42
+ end
43
+ end
44
+ }
45
+ }
46
+ end
47
+ end
48
+
49
+ def self.get_copyright(album_details)
50
+ return album_details.dig('results', 0, 'copyright').to_s
51
+ end
52
+
53
+ def self.get_album_artist(album_details)
54
+ return album_details.dig('results', 0, 'artistName').to_s
55
+ end
56
+
57
+ # TODO: Refactor this and etc. Also, add exclusive to deluxe option
58
+ def self.get_album_id(album, artist, clean, deluxe)
59
+ lookup = 'https://itunes.apple.com/search?term='
60
+ query = (artist + ' ' + album).downcase.tr!(' ', '+') + '&entity=album'
61
+ result_hash = JSON.parse(Net::HTTP.get(URI.parse(lookup + query)))
62
+ unless result_hash['resultCount'].to_i.zero?
63
+ (0..result_hash['resultCount'].to_i).each do |key|
64
+ itunes_rating = result_hash.dig('results', key, 'contentAdvisoryRating')
65
+ itunes_rating = result_hash.dig('results', key, 'collectionExplicitness') if itunes_rating.nil?
66
+ if (itunes_rating == 'Clean' || itunes_rating == 'notExplicit') && clean
67
+ if (result_hash.dig('results', key, 'collectionName').include? 'Deluxe') && deluxe
68
+ return result_hash.dig('results', key, 'collectionId')
69
+ elsif !(result_hash.dig('results', key, 'collectionName').include? 'Deluxe') && !deluxe
70
+ return result_hash.dig('results', key, 'collectionId')
71
+ end
72
+ elsif (itunes_rating == 'Explicit' || itunes_rating == 'notExplicit') && !clean
73
+ if (result_hash.dig('results', key, 'collectionName').include? 'Deluxe') && deluxe
74
+ return result_hash.dig('results', key, 'collectionId')
75
+ elsif !(result_hash.dig('results', key, 'collectionName').include? 'Deluxe') && !deluxe
76
+ return result_hash.dig('results', key, 'collectionId')
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ private_class_method :get_album_id
84
+ end
85
+ end
@@ -0,0 +1,40 @@
1
+ require 'find'
2
+ require 'json'
3
+
4
+ module AutoTune
5
+ class Util
6
+
7
+ ITUNES_TAG_KEYS = Array.new.push('artistId', 'collectionId', 'trackId', 'artistName',
8
+ 'collectionName', 'trackName', 'artworkUrl100',
9
+ 'releaseDate', 'collectionExplicitness',
10
+ 'trackExplicitness', 'discCount', 'discNumber',
11
+ 'trackCount', 'trackNumber', 'trackTimeMillis',
12
+ 'country', 'currency', 'primaryGenreName')
13
+
14
+ def self.paths(directory)
15
+ Array.new(Find.find(directory).select { |p| /.*\.M4A$/i =~ p })
16
+ end
17
+
18
+ def self.parse(result_hash, track_number)
19
+ (0..result_hash['resultCount'].to_i).each { |key|
20
+ itunes_track_number = result_hash.dig('results', key, 'trackNumber')
21
+ if track_number == itunes_track_number.to_i
22
+ info = Array.new
23
+ (0..ITUNES_TAG_KEYS.length).each { |index|
24
+ info.push(result_hash.dig('results', key, ITUNES_TAG_KEYS[index]))
25
+ }
26
+ return info
27
+ end
28
+ }
29
+ end
30
+
31
+ def self.os
32
+ case RUBY_PLATFORM
33
+ when /darwin|mac os/
34
+ return 'macos'
35
+ else
36
+ raise SystemCallError.new('Operating System is not supported', 1)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module AutoTune
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: autotune
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dominic Antony Philip
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: taglib-ruby
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.7.0
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 0.7.0
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: 0.7.0
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 0.7.0
75
+ description: AutoTune is a library that automates the task of adding metadata to music
76
+ with the help of the iTunes Affiliates Search API.
77
+ email:
78
+ - domi.a.philip@gmail.com
79
+ executables:
80
+ - autotune
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - ".gitignore"
85
+ - ".rspec"
86
+ - ".travis.yml"
87
+ - Dockerfile
88
+ - Gemfile
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - autotune.gemspec
93
+ - bin/console
94
+ - bin/setup
95
+ - exe/autotune
96
+ - lib/autotune.rb
97
+ - lib/autotune/designator.rb
98
+ - lib/autotune/obtainer.rb
99
+ - lib/autotune/util.rb
100
+ - lib/autotune/version.rb
101
+ homepage: https://github.com/dominicap/auto-tune
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.6.11
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: A music auto-tagging library using the iTunes API
125
+ test_files: []