Class: ItunesController::WindowsITunesController

Inherits:
BaseITunesController show all
Defined in:
lib/itunesController/windows_itunescontroller.rb

Instance Method Summary collapse

Constructor Details

#initializeWindowsITunesController

The constructor



33
34
35
36
# File 'lib/itunesController/windows_itunescontroller.rb', line 33

def initialize
    @iTunes = WIN32OLE.new('iTunes.Application')
    @libraryPlaylists=@iTunes.LibraryPlaylist
end

Instance Method Details

#addFilesToLibrary(files) ⇒ Array[ItunesController::Track]

Used to add a list of files to the itunes library

Parameters:

  • A (Array[String])

    list of files to add to the itunes library

Returns:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/itunesController/windows_itunescontroller.rb', line 63

def addFilesToLibrary(files)
    tracks=[]
    files.each do | file |
        if (!File.exist?(file))
            ItunesController::ItunesControllerLogging::error("Unable to find file #{file}")
        else
            itracks=@libraryPlaylists.AddFile(file)   
            if (itracks!=nil)
                itracks=itracks.Tracks                                                         
                for i in (1..itracks.Count())                      
                    itrack=itracks.Item(i)
                    track=ItunesController::Track.new(file,itrack.TrackDatabaseID,itrack.Name)
                    tracks.push(track)
                end                                                             
            else
                ItunesController::ItunesControllerLogging::error("Unable to add file '#{file}'")                         
            end
        end
    end

    return tracks;
end

#getTrackCountNumber

Used to find the number of tracks in the library

Returns:

  • (Number)

    The number of tracks



117
118
119
# File 'lib/itunesController/windows_itunescontroller.rb', line 117

def getTrackCount()                          
    return @libraryPlaylists.Tracks.Count()
end

#getTrackDatabaseId(track) ⇒ Object

This method is abstract.

Must be overridden

Used to get the database of a itunes track

Parameters:

  • track

    the track

Returns:

  • The database id



141
142
143
# File 'lib/itunesController/windows_itunescontroller.rb', line 141

def getTrackDatabaseId(track)
    return track.TrackDatabaseID()
end

#getTracks(&b) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/itunesController/windows_itunescontroller.rb', line 86

def getTracks(&b)
    ItunesController::ItunesControllerLogging::debug("Retriving track information...")
    playlist=@libraryPlaylists
    fileTracks = playlist.Tracks
    size = fileTracks.Count()
    count = 1
    for count in (1..size)
        track=fileTracks.Item(count)
        location=track.location            
        dead=false
        if (location!=nil)                   
            if (!File.exist?(location))
                dead = true
            end
        else
            dead = true
        end                
        if (count % 1000 == 0)
            ItunesController::ItunesControllerLogging::debug("Found tracks #{count} of #{size}")
        end
        if (track.name!=nil)
            b.call(ItunesController::Track.new(location,track.TrackDatabaseID,track.name),count,size,dead)
        end
        count=count+1
    end
    ItunesController::ItunesControllerLogging::debug("Found tracks #{count-1} of #{size}")
    return size
end

#refreshTracks(tracks) ⇒ Object

Used to tell iTunes to refresh a list of tracks data from the info stored in the files

Parameters:

  • tracks (Array)

    A list of tracks to fresh



46
47
48
49
50
# File 'lib/itunesController/windows_itunescontroller.rb', line 46

def refreshTracks(tracks)
    tracks.reverse.each do | track |                
        track.UpdateInfoFromFile
    end
end

#removeTracksFromLibrary(tracks) ⇒ Object

Used to remove tracks from the libaray

Parameters:

  • tracks (Array)

    A list of tracks to remove from the itunes libaray



54
55
56
57
58
# File 'lib/itunesController/windows_itunescontroller.rb', line 54

def removeTracksFromLibrary(tracks)
    tracks.reverse.each do | track |               
        track.Delete
    end
end

#searchLibrary(term) ⇒ Array

Used to search the itunes library

Parameters:

  • term

    The search term

Returns:

  • (Array)

    a list of iTunes track that match the search term



124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/itunesController/windows_itunescontroller.rb', line 124

def searchLibrary(term)
    tracks=[]
    playlist=@libraryPlaylists                             
    foundTracks = playlist.Search(term,1)            
    if (foundTracks!=nil)
        foundTracks.each do | t |
            tracks.push(t)
        end
    end
   
    return tracks
end

#versionString

Used to get the iTunes version

Returns:

  • (String)

    The itunes version



40
41
42
# File 'lib/itunesController/windows_itunescontroller.rb', line 40

def version
    return @iTunes.version.to_s+" (Windows)"
end