private static List <Track> BuildLibraryTrackList(iTunesLibrary library, DisplayMessage dm, BackgroundWorker bgw, DoWorkEventArgs bgwArgs)
        {
            dm(new OutputMessage("Scanning track library...", MessageSeverity.Always));

            List <Track> trackList = new List <Track>();

            IITPlaylist libraryPlaylist = library.GetLibraryPlaylist();

            if (libraryPlaylist != null)
            {
                int trackCount        = libraryPlaylist.Tracks.Count;
                int currentTrackIndex = 0;

                foreach (IITTrack track in libraryPlaylist.Tracks)
                {
                    if (bgw.CancellationPending == true)
                    {
                        break;
                    }

                    double percentComplete    = Math.Floor(((double)currentTrackIndex / (double)trackCount) * 100.0);
                    int    intPercentComplete = (int)percentComplete;
                    bgw.ReportProgress(intPercentComplete);
                    currentTrackIndex++;

                    if (
                        track is IITFileOrCDTrack &&
                        ((IITFileOrCDTrack)track).Kind == ITTrackKind.ITTrackKindFile &&
                        ((IITFileOrCDTrack)track).VideoKind == ITVideoKind.ITVideoKindNone &&
                        ((IITFileOrCDTrack)track).Podcast == false &&
                        string.Compare(((IITFileOrCDTrack)track).Genre, "Voice Memo") != 0
                        )
                    {
                        try
                        {
                            IITFileOrCDTrack fileTrack = (IITFileOrCDTrack)track;
                            Track            tr        = Track.GetTrack(fileTrack, library.GetITunesApp());
                            trackList.Add(tr);
                        }
                        catch (Exception ex)
                        {
                            dm(new OutputMessage("Error: Could not get track information for Track \"" + track.Name + "\", Artist = \"" + track.Artist + "\", Album = \"" + track.Album + "\": " + ex.Message, MessageSeverity.Warning));
                        }
                    }
                    else
                    {
                        dm(new OutputMessage("Found excluded track \"" + track.Name + "\", Artist = \"" + track.Artist + "\", Album = \"" + track.Album + "\".", MessageSeverity.Debug));
                    }
                }
            }
            else
            {
                dm(new OutputMessage("Could not retrieve the library playlist from the iTunes library.", MessageSeverity.Error));
            }

            return(trackList);
        }
 private static IITTrack GetTrackByPersistentID(iTunesLibrary library, PersistentID persistentID)
 {
     return(library.GetLibraryPlaylist().Tracks.get_ItemByPersistentID(persistentID.HighBits, persistentID.LowBits));
 }