music_meta_fixer 0.0.1 → 0.1.0

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: 1e00914b7ebaff094156bd180a5da95450c4985e
4
- data.tar.gz: d6ea2c04a3ec6dd37f2d654ced6827bac346811c
3
+ metadata.gz: aad28840dab9e9a13d95d47106b6284380895167
4
+ data.tar.gz: 6e4c61935fc4699a443e86b31229d9dd827a680e
5
5
  SHA512:
6
- metadata.gz: 0ddea86194905d8077cdae4c3c8e3a07a220a6d4c5cecbf74545a7e3f6c358ec9d6baff176b8775bee5a41aed914c0dd5d32c727ebbdb543e8a6aeb63bfa1185
7
- data.tar.gz: 3a6a037b2a8904631e4808870a47986daa96112215c8bf6bc89262422408c76ec75796369da6ad126e38fd2441f03e9520cb0c178f2794e07d9ed7258cbe386b
6
+ metadata.gz: 0844041ee93c4a9b592425c2a0c6326a43fd9a6e307ef40a13a5d065977c3cc29d1a3bda81e8134c24b234e923de9419f9ac476e6c586865091278fef94a0f17
7
+ data.tar.gz: a25dc02fc3af8997e22e81d7b20b80410fbd3250400166b278bfb18703d217239be1128378c8295a4c641de2fa5308ba54ff4ba90ea9241de2bc65867aa14eb9
data/README.md CHANGED
@@ -5,6 +5,12 @@ in your iTunes Library.
5
5
 
6
6
  # Install
7
7
 
8
+ Install taglib
9
+
10
+ $ brew install taglib
11
+
12
+ Install my gem
13
+
8
14
  $ gem install music_meta_fixer
9
15
 
10
16
  ## How to Use?
data/Rakefile CHANGED
@@ -4,6 +4,8 @@ require 'rake/testtask'
4
4
  Rake::TestTask.new do |t|
5
5
  t.libs << 'test'
6
6
  t.test_files = FileList['test/*test.rb']
7
+ # t.verbose = true
8
+ t.warning = true
7
9
  end
8
10
 
9
11
  desc "Run tests"
@@ -1,13 +1,22 @@
1
1
  module MusicMetaFixer
2
- module ItunesAPI
2
+ class ItunesAPI
3
3
  ITUNES_API_URL = 'https://itunes.apple.com/search?'
4
- LIMIT = 1
5
4
  MEDIA = 'music'
6
5
 
7
- def self.get_song_info(term)
8
- encoded_term = URI::encode(term)
9
- query = "term=#{encoded_term}&media=#{MEDIA}&limit=#{LIMIT}"
10
- res = Typhoeus.get(ITUNES_API_URL + query)
6
+ attr_accessor :term
7
+
8
+ def initialize(term, options={})
9
+ @term = term
10
+ @limit = options[:limit] || 1
11
+ end
12
+
13
+ def query
14
+ encoded_term = CGI.escape(@term)
15
+ ITUNES_API_URL + "term=#{encoded_term}&media=#{MEDIA}&limit=#{@limit}"
16
+ end
17
+
18
+ def get_song_info
19
+ res = Typhoeus.get(query)
11
20
 
12
21
  if res.code == 200
13
22
  json = JSON.parse res.body
@@ -18,7 +27,7 @@ module MusicMetaFixer
18
27
  new_music.artist = song_info["artistName"]
19
28
  new_music.genre = song_info["primaryGenreName"]
20
29
  new_music.album = song_info["collectionName"]
21
- new_music.year = song_info["releaseDate"].split("-").first
30
+ new_music.year = song_info["releaseDate"].split("-").first.to_i
22
31
  return new_music
23
32
  end
24
33
  end
@@ -13,10 +13,10 @@ module MusicMetaFixer
13
13
  SONG_END_PATH = %w(plist dict dict)
14
14
 
15
15
 
16
- def initialize
16
+ def initialize(options={})
17
17
  @counter = 0
18
18
  @path = []
19
- # @longest_counter = File.read('counter.txt').to_i
19
+ @pretty_printer = PrettyPrinter.new
20
20
  end
21
21
 
22
22
  def end_document
