music_meta_fixer 0.0.1 → 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.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/Rakefile +2 -0
- data/lib/music_meta_fixer/itunes_api.rb +16 -7
- data/lib/music_meta_fixer/itunes_lib_parser.rb +12 -14
- data/lib/music_meta_fixer/pretty_printer.rb +31 -0
- data/lib/music_meta_fixer/song.rb +10 -1
- data/lib/music_meta_fixer/version.rb +1 -1
- data/lib/music_meta_fixer.rb +3 -2
- data/music_meta_fixer.gemspec +1 -0
- data/screenshots/screen1.png +0 -0
- data/test/music_meta_fixer_test.rb +20 -3
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aad28840dab9e9a13d95d47106b6284380895167
|
4
|
+
data.tar.gz: 6e4c61935fc4699a443e86b31229d9dd827a680e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0844041ee93c4a9b592425c2a0c6326a43fd9a6e307ef40a13a5d065977c3cc29d1a3bda81e8134c24b234e923de9419f9ac476e6c586865091278fef94a0f17
|
7
|
+
data.tar.gz: a25dc02fc3af8997e22e81d7b20b80410fbd3250400166b278bfb18703d217239be1128378c8295a4c641de2fa5308ba54ff4ba90ea9241de2bc65867aa14eb9
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -1,13 +1,22 @@
|
|
1
1
|
module MusicMetaFixer
|
2
|
-
|
2
|
+
class ItunesAPI
|
3
3
|
ITUNES_API_URL = 'https://itunes.apple.com/search?'
|
4
|
-
LIMIT = 1
|
5
4
|
MEDIA = 'music'
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
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 =
|
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
|
-
|
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
|
-
|
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
|
-
|
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, :
|
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" \
|
data/lib/music_meta_fixer.rb
CHANGED
@@ -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
|
data/music_meta_fixer.gemspec
CHANGED
data/screenshots/screen1.png
CHANGED
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
|
-
|
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
|
17
|
-
filepath =
|
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
|
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-
|
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
|