public void NavigateToGenre(string genre, Item currentMovie, string itemType)
        {
            switch (currentMovie.BaseItem.GetType().Name)
            {
                case "Series":
                case "Season":
                case "Episode":
                    itemType = "Series";
                    break;

                case "MusicAlbum":
                case "MusicArtist":
                case "MusicGenre":
                case "Song":
                    itemType = "MusicAlbum";
                    break;

                case "Game":
                    itemType = "Game";
                    break;
            }

            Async.Queue(Async.ThreadPoolName.GenreNavigation, () =>
                                                {
                                                    ProgressBox(string.Format("Finding items in the {0} genre...", genre));
                                                    var searchStart = GetStartingFolder(currentMovie.BaseItem.Parent);

                                                    var query = new ItemQuery
                                                                    {
                                                                        UserId = Kernel.CurrentUser.Id.ToString(),
                                                                        Fields = MB3ApiRepository.StandardFields,
                                                                        ParentId = searchStart.ApiId,
                                                                        Genres = new[] {genre},
                                                                        IncludeItemTypes = new [] {itemType},
                                                                        Recursive = true
                                                                    };
                                                    var index = new SearchResultFolder(Kernel.Instance.MB3ApiRepository.RetrieveItems(query).ToList()) {Name = genre};
                                                    ShowMessage = false;

                                                    Navigate(ItemFactory.Instance.Create(index));
                                                });
        }
        public void NavigateToSimilar(Item item)
        {
            var itemType = "Movies";

            switch (item.BaseItem.GetType().Name)
            {
                case "Series":
                case "Season":
                case "Episode":
                    itemType = "Shows";
                    break;

                case "MusicAlbum":
                case "MusicArtist":
                case "Song":
                    itemType = "Albums";
                    break;

                case "Game":
                    itemType = "Games";
                    break;
            }

            Async.Queue(Async.ThreadPoolName.SimilarNavigation, () =>
                                                {
                                                    ProgressBox(string.Format("Finding {0} similar to {1}...", itemType, item.Name));

                                                    var query = new SimilarItemsQuery
                                                                    {
                                                                        UserId = Kernel.CurrentUser.Id.ToString(),
                                                                        Fields = MB3ApiRepository.StandardFields,
                                                                        Id = item.BaseItem.ApiId,
                                                                        Limit = 25
                                                                        
                                                                    };
                                                    var items = Kernel.Instance.MB3ApiRepository.RetrieveSimilarItems(query, itemType).ToList();
                                                    // Preserve the order of scoring
                                                    var i = 0;
                                                    foreach (var thing in items)
                                                    {
                                                        thing.SortName = i.ToString("000");
                                                        i++;
                                                    }
                                                    var index = new SearchResultFolder(items) {Name = LocalizedStrings.Instance.GetString("SimilarTo")+item.Name};
                                                    ShowMessage = false;

                                                    if (index.Children.Any())
                                                    {
                                                        Navigate(ItemFactory.Instance.Create(index));
                                                    }
                                                    else
                                                    {
                                                        MessageBox("No Items Found.");
                                                    }
                                                });
        }
        void NavigateToPerson(string name, string[] personTypes)
        {
            Async.Queue(Async.ThreadPoolName.PersonNavigation, () =>
                                                 {
                                                    ProgressBox(string.Format("Finding items with {0} in them...", name));
                                                    
                                                    var person = Kernel.Instance.MB3ApiRepository.RetrievePerson(name) ?? new Person();

                                                    var query = new ItemQuery
                                                                    {
                                                                        UserId = Kernel.CurrentUser.Id.ToString(),
                                                                        Fields = MB3ApiRepository.StandardFields,
                                                                        PersonIds = new [] {person.ApiId},
                                                                        PersonTypes = personTypes,
                                                                        Recursive = true
                                                                    };

                                                    var index = new SearchResultFolder(Kernel.Instance.MB3ApiRepository.RetrieveItems(query).ToList()) {Name = name, Overview = person.Overview};
                                                    ShowMessage = false;

                                                    Application.UIDeferredInvokeIfRequired(() => Navigate(ItemFactory.Instance.Create(index)));
                                                     
                                                 });
            
        }
        public void NavigateToGenre(string genre, Item currentMovie)
        {
            Async.Queue("Genre navigation", () =>
                                                {
                                                    ProgressBox(string.Format("Finding items in the {0} genre...", genre));
                                                    var searchStart = GetStartingFolder(currentMovie.BaseItem.Parent);

                                                    var query = new ItemQuery
                                                                    {
                                                                        UserId = Kernel.CurrentUser.Id.ToString(),
                                                                        Fields = MB3ApiRepository.StandardFields,
                                                                        ParentId = searchStart.ApiId,
                                                                        Genres = new[] {genre},
                                                                        ExcludeItemTypes = Config.ExcludeRemoteContentInSearch ? new[] {"Episode", "Season", "Trailer"} : new[] {"Episode", "Season"},
                                                                        Recursive = true
                                                                    };
                                                    var index = new SearchResultFolder(Kernel.Instance.MB3ApiRepository.RetrieveItems(query).ToList()) {Name = genre};
                                                    ShowMessage = false;

                                                    Microsoft.MediaCenter.UI.Application.DeferredInvoke(_ => Navigate(ItemFactory.Instance.Create(index)));
                                                });
        }
        void NavigateToActor(Item item)
        {
            Async.Queue("Person navigation", () =>
                                                 {
                                                    ProgressBox(string.Format("Finding items with {0} in them...", item.Name));
                                                    var person = (Person)item.BaseItem;
                                                    //Folder searchStart = GetStartingFolder(item.BaseItem.Parent);

                                                    var query = new ItemQuery
                                                                    {
                                                                        UserId = Kernel.CurrentUser.Id.ToString(),
                                                                        Fields = MB3ApiRepository.StandardFields,
                                                                        //ParentId = searchStart.ApiId,
                                                                        Person = person.Name,
                                                                        PersonTypes = new[] {"Actor"},
                                                                        Recursive = true
                                                                    };
                                                    var index = new SearchResultFolder(Kernel.Instance.MB3ApiRepository.RetrieveItems(query).ToList()) {Name = item.Name};
                                                    ShowMessage = false;

                                                    Microsoft.MediaCenter.UI.Application.DeferredInvoke(_ =>Navigate(ItemFactory.Instance.Create(index)));
                                                     
                                                 });
        }
