Exemplo n.º 1
0
 protected void RemoveQuicklist()
 {
     //remove any persisted lists from the cache
     quickListFolder = new IndexFolder(new List <BaseItem>())
     {
         Id = QuickListID("added"), Name = "Reset"
     };
     Kernel.Instance.ItemRepository.SaveItem(quickListFolder);
     Kernel.Instance.ItemRepository.SaveChildren(quickListFolder.Id, new List <Guid>());
     quickListFolder.Id = QuickListID("unwatched");
     Kernel.Instance.ItemRepository.SaveItem(quickListFolder);
     Kernel.Instance.ItemRepository.SaveChildren(quickListFolder.Id, new List <Guid>());
     quickListFolder.Id = QuickListID("watched");
     Kernel.Instance.ItemRepository.SaveItem(quickListFolder);
     Kernel.Instance.ItemRepository.SaveChildren(quickListFolder.Id, new List <Guid>());
 }
Exemplo n.º 2
0
        void AddItemToIndex(Dictionary <BaseItem, List <BaseItem> > index, BaseItem item, BaseItem child)
        {
            List <BaseItem> subItems;

            if (!index.TryGetValue(item, out subItems))
            {
                subItems    = new List <BaseItem>();
                index[item] = subItems;
            }
            if (child is Episode)
            {
                //we want to group these by series - find or create a series head
                Episode     episode       = child as Episode;
                Folder      currentSeries = episode.Parent is IndexFolder ? episode.Parent : episode.Series; //may already be indexed
                IndexFolder series        = (IndexFolder)index[item].Find(i => i.Id == (item.Name + currentSeries.Name).GetMD5());
                if (series == null)
                {
                    series = new IndexFolder()
                    {
                        Id                 = (item.Name + currentSeries.Name).GetMD5(),
                        Name               = currentSeries.Name,
                        Overview           = currentSeries.Overview,
                        PrimaryImagePath   = currentSeries.PrimaryImagePath,
                        SecondaryImagePath = currentSeries.SecondaryImagePath,
                        BannerImagePath    = currentSeries.BannerImagePath,
                        BackdropImagePaths = currentSeries.BackdropImagePaths
                    };
                    index[item].Add(series);
                }
                series.AddChild(episode);
            }
            else
            {
                if (!(child is Season))
                {
                    subItems.Add(child);                     //never want seasons
                }
            }
        }