@@ -36,7 +36,7 @@ module MusicMetaFixer
36
36
  end
37
37
  elsif @path == SONG_VALUE_STRING_PATH && @key
38
38
  if @key == LOCATION
39
- @song_path = URI::decode(chars).gsub(/file:\/\/localhost/, "")
39
+ @song_path = CGI.unescape(chars).gsub(/file:\/\/localhost/, "")
40
40
  end
41
41
  end
42
42
  end
@@ -47,24 +47,22 @@ module MusicMetaFixer
47
47
  @song = TagEditor.get_song_info(@song_path)
48
48
 
49
49
  if @song
50
- @new_song = ItunesAPI.get_song_info("#{@song.artist} #{@song.name}")
50
+ itunes_api = ItunesAPI.new("#{@song.artist} #{@song.name}" )
51
+ @pretty_printer.print_itunes_api_query(itunes_api)
52
+ @new_song = itunes_api.get_song_info
51
53
 
52
- if @new_song
53
- puts "######## OLD #######"
54
- current_info = "Change:\n" + @song.pretty_string
55
- puts current_info
56
- puts "######## NEW ########\n"
57
- puts @new_song.pretty_string
54
+ if @new_song && (diff = @song.compare_to(@new_song)) && !diff.empty?
55
+ @pretty_printer.print_song_diff(@song, @new_song, diff)
58
56
 
59
- print "Change? "
57
+ puts "Change? (y/n)"
58
+ print "> "
60
59
  answer = gets.chomp
61
60
  if answer.match(/y/i)
62
- puts "Changing #{@song.name} at #{@song_path}"
61
+ puts "Changing #{@song.name} at #{@song_path}\n\n"
63
62
  TagEditor.change_tag_info(@song_path, @new_song)
64
63
  else
65
- puts "Moving on"
64
+ puts "Moving on\n\n"
66
65
  end
67
- puts ""
68
66
  end
69
67
  end
70
68
  end
@@ -0,0 +1,31 @@
1
+ module MusicMetaFixer
2
+ class PrettyPrinter
3
+ def initialize(options={})
4
+ end
5
+
6
+ def c
7
+ @c ||= Term::ANSIColor
8
+ end
9
+
10
+ def print_itunes_api_query(itunes_api)
11
+ puts "[#{c.blue 'INFO' }] Searching iTunes API with term '#{c.green itunes_api.term}' " \
12
+ "@ '#{c.green itunes_api.query}'"
13
+ end
14
+
15
+ def print_song_diff(song, compared_song, diff)
16
+ current_info = c.bold("##### OLD #####\n")
17
+ new_info = c.bold("##### NEW #####\n")
18
+
19
+ song.instance_variables.each do |key|
20
+ key = key.to_s.delete('@')
21
+ sym_key = key.to_sym
22
+
23
+ current_info_line = "#{key}: #{song.send(sym_key)}\n"
24
+ new_info_line = "#{key}: #{compared_song.send(sym_key)}\n"
25
+ current_info += diff.include?(sym_key) ? c.red("- " + current_info_line) : " " + current_info_line
26
+ new_info += diff.include?(sym_key) ? c.green("+ " + new_info_line) : " " + new_info_line
27
+ end
28
+ puts current_info + new_info
29
+ end
30
+ end
31
+ end
@@ -1,11 +1,20 @@
1
1
  module MusicMetaFixer
2
2
  class Song
3
- attr_accessor :name, :artist, :location, :genre, :album, :album_artist, :year
3
+ attr_accessor :name, :artist, :location, :genre, :album, :year
4
4
 
5
5
  def initialize name
6
6
  @name = name
7
7
  end
8
8
 
9
+ def compare_to(another_song)
10
+ diff = []
11
+ self.instance_variables.each do |key|
12
+ key = key.to_s.delete("@").to_sym
13
+ diff += [key] unless another_song.send(key) == self.send(key)
14
+ end
15
+ diff
16
+ end
17
+
9
18
  def pretty_string
10
19
  "Artist: #{artist}\n" \
11
20
  "Song: #{name}\n" \
@@ -1,3 +1,3 @@
1
1
  module MusicMetaFixer
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -3,13 +3,14 @@ require 'music_meta_fixer/song'
3
3
  require 'music_meta_fixer/itunes_lib_parser'
