class Spotify::Music::Importer::SpotifyLibrary

Public Class Methods

new(client) click to toggle source
# File lib/spotify/music/importer/spotify_library.rb, line 6
def initialize(client)
  @client = client
  @missing = []
end

Public Instance Methods

find_and_add_to_library(record, results, index) click to toggle source
# File lib/spotify/music/importer/spotify_library.rb, line 11
def find_and_add_to_library(record, results, index)
  match = CollectionMatch.new(record, results)

  if results.found_match?
    print "[#{index+1}] "
    if match.full_match
      print results.to_s.green
      add_to_library(results.id)
    elsif match.name_match
      print results.to_s.yellow
      add_to_library(results.id)
    elsif match.album_match
      print results.to_s.colorize(:orange)
      add_to_library(results.id)
      puts "Collection Record: #{record}"
    else
      print results
      add_to_library(results.id)
      puts "Collection Record: #{record}"
    end
  else
    puts "not found - #{record}".red
    @missing << record
  end
end
missing() click to toggle source
# File lib/spotify/music/importer/spotify_library.rb, line 37
def missing
  @missing
end

Private Instance Methods

add_to_library(track_id) click to toggle source
# File lib/spotify/music/importer/spotify_library.rb, line 43
def add_to_library(track_id)
  if @client.library?(track_id).first
    puts " Ignored #{track_id}"
  else
    print ' Adding '
    @client.add_library_tracks(track_id)
    puts " Added #{track_id}"
  end
end