Exemplo n.º 3
0
        private List<BaseItem> GroupResults(IEnumerable<BaseItem> items)
        {
            List<BaseItem> folderChildren = new List<BaseItem>();
            int containerNo = 0;
            //now collapse anything that needs to be and create the child list for the list folder
            var containers = from item in items
                             where item is IGroupInIndex
                             group item by (item as IGroupInIndex).MainContainer;

            foreach (var container in containers)
            {
                Logger.ReportVerbose("Container " + (container.Key == null ? "--Unknown--" : container.Key.Name) + " items: " + container.Count());
                if (container.Count() < Kernel.Instance.ConfigData.RecentItemCollapseThresh)
                {
                    //add the items without rolling up
                    foreach (var i in container)
                    {
                        //make sure any inherited images get loaded
                        var ignore = i.Parent != null ? i.Parent.BackdropImages : null;
                        ignore = i.BackdropImages;
                        var ignore2 = i.LogoImage;
                        ignore2 = i.ArtImage;

                        folderChildren.Add(i);
                    }
                }
                else
                {
                    var currentContainer = container.Key as IContainer ?? new IndexFolder() { Name = "<Unknown>" };
                    containerNo++;
                    IndexFolder aContainer = new IndexFolder(new List<BaseItem>())
                    {
                        Id = ("searchcontainer" + this.Name + this.Path + containerNo).GetMD5(),
                        Name = currentContainer.Name + " (" + container.Count() + " Items)",
                        Overview = currentContainer.Overview,
                        MpaaRating = currentContainer.MpaaRating,
                        Genres = currentContainer.Genres,
                        ImdbRating = currentContainer.ImdbRating,
                        Studios = currentContainer.Studios,
                        PrimaryImagePath = currentContainer.PrimaryImagePath,
                        SecondaryImagePath = currentContainer.SecondaryImagePath,
                        BannerImagePath = currentContainer.BannerImagePath,
                        BackdropImagePaths = currentContainer.BackdropImagePaths,
                        TVDBSeriesId = currentContainer is Series ? (currentContainer as Series).TVDBSeriesId : null,
                        LogoImagePath = currentContainer is Media ? (currentContainer as Media).LogoImagePath : null,
                        ArtImagePath = currentContainer is Media ? (currentContainer as Media).ArtImagePath : null,
                        ThumbnailImagePath = currentContainer is Media ? (currentContainer as Media).ThumbnailImagePath : null,
                        DisplayMediaType = currentContainer.DisplayMediaType,
                        DateCreated = container.First().DateCreated,
                        Parent = this.Folder
                    };
                    if (container.Key is Series)
                    {

                        //always roll into seasons
                        var seasons = from episode in container
                                      group episode by episode.Parent;
                        foreach (var season in seasons)
                        {
                            var currentSeason = season.Key as Series ?? new Season() { Name = "<Unknown>" };
                            containerNo++;
                            IndexFolder aSeason = new IndexFolder(season.ToList())
                            {
                                Id = ("searchseason" + this.Name + this.Path + containerNo).GetMD5(),
                                Name = currentSeason.Name + " (" + season.Count() + " Items)",
                                Overview = currentSeason.Overview,
                                MpaaRating = currentSeason.MpaaRating,
                                Genres = currentSeason.Genres,
                                ImdbRating = currentSeason.ImdbRating,
                                Studios = currentSeason.Studios,
                                PrimaryImagePath = currentSeason.PrimaryImagePath,
                                SecondaryImagePath = currentSeason.SecondaryImagePath,
                                BannerImagePath = currentSeason.BannerImagePath,
                                BackdropImagePaths = currentSeason.BackdropImagePaths,
                                TVDBSeriesId = currentSeason.TVDBSeriesId,
                                LogoImagePath = currentSeason.LogoImagePath,
                                ArtImagePath = currentSeason.ArtImagePath,
                                ThumbnailImagePath = currentSeason.ThumbnailImagePath,
                                DisplayMediaType = currentSeason.DisplayMediaType,
                                DateCreated = season.First().DateCreated,
                                Parent = currentSeason == aContainer ? this.Folder : aContainer
                            };
                            aContainer.AddChild(aSeason);
                        }
                    }
                    else
                    {
                        //not series so just add all children to container
                        aContainer.AddChildren(container.ToList());
                    }
                    //and container to children
                    folderChildren.Add(aContainer);
                }
            }

            //finally add all the items that don't go in containers
            folderChildren.AddRange(items.Where(i => (!(i is IGroupInIndex))));

            return folderChildren;
        }
        private void AddItemToIndex(string indexName, List<BaseItem> index, Dictionary<Guid, IContainer> seriesList, BaseItem child)
        {
            if (child is IGroupInIndex)
            {
                //we want to group these by their main containers - find or create a head
                IContainer currentContainer = seriesList[child.Id];

                if (currentContainer == null)
                {
                    //couldn't find our container...
                    currentContainer = new Series()
                    {
                        Id = Guid.NewGuid(),
                        Name = "<Unknown>"
                    };
                }
                IndexFolder container = (IndexFolder)index.Find(i => i.Id == (indexName + currentContainer.Name).GetMD5());
                if (container == null)
                {
                    container = new IndexFolder()
                    {
                        Id = (indexName + currentContainer.Name).GetMD5(),
                        Name = currentContainer.Name,
                        Overview = currentContainer.Overview,
                        MpaaRating = currentContainer.MpaaRating,
                        Genres = currentContainer.Genres,
                        ImdbRating = currentContainer.ImdbRating,
                        Studios = currentContainer.Studios,
                        PrimaryImagePath = currentContainer.PrimaryImagePath,
                        SecondaryImagePath = currentContainer.SecondaryImagePath,
                        BannerImagePath = currentContainer.BannerImagePath,
                        BackdropImagePaths = currentContainer.BackdropImagePaths,
                        DisplayMediaType = currentContainer.DisplayMediaType,
                    };
                    index.Add(container);
                }
                container.AddChild(child);
            }
            else
            {
                index.Add(child);
            }
        }