Example #6
0
        public virtual IndexFolder 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.ActualChildren[0] is MusicArtist) && Kernel.Instance.ConfigData.RecentItemCollapseThresh <= 6 ? Kernel.Instance.ConfigData.RecentItemContainerCount : Kernel.Instance.ConfigData.RecentItemCount : Kernel.Instance.ConfigData.RecentItemCount;

            using (new Profiler(string.Format("RAL child retrieval for {0} option {1}", Name, recentItemOption)))
            {
                items = GetLatestItems(recentItemOption, maxItems).ToList();
            }

            Logger.ReportVerbose(recentItemOption + " list for " + this.Name + " loaded with " + items.Count + " items.");
            var 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).MainContainerId;

            foreach (var container in containers)
            {
                var containerObj = ((IGroupInIndex)container.First()).MainContainer;
                //Logger.ReportVerbose("Container " + (containerObj == null ? "--Unknown--" : containerObj.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 = containerObj ?? new IndexFolder()
                    {
                        Name = "<Unknown>"
                    };
                    var currentSeries = currentContainer as Series;
                    containerNo++;
                    var aContainer = new SearchResultFolder(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,
                        ThemeId            = currentSeries != null ? currentSeries.ApiId : null,
                        TVDBSeriesId       = currentSeries != null ? currentSeries.TVDBSeriesId : null,
                        LogoImagePath      = currentSeries != null ? currentSeries.LogoImagePath : null,
                        ArtImagePath       = currentSeries != null ? currentSeries.ArtImagePath : null,
                        ThumbnailImagePath = currentSeries != null ? currentSeries.ThumbnailImagePath : null,
                        DisplayMediaType   = currentContainer.DisplayMediaType,
                        DateCreated        = container.First().DateCreated,
                        Parent             = this
                    };
                    if (containerObj is Series)
                    {
                        //always roll into seasons
                        var seasons = from episode in container
                                      group episode by(episode as Episode).SeasonId;

                        foreach (var season in seasons)
                        {
                            var currentSeason = ((Episode)season.First()).Season;
                            containerNo++;
                            var aSeason = new SearchResultFolder(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 ?? containerObj.PrimaryImagePath,
                                SecondaryImagePath = currentSeason.SecondaryImagePath,
                                BannerImagePath    = currentSeason.BannerImagePath ?? containerObj.BannerImagePath,
                                BackdropImagePaths = currentSeason.BackdropImagePaths ?? containerObj.BackdropImagePaths,
                                TVDBSeriesId       = currentSeason.TVDBSeriesId,
                                LogoImagePath      = currentSeason.LogoImagePath,
                                ArtImagePath       = currentSeason.ArtImagePath,
                                ThumbnailImagePath = currentSeason.ThumbnailImagePath,
                                DisplayMediaType   = currentSeason.DisplayMediaType,
                                DateCreated        = season.First().DateCreated,
                                Parent             = currentSeason.Id == aContainer.Id ? this : 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))));

            //and create our quicklist folder
            return(new IndexFolder(folderChildren)
            {
                Id = QuickListID(recentItemOption), Name = "User:" + Kernel.CurrentUser.Name, DateCreated = DateTime.UtcNow, Parent = this
            });
        }
