class Lyricit::Itunes

Public Instance Methods

add_lyrics(lyrics, track) click to toggle source
# File lib/lyricit/itunes.rb, line 20
def add_lyrics lyrics, track
    %x(osascript -e "tell application \\"iTunes\\" to set lyrics of current track to \\"#{lyrics}\\" ")
end
db_id_of_current_track() click to toggle source
# File lib/lyricit/itunes.rb, line 16
def db_id_of_current_track
    %x(osascript -e 'tell application "iTunes" to database id of current track as string')
end
find_by_name(input) click to toggle source
# File lib/lyricit/itunes.rb, line 28
def find_by_name input

    dirty_track_names = %x(osascript -e "tell application \\"iTunes\\" to name of tracks of library playlist 1")
    track_names = dirty_track_names.split(',').map(&:strip)

    matching_names = track_names.select{|v| v.downcase.match(/#{input.downcase}/)}
    name_id = {}
    matching_names.each do |name|
        temp = %x(osascript -e "tell application \\"iTunes\\" to database id of (some track of library playlist 1 whose name is \\"#{name}\\")")
        name_id[name] = temp.strip
    end

    print_matching_results name_id
end
print_matching_results(name_id_hash) click to toggle source
set_lyrics_by_id(db_id, lyrics) click to toggle source
# File lib/lyricit/itunes.rb, line 24
def set_lyrics_by_id db_id, lyrics
    %x(osascript -e "tell application \\"iTunes\\" to set lyrics of (every track where database ID is #{db_id.strip}) to \\"#{lyrics}\\" ")
end
song_and_artist_by_current_track() click to toggle source
# File lib/lyricit/itunes.rb, line 3
def song_and_artist_by_current_track
    artist=%x(osascript -e 'tell application "iTunes" to artist of current track as string');
    name=%x(osascript -e 'tell application "iTunes" to name of current track as string');
    [artist, name]
end
song_and_artist_by_id(db_id) click to toggle source
# File lib/lyricit/itunes.rb, line 9
def song_and_artist_by_id db_id
    return nil if db_id.strip == ""
    artist = %x(osascript -e "tell application \\"iTunes\\" to get artist of (every track where database ID is #{db_id.strip})")
    name = %x(osascript -e "tell application \\"iTunes\\" to get name of (every track where database ID is #{db_id.strip})")
    [artist, name]
end