Exemplo n.º 5
0
        public virtual void UpdateQuickList(string recentItemOption)
        {
            //rebuild the proper list
            List <BaseItem> items       = null;
            int             containerNo = 0;
            int             maxItems    = this.ActualChildren.Count > 0 ? (this.ActualChildren[0] is IContainer || this.GetType().Name == "MusicMainFolder") && Kernel.Instance.ConfigData.RecentItemCollapseThresh <= 6 ? Kernel.Instance.ConfigData.RecentItemContainerCount : Kernel.Instance.ConfigData.RecentItemCount : Kernel.Instance.ConfigData.RecentItemCount;

            Logger.ReportVerbose("Starting RAL (" + recentItemOption + ") Build for " + this.Name +
                                 " with " + maxItems + " items out of " + this.RecursiveChildren.Count() + ".");
            switch (recentItemOption)
            {
            case "watched":
                items = this.RecursiveChildren.Where(i => i is Media && (i as Media).PlaybackStatus.PlayCount > 0).Distinct(new BaseItemEqualityComparer()).OrderByDescending(i => (i as Media).PlaybackStatus.LastPlayed).Take(maxItems).ToList();

                break;

            case "unwatched":
                items = this.RecursiveChildren.Where(i => i is Media && (i as Media).PlaybackStatus.PlayCount == 0).Distinct(new BaseItemEqualityComparer()).OrderByDescending(v => v.DateCreated).Take(maxItems).ToList();
                break;

            default:
                items = this.RecursiveChildren.Where(i => i is Media).Distinct(new BaseItemEqualityComparer()).OrderByDescending(i => i.DateCreated).Take(maxItems).ToList();
                break;
            }
            if (items != null)
            {
                Logger.ReportVerbose(recentItemOption + " list for " + this.Name + " loaded with " + items.Count + " items.");
                List <BaseItem> folderChildren = new List <BaseItem>();
                //now collapse anything that needs to be and create the child list for the list folder
                var containers = from item in items
                                 where item is IGroupInIndex
                                 group item by(item as IGroupInIndex).MainContainer;

                foreach (var container in containers)
                {
                    Logger.ReportVerbose("Container " + (container.Key == null ? "--Unknown--" : container.Key.Name) + " items: " + container.Count());
                    if (container.Count() < Kernel.Instance.ConfigData.RecentItemCollapseThresh)
                    {
                        //add the items without rolling up
                        foreach (var i in container)
                        {
                            //make sure any inherited images get loaded
                            var ignore = i.Parent != null ? i.Parent.BackdropImages : null;
                            ignore = i.BackdropImages;
                            var ignore2 = i.LogoImage;
                            ignore2 = i.ArtImage;

                            folderChildren.Add(i);
                        }
                    }
                    else
                    {
                        var currentContainer = container.Key as IContainer ?? new IndexFolder()
                        {
                            Name = "<Unknown>"
                        };
                        containerNo++;
                        IndexFolder aContainer = new IndexFolder(new List <BaseItem>())
                        {
                            Id                 = ("container" + recentItemOption + this.Name + this.Path + containerNo).GetMD5(),
                            Name               = currentContainer.Name + " (" + container.Count() + " Items)",
                            Overview           = currentContainer.Overview,
                            MpaaRating         = currentContainer.MpaaRating,
                            Genres             = currentContainer.Genres,
                            ImdbRating         = currentContainer.ImdbRating,
                            Studios            = currentContainer.Studios,
                            PrimaryImagePath   = currentContainer.PrimaryImagePath,
                            SecondaryImagePath = currentContainer.SecondaryImagePath,
                            BannerImagePath    = currentContainer.BannerImagePath,
                            BackdropImagePaths = currentContainer.BackdropImagePaths,
                            TVDBSeriesId       = currentContainer is Series ? (currentContainer as Series).TVDBSeriesId : null,
                            LogoImagePath      = currentContainer is Media ? (currentContainer as Media).LogoImagePath : null,
                            ArtImagePath       = currentContainer is Media ? (currentContainer as Media).ArtImagePath : null,
                            ThumbnailImagePath = currentContainer is Media ? (currentContainer as Media).ThumbnailImagePath : null,
                            DisplayMediaType   = currentContainer.DisplayMediaType,
                            DateCreated        = container.First().DateCreated,
                            Parent             = this
                        };
                        if (container.Key is Series)
                        {
                            //always roll into seasons
                            var seasons = from episode in container
                                          group episode by episode.Parent;
                            foreach (var season in seasons)
                            {
                                var currentSeason = season.Key as Series ?? new Season()
                                {
                                    Name = "<Unknown>"
                                };
                                containerNo++;
                                IndexFolder aSeason = new IndexFolder(season.ToList())
                                {
                                    Id                 = ("season" + recentItemOption + this.Name + this.Path + containerNo).GetMD5(),
                                    Name               = currentSeason.Name + " (" + season.Count() + " Items)",
                                    Overview           = currentSeason.Overview,
                                    MpaaRating         = currentSeason.MpaaRating,
                                    Genres             = currentSeason.Genres,
                                    ImdbRating         = currentSeason.ImdbRating,
                                    Studios            = currentSeason.Studios,
                                    PrimaryImagePath   = currentSeason.PrimaryImagePath,
                                    SecondaryImagePath = currentSeason.SecondaryImagePath,
                                    BannerImagePath    = currentSeason.BannerImagePath,
                                    BackdropImagePaths = currentSeason.BackdropImagePaths,
                                    TVDBSeriesId       = currentSeason.TVDBSeriesId,
                                    LogoImagePath      = currentSeason.LogoImagePath,
                                    ArtImagePath       = currentSeason.ArtImagePath,
                                    ThumbnailImagePath = currentSeason.ThumbnailImagePath,
                                    DisplayMediaType   = currentSeason.DisplayMediaType,
                                    DateCreated        = season.First().DateCreated,
                                    Parent             = currentSeason == aContainer ? this : aContainer
                                };
                                Kernel.Instance.ItemRepository.SaveItem(aSeason);
                                Kernel.Instance.ItemRepository.SaveChildren(aSeason.Id, season.Select(i => i.Id));
                                aContainer.AddChild(aSeason);
                            }
                        }
                        else
                        {
                            //not series so just add all children to container
                            aContainer.AddChildren(container.ToList());
                        }
                        Kernel.Instance.ItemRepository.SaveItem(aContainer);
                        Kernel.Instance.ItemRepository.SaveChildren(aContainer.Id, aContainer.Children.Select(i => i.Id));
                        //and container to children
                        folderChildren.Add(aContainer);
                    }
                }

                //finally add all the items that don't go in containers
                folderChildren.AddRange(items.Where(i => (!(i is IGroupInIndex))));

                //and create our quicklist folder
                //we save it with the current state of parental controls so we know when we re-load if it is valid
                IndexFolder quickList = new IndexFolder(folderChildren)
                {
                    Id = QuickListID(recentItemOption), Name = "ParentalControl:" + Kernel.Instance.ParentalControls.Enabled
                };
                Logger.ReportVerbose(this.Name + " folderChildren: " + folderChildren.Count + " listfolder.children: " + quickList.Children.Count());
                Kernel.Instance.ItemRepository.SaveItem(quickList);
                Kernel.Instance.ItemRepository.SaveChildren(QuickListID(recentItemOption), folderChildren.Select(i => i.Id));
            }
        }
Exemplo n.º 6
0
 public virtual void ResetQuickList()
 {
     quickListFolder  = null; //it will re-load next time requested
     reBuildQuickList = true;
 }