Example #7
0
        public virtual IndexFolder 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.ActualChildren[0] is MusicArtist) && Kernel.Instance.ConfigData.RecentItemCollapseThresh <= 6 ? Kernel.Instance.ConfigData.RecentItemContainerCount : Kernel.Instance.ConfigData.RecentItemCount : Kernel.Instance.ConfigData.RecentItemCount;

            using (new Profiler(string.Format("RAL child retrieval for {0} option {1}", Name, recentItemOption)))
            {
                switch (recentItemOption)
                {
                case "watched":
                    items = Kernel.Instance.MB3ApiRepository.RetrieveItems(new ItemQuery
                    {
                        UserId               = Kernel.CurrentUser.ApiId,
                        ParentId             = RalParentId,
                        Limit                = maxItems,
                        Recursive            = true,
                        ExcludeItemTypes     = RalExcludeTypes,
                        IncludeItemTypes     = RalIncludeTypes,
                        ExcludeLocationTypes = new[] { LocationType.Virtual },
                        Fields               = MB3ApiRepository.StandardFields,
                        Filters              = (new[] { Config.Instance.TreatWatchedAsInProgress?ItemFilter.IsResumable: ItemFilter.IsPlayed, }).Concat(AdditionalRalFilters).ToArray(),
                        SortBy               = new[] { ItemSortBy.DatePlayed },
                        SortOrder            = Model.Entities.SortOrder.Descending
                    }).ToList();

                    break;

                case "unwatched":
                    items = Kernel.Instance.MB3ApiRepository.RetrieveItems(new ItemQuery
                    {
                        UserId               = Kernel.CurrentUser.ApiId,
                        ParentId             = RalParentId,
                        Limit                = maxItems,
                        Recursive            = true,
                        Fields               = MB3ApiRepository.StandardFields,
                        ExcludeItemTypes     = RalExcludeTypes,
                        IncludeItemTypes     = RalIncludeTypes,
                        ExcludeLocationTypes = new[] { LocationType.Virtual },
                        Filters              = (new[] { ItemFilter.IsUnplayed, }).Concat(AdditionalRalFilters).ToArray(),
                        SortBy               = new[] { ItemSortBy.DateCreated },
                        SortOrder            = Model.Entities.SortOrder.Descending
                    }).ToList();
                    break;

                default:
                    items = Kernel.Instance.MB3ApiRepository.RetrieveItems(new ItemQuery
                    {
                        UserId               = Kernel.CurrentUser.ApiId,
                        ParentId             = RalParentId,
                        Limit                = maxItems,
                        Recursive            = true,
                        Filters              = AdditionalRalFilters,
                        ExcludeItemTypes     = RalExcludeTypes,
                        IncludeItemTypes     = RalIncludeTypes,
                        ExcludeLocationTypes = new[] { LocationType.Virtual },
                        Fields               = MB3ApiRepository.StandardFields,
                        SortBy               = new[] { ItemSortBy.DateCreated },
                        SortOrder            = Model.Entities.SortOrder.Descending
                    }).ToList();
                    break;
                }
            }
            Logger.ReportVerbose(recentItemOption + " list for " + this.Name + " loaded with " + items.Count + " items.");
            var 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.Id;

            foreach (var container in containers)
            {
                var containerObj = ((IGroupInIndex)container.First()).MainContainer;
                //Logger.ReportVerbose("Container " + (containerObj == null ? "--Unknown--" : containerObj.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 = containerObj ?? new IndexFolder()
                    {
                        Name = "<Unknown>"
                    };
                    var currentSeries = currentContainer as Series;
                    containerNo++;
                    var aContainer = new SearchResultFolder(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       = currentSeries != null ? currentSeries.TVDBSeriesId : null,
                        LogoImagePath      = currentSeries != null ? currentSeries.LogoImagePath : null,
                        ArtImagePath       = currentSeries != null ? currentSeries.ArtImagePath : null,
                        ThumbnailImagePath = currentSeries != null ? currentSeries.ThumbnailImagePath : null,
                        DisplayMediaType   = currentContainer.DisplayMediaType,
                        DateCreated        = container.First().DateCreated,
                        Parent             = this
                    };
                    if (containerObj is Series)
                    {
                        //always roll into seasons
                        var seasons = from episode in container
                                      group episode by(episode as Episode).Season.Id;

                        foreach (var season in seasons)
                        {
                            var currentSeason = ((Episode)season.First()).Season;
                            containerNo++;
                            var aSeason = new SearchResultFolder(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.Id == aContainer.Id ? this : 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))));

            //and create our quicklist folder
            return(new IndexFolder(folderChildren)
            {
                Id = QuickListID(recentItemOption), Name = "User:" + Kernel.CurrentUser.Name, DateCreated = DateTime.UtcNow, Parent = this
            });
        }