Beispiel #1
0
        /// <summary>
        /// Resets the hierarchy from the root.
        /// </summary>
        public static void RebuildList()
        {
            if (!Signature.IsActivated && IsRunning)
            {
                Stop();
                return;
            }

            var st = DateTime.Now;

            Log.Debug("Rebuilding UPnP/DLNA library...");

            MediaBuilder.SetNextID(0);

            var allEps = DvMediaBuilder.CreateContainer(new MediaBuilder.container("-- All Episodes --")
            {
                IsRestricted = true
            });
            var unwEps = DvMediaBuilder.CreateContainer(new MediaBuilder.container("-- Unwatched Episodes --")
            {
                IsRestricted = true
            });

            _ms.Root.AddObject(allEps, true);
            _ms.Root.AddObject(unwEps, true);

            var shows = new Dictionary <int, DvMediaContainer>();

            foreach (var tvs in Database.TVShows.OrderBy(t => t.Value.Title))
            {
                shows[tvs.Key] = DvMediaBuilder.CreateContainer(new MediaBuilder.container(tvs.Value.Title)
                {
                    IsRestricted = true
                });
            }

            foreach (var item in Library.Files)
            {
                var sid = (int)Math.Floor((double)item.Key / 1000 / 1000);

                TVShow show;
                if (!Database.TVShows.TryGetValue(sid, out show))
                {
                    continue;
                }

                Episode ep;
                if (!show.EpisodeByID.TryGetValue(item.Key - (sid * 1000 * 1000), out ep))
                {
                    continue;
                }

                var txt = string.Format("S{0:00}E{1:00}: {2}", ep.Season, ep.Number, ep.Title);

                foreach (var file in Library.Files[item.Key])
                {
                    if (OpenArchiveTaskDialog.SupportedArchives.Contains(Path.GetExtension(file).ToLower()))
                    {
                        continue;
                    }

                    var ltxt = txt;
                    var q    = FileNames.Parser.ParseQuality(file);

                    if (q != Qualities.Unknown)
                    {
                        ltxt += " [" + q.GetAttribute <DescriptionAttribute>().Description + "]";
                    }
                    else
                    {
                        var ed = FileNames.Parser.ParseEdition(file);

                        if (ed != Editions.Unknown)
                        {
                            ltxt += " [" + ed.GetAttribute <DescriptionAttribute>().Description + "]";
                        }
                        else
                        {
                            ltxt += " [" + Path.GetExtension(file) + "]";
                        }
                    }

                    allEps.AddBranch(CreateObject(show.Title + " " + ltxt, file));

                    if (!ep.Watched)
                    {
                        unwEps.AddBranch(CreateObject(show.Title + " " + ltxt, file));
                    }

                    shows[sid].AddBranch(CreateObject(ltxt, file));
                }
            }

            foreach (var tvs in shows)
            {
                if (tvs.Value.ChildCount != 0)
                {
                    _ms.Root.AddObject(tvs.Value, true);
                }
            }

            Log.Debug("Rebuilt UPnP/DLNA library in " + (DateTime.Now - st).TotalSeconds + "s, all episodes menu has " + allEps.ChildCount + " entries.");
        }