Search code examples
c#itunes-sdk

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?


Solution

  • 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 (p is IITUserPlaylist)
                {
                    var upl = (IITUserPlaylist)p;
                    if (upl.SpecialKind != ITUserPlaylistSpecialKind.ITUserPlaylistSpecialKindNone)
                        continue;
                }
    
                /* and this one */
                if (p.Kind == ITPlaylistKind.ITPlaylistKindLibrary)
                    continue;
    
                // add pl.Name to a List<string> and them show them on TreeView
            }
        }
    }