Module: IMP3::Commands::Artists

Included in:
IMP3::Commands
Defined in:
lib/imp3/commands/artists.rb

Instance Method Summary collapse

Instance Method Details

#artists_misspelled_commandObject

For every artist in iTunes,



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/imp3/commands/artists.rb', line 5

def artists_misspelled_command
  artist_choices = {}
  tagged = 0

  progress_bar artists, :complete_message => "Misspelled artist name scan complete." do |artist, bar|
    bar.increment :title => "Scanning artist '#{artist}'"
    normalized_artist_name = artist.normalized_without_words
    artist_choices[normalized_artist_name] ||= []
    artist_choices[normalized_artist_name] << artist.strip unless artist_choices[normalized_artist_name].include?(artist)
  end

  artist_names = {}
  tracks.each do |track|
    normalized_artist_name = track.artist.normalized_without_words
    unless artist_names.has_key?(normalized_artist_name)
      if artist_choices[normalized_artist_name] && artist_choices[normalized_artist_name].size > 1
        puts
        artist_name = choose("What is the correct artist name for #{track.artist}?", *(artist_choices[normalized_artist_name] << :"(Skip)"))
        artist_names[normalized_artist_name] = artist_name
      else
        artist_names[normalized_artist_name] = track.artist
      end
    end

    unless artist_names[normalized_artist_name].eql?(:"(Skip)") or track.artist.eql?(artist_names[normalized_artist_name])
      tagged += 1
      puts "Tagging track #{track.persistent_id} with artist name '#{artist_names[normalized_artist_name]}'"
      track.artist = ""
      track.artist = artist_names[normalized_artist_name]
    end
  end

  summary :tracks_tagged => tagged
end