internal static async Task<List<PlaylistItem>> GetInstantMixPlaylist(this IApiClient apiClient, BaseItemDto item, IPlaybackManager playbackManager)
        {
            ItemsResult result;
            var query = new SimilarItemsQuery { UserId = AuthenticationService.Current.LoggedInUserId, Id = item.Id, Fields = new []{ ItemFields.MediaSources}};

            switch (item.Type)
            {
                case "Audio":
                    result = await apiClient.GetInstantMixFromSongAsync(query);
                    break;
                case "MusicArtist":
                    result = await apiClient.GetInstantMixFromArtistAsync(query);
                    break;
                case "MusicAlbum":
                    result = await apiClient.GetInstantMixFromAlbumAsync(query);
                    break;
                case "Genre":
                    result = await apiClient.GetInstantMixFromMusicGenreAsync(query);
                    break;
                default:
                    return new List<PlaylistItem>();
            }

            if (result == null || result.Items.IsNullOrEmpty())
            {
                return new List<PlaylistItem>();
            }

            return await result.Items.ToList().ToPlayListItems(apiClient, playbackManager);
        }
        private Task<ItemsResult> GetSimilarItemsAsync(ItemListViewModel viewModel)
        {
            var item = ItemViewModel.Item;

            var query = new SimilarItemsQuery
            {
                UserId = _sessionManager.LocalUserId,
                Limit = item.IsGame || item.IsType("musicalbum") ? 6 : 12,
                Fields = new[]
                        {
                                 ItemFields.PrimaryImageAspectRatio,
                                 ItemFields.DateCreated,
                                 ItemFields.Overview,
                                 ItemFields.MediaStreams
                        },
                Id = item.Id
            };

            if (item.IsType("trailer"))
            {
                return _apiClient.GetSimilarTrailersAsync(query, CancellationToken.None);
            }
            if (item.IsGame)
            {
                return _apiClient.GetSimilarGamesAsync(query, CancellationToken.None);
            }
            if (item.IsType("musicalbum"))
            {
                return _apiClient.GetSimilarAlbumsAsync(query, CancellationToken.None);
            }
            if (item.IsType("series"))
            {
                return _apiClient.GetSimilarSeriesAsync(query, CancellationToken.None);
            }

            return _apiClient.GetSimilarMoviesAsync(query, CancellationToken.None);
        }
        public IEnumerable<BaseItem> RetrieveSimilarItems(SimilarItemsQuery query, string type)
        {
            var dtos = Kernel.ApiClient.GetSimilarItems(query, type);

            return dtos == null ? new BaseItem[] {} : dtos.Items.Select(dto => GetItem(dto, dto.Type)).Where(item => item != null);
            
        }
        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.");
                                                    }
                                                });
        }
Esempio n. 5
0
        private async void LoadItems()
        {
            var query = new SimilarItemsQuery { Id = _item.Id, UserId = _sessionManager.CurrentUser.Id, Limit = 6 };

            switch (_item.Type) {
                case "Movie":
                    LoadItems(await _apiClient.GetSimilarMoviesAsync(query));
                    break;
                case "Series":
                case "Season":
                case "Episode":
                    LoadItems(await _apiClient.GetSimilarSeriesAsync(query));
                    break;
                case "Game":
                    LoadItems(await _apiClient.GetSimilarGamesAsync(query));
                    break;
                case "Album":
                    LoadItems(await _apiClient.GetSimilarAlbumsAsync(query));
                    break;
                default:
                    IsVisible = false;
                    break;
            }
        }