4
4
  require 'music_meta_fixer/itunes_api'
5
5
  require 'music_meta_fixer/tag_editor'
6
+ require 'music_meta_fixer/pretty_printer'
6
7
 
7
8
  require 'taglib'
8
9
  require 'nokogiri'
9
10
  require 'typhoeus'
10
- require 'uri'
11
- require 'open-uri'
12
11
  require 'json'
12
+ require 'term/ansicolor'
13
+ require 'cgi'
13
14
 
14
15
  module MusicMetaFixer
15
16
  def self.run
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_runtime_dependency 'taglib-ruby', '~> 0.6.0'
25
25
  spec.add_runtime_dependency 'nokogiri', '~> 1.6.0'
26
26
  spec.add_runtime_dependency 'typhoeus', '~> 0.6.6'
27
+ spec.add_runtime_dependency 'term-ansicolor', '~> 1.2.2'
27
28
  end
Binary file
@@ -3,18 +3,22 @@ require 'music_meta_fixer'
3
3
 
4
4
  class MusicMetaFixerTest < Test::Unit::TestCase
5
5
  def test_itunes_api
6
- song_info = MusicMetaFixer::ItunesAPI.get_song_info("Hardwell Apollo")
6
+ pretty_printer = MusicMetaFixer::PrettyPrinter.new
7
+ itunes_api = MusicMetaFixer::ItunesAPI.new("Hardwell Apollo")
8
+ puts "\n"
9
+ song_info = itunes_api.get_song_info
7
10
 
8
11
  assert_equal "Hardwell", song_info.artist
9
12
  assert_equal "Apollo (feat. Amba Shepherd)", song_info.name
10
13
  assert_equal "Dance" , song_info.genre
11
14
  assert_equal "2012", song_info.year
12
15
  assert_equal "Apollo (feat. Amba Shepherd) - Single", song_info.album
16
+ pretty_printer.print_itunes_api_query(itunes_api)
13
17
  end
14
18
 
15
19
  def test_tag_editor_getting_song_info
16
- # TODO Fill in below
17
- filepath = URI::decode('/path/to/Music/iTunes/iTunes%20Media/Music/Airbase/Pandemonium%20_%20Ocean%20Realm%20-%20Single/02%20Ocean%20Realm.m4p')
20
+ # TODO Export that bacon pancake
21
+ filepath = CGI.unescape ENV['bacon_pancakes']
18
22
  song_info = MusicMetaFixer::TagEditor.get_song_info(filepath)
19
23
 
20
24
  assert_equal "Airbase", song_info.artist
@@ -23,4 +27,17 @@ class MusicMetaFixerTest < Test::Unit::TestCase
23
27
  assert_equal 2004, song_info.year
24
28
  assert_equal "Pandemonium / Ocean Realm - Single", song_info.album
25
29
  end
30
+
31
+ def test_music_comparer
32
+ song = MusicMetaFixer::Song.new "Every Teardrop"
33
+ song.artist = "Swedish House Mafia"
34
+ song.genre = "Dance"
35
+
36
+ song_copy = song.clone
37
+ song_copy.artist = "Coldplay"
38
+ song_copy.genre = "Pop"
39
+
40
+ assert_equal [:artist, :genre], song.compare_to(song_copy)
41
+ end
42
+
26
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: music_meta_fixer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Villena
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-21 00:00:00.000000000 Z
11
+ date: 2013-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.6.6
83
+ - !ruby/object:Gem::Dependency
84
+ name: term-ansicolor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.2.2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.2.2
83
97
  description: Somewhat automated iTunes meta data fixer. Built on Ruby 2.0
84
98
  email:
85
99
  - mavoir6@gmail.com
@@ -97,6 +111,7 @@ files:
97
111
  - lib/music_meta_fixer.rb
98
112
  - lib/music_meta_fixer/itunes_api.rb
99
113
  - lib/music_meta_fixer/itunes_lib_parser.rb
114
+ - lib/music_meta_fixer/pretty_printer.rb
100
115
  - lib/music_meta_fixer/song.rb
101
116
  - lib/music_meta_fixer/tag_editor.rb
102
117
  - lib/music_meta_fixer/version.rb