示例#1
0
        private void AddChildren(iTunesPlaylist playlist)
        {
            var parentTreeViewPlaylist = _localPlayLists.RecursiveSelect(item => item.Children).FirstOrDefault(item => item.PlaylistPersistentID == playlist.ParentPersistentID);

            parentTreeViewPlaylist?.Children.Add(new TreeViewPlaylist()
            {
                Name = playlist.Name, Id = playlist.Id, PlaylistPersistentID = playlist.PlaylistPersistentID
            });

            foreach (iTunesPlaylist child in playlist.Children)
            {
                AddChildren(child);
            }
        }
示例#2
0
        public static IReadOnlyList <iTunesPlaylist> GetiTunesPlaylists(XDocument xmliTunesMediaLibrary)
        {
            //var keys = new ConcurrentDictionary<string, ISet<string>>();

            var array = xmliTunesMediaLibrary
                        .Element("plist")
                        .Element("dict")
                        .Elements()
                        .AsParallel()
                        .SkipWhile(x => x.Name != "key" || x.Value != "Playlists")
                        .Skip(1)
                        .FirstOrDefault()
                        .Elements("dict");

            var result = array
                         .Select(xDict => xDict.ToDictionary())
                         .Select(xmliTunesPlaylist =>
            {
                //foreach (var x in xmliTunesPlaylist)
                //{
                //    if (!keys.ContainsKey(x.Key))
                //        keys[x.Key] = new HashSet<string>(new[] { x.Value });
                //    else
                //        keys[x.Key].Add(x.Value);
                //}

                iTunesPlaylist iTunesPlaylist = null;

                try
                {
                    iTunesPlaylist = new iTunesPlaylist()
                    {
                        Playlist_ID            = xmliTunesPlaylist.GetValue("Playlist ID", default(int)),
                        Playlist_Persistent_ID = xmliTunesPlaylist.GetValue("Playlist Persistent ID", default(string)),
                        Parent_Persistent_ID   = xmliTunesPlaylist.GetValue("Parent Persistent ID", default(string)),

                        Name = xmliTunesPlaylist.GetValue("Name", default(string)),

                        Playlist_Items = xmliTunesPlaylist.GetValue("Playlist Items", default(string))
                                         ?.Split(new string[] { "Track ID" }, StringSplitOptions.RemoveEmptyEntries)
                                         .Select(x => uint.Parse(x))
                                         .ToImmutableList(),

                        Visible = xmliTunesPlaylist.GetValue("Visible", default(bool)),

                        Distinguished_Kind = xmliTunesPlaylist.GetValue("Distinguished Kind", default(int)),

                        Folder     = xmliTunesPlaylist.GetValue("Folder", default(bool)),
                        Master     = xmliTunesPlaylist.GetValue("Master", default(bool)),
                        All_Items  = xmliTunesPlaylist.GetValue("All Items", default(bool)),
                        Audiobooks = xmliTunesPlaylist.GetValue("Audiobooks", default(bool)),
                        Movies     = xmliTunesPlaylist.GetValue("Movies", default(bool)),
                        Music      = xmliTunesPlaylist.GetValue("Music", default(bool)),
                        Podcasts   = xmliTunesPlaylist.GetValue("Podcasts", default(bool)),
                        TV_Shows   = xmliTunesPlaylist.GetValue("TV Shows", default(bool)),

                        Smart_Criteria = xmliTunesPlaylist.GetValue("Smart Criteria", default(string)),
                        Smart_Info     = xmliTunesPlaylist.GetValue("Smart Info", default(string)),
                    };
                }
                catch     //(Exception ex)
                {
                    iTunesPlaylist = null;
                }
                finally
                {
                }

                return(iTunesPlaylist);
            })
                         .ToArray();

            return(result);
        }