FLICKER
FLICKER

Reputation: 6683

Differentiate iTunes internal playlists and user playlist

Following my previous question

When I fetch Playlists in iTunes library I get some entries which seems to be default playlists for iTunes

Here is my code:

App = new iTunesAppClass();
IITSourceCollection sources = App.Sources;

foreach (IITSource src in sources)
{
    if (src.Name == "Library")
    {
        IITPlaylistCollection pls = src.Playlists;
        foreach (IITPlaylist pl in pls)
        {
            // add pl.Name to a List<string> and them show them on TreeView
        }
    }
}

This is the result:

enter image description here

You see that I have created a playlist named "Music". There is also a default entry named "Music". How can I differentiate these two playlist ? Is there any property in iTunesLib which says which one is the default one and which is the one I have created?

Upvotes: 2

Views: 63

Answers (1)

FLICKER
FLICKER

Reputation: 6683

Using Kind and SpecialKind properties, I was able to implement a solution:

App = new iTunesAppClass();
IITSourceCollection sources = App.Sources;

foreach (IITSource src in sources)
{
    if (src.Name == "Library")
    {
        IITPlaylistCollection pls = src.Playlists;
        foreach (IITPlaylist pl in pls)
        {
            /* here is the trick */
            if (pl is IITUserPlaylist)
            {
                var upl = (IITUserPlaylist)pl;
                if (upl.SpecialKind != ITUserPlaylistSpecialKind.ITUserPlaylistSpecialKindNone)
                    continue;
            }

            /* and this one */
            if (pl.Kind == ITPlaylistKind.ITPlaylistKindLibrary)
                continue;

            // add pl.Name to a List<string> and them show them on TreeView
        }
    }
}

Upvotes: 1

Related Questions