private async Task GetAlbumTracks(BaseItemDto item)
        {
            if (!_navigationService.IsNetworkAvailable)
            {
                return;
            }

            SetProgressBar("Getting album tracks...");

            try
            {
                var query = new ItemQuery
                {
                    UserId           = AuthenticationService.Current.LoggedInUser.Id,
                    Recursive        = true,
                    Fields           = new[] { ItemFields.ParentId, },
                    ParentId         = item.Id,
                    IncludeItemTypes = new[] { "Audio" }
                };

                Log.Info("Getting tracks for album [{0}] ({1})", item.Name, item.Id);

                var itemResponse = await _apiClient.GetItemsAsync(query);

                SendItemsToPlaylist(itemResponse);
            }
            catch (HttpException ex)
            {
                Log.ErrorException(string.Format("GetAlbumTracks({0})", item.Name), ex);
            }

            SetProgressBar();
        }
        private async Task <bool> GetArtistTracks()
        {
            try
            {
                var query = new ItemQuery
                {
                    UserId           = AuthenticationService.Current.LoggedInUserId,
                    ArtistIds        = new[] { SelectedArtist.Id },
                    Recursive        = true,
                    Fields           = new[] { ItemFields.ParentId, ItemFields.MediaSources, ItemFields.SyncInfo },
                    IncludeItemTypes = new[] { "Audio" }
                };

                Log.Info("Getting tracks for artist [{0}] ({1})", SelectedArtist.Name, SelectedArtist.Id);

                var items = await ApiClient.GetItemsAsync(query);

                if (items != null && items.Items.Any())
                {
                    _artistTracks = items.Items.ToList();
                }

                return(true);
            }
            catch (HttpException ex)
            {
                Utils.HandleHttpException("GetArtistTracks()", ex, NavigationService, Log);
                return(false);
            }
        }
        private async Task <bool> GetAlbums()
        {
            try
            {
                var query = new ItemQuery
                {
                    UserId           = AuthenticationService.Current.LoggedInUserId,
                    ArtistIds        = new[] { SelectedArtist.Id },
                    Recursive        = true,
                    Fields           = new[] { ItemFields.ParentId, ItemFields.MediaSources, ItemFields.SyncInfo, },
                    IncludeItemTypes = new[] { "MusicAlbum" }
                };

                Log.Info("Getting albums for artist [{0}] ({1})", SelectedArtist.Name, SelectedArtist.Id);

                var items = await ApiClient.GetItemsAsync(query);

                if (items != null && items.Items.Any())
                {
                    foreach (var album in items.Items)
                    {
                        Albums.Add(album);
                    }
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                Log.ErrorException("GetAlbums()", ex);
                return(false);
            }
        }
예제 #4
0
        private Task <ItemsResult> GetGamesByYear(ItemListViewModel viewModel, DisplayPreferences displayPreferences)
        {
            var query = new ItemQuery
            {
                Fields = FolderPage.QueryFields,

                UserId = _sessionManager.CurrentUser.Id,

                IncludeItemTypes = new[] { "Game" },

                SortBy = !String.IsNullOrEmpty(displayPreferences.SortBy)
                             ? new[] { displayPreferences.SortBy }
                             : new[] { ItemSortBy.SortName },

                SortOrder = displayPreferences.SortOrder,

                Recursive = true,

                ParentId = ParentId
            };

            var indexOption = viewModel.CurrentIndexOption;

            if (indexOption != null)
            {
                query.Years = new[] { int.Parse(indexOption.Name) };
            }

            return(ApiClient.GetItemsAsync(query, CancellationToken.None));
        }
        private async Task GetAlbumTracks()
        {
            try
            {
                var query = new ItemQuery
                {
                    ParentId         = SelectedAlbum.Id,
                    IncludeItemTypes = new[] { "Audio" },
                    UserId           = AuthenticationService.Current.LoggedInUserId,
                    Fields           = new[] { ItemFields.MediaSources, ItemFields.SyncInfo }
                };

                var tracks = await ApiClient.GetItemsAsync(query);

                if (tracks.Items.IsNullOrEmpty())
                {
                    return;
                }

                AlbumTracks = tracks.Items.OrderBy(x => x.ParentIndexNumber)
                              .ThenBy(x => x.IndexNumber).ToList();
            }
            catch (HttpException ex)
            {
                Utils.HandleHttpException("GetAlbumTracks()", ex, NavigationService, Log);
            }
        }
예제 #6
0
        private Task <ItemsResult> GetLatestMoviesAsync(ItemListViewModel viewModel)
        {
            var query = new ItemQuery
            {
                Fields = new[]
                {
                    ItemFields.PrimaryImageAspectRatio,
                    ItemFields.DateCreated,
                    ItemFields.DisplayPreferencesId
                },

                UserId = _sessionManager.CurrentUser.Id,

                SortBy = new[] { ItemSortBy.DateCreated },

                SortOrder = SortOrder.Descending,

                IncludeItemTypes = new[] { "Movie" },

                Filters = new[] { ItemFilter.IsUnplayed },

                Limit = 8,

                Recursive = true
            };

            return(ApiClient.GetItemsAsync(query));
        }
        private async Task <bool> GetBoxsets()
        {
            try
            {
                SetProgressBar("Getting boxsets...");

                var query = new ItemQuery
                {
                    UserId           = AuthenticationService.Current.LoggedInUser.Id,
                    SortBy           = new[] { "SortName" },
                    SortOrder        = SortOrder.Ascending,
                    IncludeItemTypes = new[] { "BoxSet" },
                    Recursive        = true
                };

                var itemResponse = await _apiClient.GetItemsAsync(query);

                return(await SetBoxsets(itemResponse));
            }
            catch (HttpException ex)
            {
                Log.ErrorException("GetBoxsets()", ex);
            }

            SetProgressBar();

            return(false);
        }
예제 #8
0
        internal static ItemQuery GetRecentItemsQuery(string id = null, string[] excludedItemTypes = null)
        {
            var query = new ItemQuery
            {
                Filters  = new[] { ItemFilter.IsRecentlyAdded, ItemFilter.IsNotFolder },
                ParentId = id,
                UserId   = AuthenticationService.Current.LoggedInUserId,
                Fields   = new[]
                {
                    ItemFields.DateCreated,
                    ItemFields.ProviderIds,
                    ItemFields.ParentId,
                    ItemFields.CumulativeRunTimeTicks,
                    ItemFields.MediaSources,
                    ItemFields.SyncInfo
                },
                ExcludeItemTypes = excludedItemTypes,
                IsVirtualUnaired = App.SpecificSettings.ShowUnairedEpisodes,
                IsMissing        = App.SpecificSettings.ShowMissingEpisodes,
                Recursive        = true,
                Limit            = 50,
                SortBy           = new[] { ItemSortBy.DateCreated },
                SortOrder        = SortOrder.Descending,
                ImageTypeLimit   = 1,
                EnableImageTypes = new[] { ImageType.Backdrop, ImageType.Primary, }
            };

            return(query);
        }
        private Task <ItemsResult> GetMultiPlayerGames(ItemListViewModel viewModel, DisplayPreferences displayPreferences)
        {
            var query = new ItemQuery
            {
                Fields = FolderPage.QueryFields,

                UserId = _sessionManager.CurrentUser.Id,

                IncludeItemTypes = new[] { "Game" },

                SortBy = !String.IsNullOrEmpty(displayPreferences.SortBy)
                             ? new[] { displayPreferences.SortBy }
                             : new[] { ItemSortBy.SortName },

                SortOrder = displayPreferences.SortOrder,

                MinPlayers = 2,

                Recursive = true
            };

            var indexOption = viewModel.CurrentIndexOption;

            if (indexOption != null)
            {
                query.MinPlayers = query.MaxPlayers = int.Parse(indexOption.Name);
            }

            return(ApiClient.GetItemsAsync(query));
        }
예제 #10
0
        private async Task <IEnumerable <Movie> > GetMoviesFromEmby(string parentId, CancellationToken cancellationToken)
        {
            var query = new ItemQuery
            {
                SortBy           = new[] { "sortname" },
                SortOrder        = SortOrder.Ascending,
                EnableImageTypes = new[] { ImageType.Banner, ImageType.Primary, ImageType.Thumb, ImageType.Logo },
                ParentId         = parentId,
                Recursive        = true,
                UserId           = _settings.EmbyUserId,
                IncludeItemTypes = new[] { nameof(Movie) },
                Fields           = new[]
                {
                    ItemFields.Genres, ItemFields.DateCreated, ItemFields.MediaSources, ItemFields.HomePageUrl,
                    ItemFields.OriginalTitle, ItemFields.Studios, ItemFields.MediaStreams, ItemFields.Path,
                    ItemFields.Overview, ItemFields.ProviderIds, ItemFields.SortName, ItemFields.ParentId,
                    ItemFields.People
                }
            };

            var embyMovies = await _embyClient.GetItemsAsync(query, cancellationToken);

            Log.Information($"Ready to add movies to database. We found {embyMovies.TotalRecordCount} movies");
            return(embyMovies.Items.Select(MovieHelper.ConvertToMovie));
        }
예제 #11
0
        private async Task <ItemsResult> GetCollectionItems(int limit, ImageType imageType = ImageType.Primary)
        {
            var query = new ItemQuery
            {
                IncludeItemTypes = new[] { "Season", "Series", "Movie", "Album" },
                Limit            = limit,
                SortBy           = new[] { ItemSortBy.Random },
                UserId           = AuthenticationService.Current.LoggedInUserId,
                ImageTypes       = new[] { imageType },
                Recursive        = true
            };

            try
            {
                var itemResponse = await _connectionManager.GetApiClient(App.ServerInfo.Id).GetItemsAsync(query);

                return(itemResponse);
            }
            catch (HttpException ex)
            {
                _logger.ErrorException("GetCollectionItems(" + imageType + ")", ex);
            }

            return(null);
        }
예제 #12
0
        internal async Task <PendingGetResult> DownloadItems(IList <ItemKey> keys, IList <string> typeVersions, PendingGetCompletionDelegate callback, CancellationToken cancelToken)
        {
            var result = new PendingGetResult();

            try
            {
                result.KeysRequested = keys;

                ItemQuery query = this.CreateRefreshQueryForKeys(keys, typeVersions);

                IList <RecordItem> items = await m_remoteStore.GetAllItemsAsync(query);

                await this.PersistDownloadedItemsAsync(items);

                result.KeysFound = (
                    from item in items
                    select item.Key
                    ).ToArray();
            }
            catch (Exception ex)
            {
                result.Exception = ex;
            }

            NotifyPendingGetComplete(callback, result);

            return(result);
        }
        private async Task <bool> GetAlbums()
        {
            var query = new ItemQuery
            {
                Recursive        = true,
                Fields           = new[] { ItemFields.ParentId, },
                IncludeItemTypes = new[] { "MusicAlbum" },
                UserId           = AuthenticationService.Current.LoggedInUser.Id
            };

            try
            {
                var itemsResponse = await _apiClient.GetItemsAsync(query);

                if (itemsResponse == null)
                {
                    return(false);
                }

                var items = itemsResponse.Items.ToList();

                Albums = await Utils.GroupItemsByName(items);

                return(true);
            }
            catch (HttpException ex)
            {
                Log.ErrorException("GetAlbums()", ex);
            }

            return(false);
        }
        private async Task GetGenreTracks(string genreName)
        {
            if (!_navigationService.IsNetworkAvailable)
            {
                return;
            }

            SetProgressBar("Getting genre tracks");

            try
            {
                var query = new ItemQuery
                {
                    UserId           = AuthenticationService.Current.LoggedInUser.Id,
                    Genres           = new[] { genreName },
                    Recursive        = true,
                    IncludeItemTypes = new[] { "Audio" }
                };

                Log.Info("Getting tracks for genre [{0}]", genreName);

                var itemResponse = await _apiClient.GetItemsAsync(query);

                SendItemsToPlaylist(itemResponse);
            }
            catch (HttpException ex)
            {
                Log.ErrorException(string.Format("GetGenreTracks({0})", genreName), ex);
            }

            SetProgressBar();
        }
예제 #15
0
        private Task <ItemsResult> GetSeriesByGenre(ItemListViewModel viewModel, DisplayPreferences displayPreferences)
        {
            var apiClient = _sessionFactory().ActiveApiClient;

            var query = new ItemQuery
            {
                Fields = FolderPage.QueryFields,

                UserId = _sessionFactory().LocalUserId,

                IncludeItemTypes = new[] { "Series" },

                SortBy = !String.IsNullOrEmpty(displayPreferences.SortBy)
                             ? new[] { displayPreferences.SortBy }
                             : new[] { ItemSortBy.SortName },

                SortOrder = displayPreferences.SortOrder,

                Recursive = true
            };

            var indexOption = viewModel.CurrentIndexOption;

            if (indexOption != null)
            {
                query.Genres = new[] { indexOption.Name };
            }

            return(apiClient.GetItemsAsync(query, CancellationToken.None));
        }
        private async Task <ItemsResult> GetRecentlyPlayedAsync(ItemListViewModel viewModel)
        {
            var query = new ItemQuery
            {
                Fields = new[]
                {
                    ItemFields.PrimaryImageAspectRatio,
                    ItemFields.DateCreated,
                    ItemFields.DisplayPreferencesId
                },

                UserId = _sessionManager.CurrentUser.Id,

                SortBy = new[] { ItemSortBy.DatePlayed },

                SortOrder = SortOrder.Descending,

                Filters = new[] { ItemFilter.IsPlayed },

                IncludeItemTypes = new[] { "Game" },

                Recursive = true,

                Limit = 6
            };

            var result = await ApiClient.GetItemsAsync(query);

            ShowRecentlyPlayed = result.Items.Length > 0;

            return(result);
        }
        private async Task <bool> GetAlbums()
        {
            var query = new ItemQuery
            {
                ParentId         = _parentId,
                Recursive        = true,
                Fields           = new[] { ItemFields.ParentId, ItemFields.SortName, ItemFields.MediaSources, ItemFields.SyncInfo, },
                IncludeItemTypes = new[] { "MusicAlbum" },
                UserId           = AuthenticationService.Current.LoggedInUserId,
                ImageTypeLimit   = 1,
                EnableImageTypes = new[] { ImageType.Backdrop, ImageType.Primary, }
            };

            try
            {
                var itemsResponse = await ApiClient.GetItemsAsync(query);

                if (itemsResponse == null)
                {
                    return(false);
                }

                var items = itemsResponse.Items.ToList();

                Albums = await Utils.GroupItemsByName(items);

                return(true);
            }
            catch (HttpException ex)
            {
                Utils.HandleHttpException("GetAlbums()", ex, NavigationService, Log);
            }

            return(false);
        }
        private async Task <bool> GetShows()
        {
            try
            {
                SetProgressBar(AppResources.SysTrayGettingShows);

                var query = new ItemQuery
                {
                    ParentId         = _parentId,
                    UserId           = AuthenticationService.Current.LoggedInUserId,
                    SortBy           = new[] { "SortName" },
                    SortOrder        = SortOrder.Ascending,
                    IncludeItemTypes = new[] { "Series" },
                    Fields           = new[] { ItemFields.DateCreated, ItemFields.SyncInfo },
                    Recursive        = true,
                    ImageTypeLimit   = 1,
                    EnableImageTypes = new[] { ImageType.Backdrop, ImageType.Primary }
                };

                Log.Info("Getting TV shows");

                var itemResponse = await ApiClient.GetItemsAsync(query);

                return(await SetShows(itemResponse));
            }
            catch (HttpException ex)
            {
                Utils.HandleHttpException("GetShows()", ex, NavigationService, Log);
            }

            SetProgressBar();

            return(false);
        }
예제 #19
0
        private async Task <Boolean> GeSearchItemsAsync()
        {
            SearchHintResult searchHintResult = await _apiClient.GetSearchHintsAsync(new SearchQuery
            {
                UserId         = _apiClient.CurrentUserId,
                SearchTerm     = CurrentSearch,
                IncludePeople  = false,
                IncludeStudios = false,
                Limit          = 9,
                IncludeGenres  = false,
                IncludeArtists = false,
                IncludeMedia   = true
            });

            var ids = (searchHintResult.TotalRecordCount > 0) ? searchHintResult.SearchHints.Select(s => s.ItemId).ToArray() : null;

            if (ids != null && ids.Length > 0)
            {
                var query = new ItemQuery
                {
                    Ids    = ids,
                    UserId = _apiClient.CurrentUserId,
                    Fields = FolderPage.QueryFields
                };

                _searchedItemsResult = await _apiClient.GetItemsAsync(query, CancellationToken.None);
            }
            else
            {
                _searchedItemsResult = _emptyItemsResult;
            }

            return(true);
        }
예제 #20
0
        /// <summary>
        /// Creates a url to return a list of items
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="listType">The type of list to retrieve.</param>
        /// <returns>System.String.</returns>
        /// <exception cref="System.ArgumentNullException">query</exception>
        protected string GetItemListUrl(ItemQuery query, string listType = null)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            var dict = new QueryStringDictionary {
            };

            dict.AddIfNotNullOrEmpty("listtype", listType);
            dict.AddIfNotNullOrEmpty("ParentId", query.ParentId);

            dict.AddIfNotNull("startindex", query.StartIndex);

            dict.AddIfNotNull("limit", query.Limit);

            dict.AddIfNotNull("sortBy", query.SortBy);

            dict.AddIfNotNull("IsPlayed", query.IsPlayed);
            dict.AddIfNotNull("CollapseBoxSetItems", query.CollapseBoxSetItems);

            if (query.SortOrder.HasValue)
            {
                dict["sortOrder"] = query.SortOrder.ToString();
            }

            if (query.Fields != null)
            {
                dict.Add("fields", query.Fields.Select(f => f.ToString()));
            }
            if (query.Filters != null)
            {
                dict.Add("Filters", query.Filters.Select(f => f.ToString()));
            }
            if (query.ImageTypes != null)
            {
                dict.Add("ImageTypes", query.ImageTypes.Select(f => f.ToString()));
            }

            dict.Add("recursive", query.Recursive);

            dict.AddIfNotNull("genres", query.Genres);
            dict.AddIfNotNull("Ids", query.Ids);
            dict.AddIfNotNull("studioIds", query.StudioIds);
            dict.AddIfNotNull("ExcludeItemTypes", query.ExcludeItemTypes);
            dict.AddIfNotNull("IncludeItemTypes", query.IncludeItemTypes);
            dict.AddIfNotNull("ExcludeLocationTypes", query.ExcludeLocationTypes.Select(t => t.ToString()));

            dict.AddIfNotNull("personIds", query.PersonIds);
            dict.AddIfNotNull("personTypes", query.PersonTypes);

            dict.AddIfNotNull("years", query.Years);

            dict.AddIfNotNullOrEmpty("SearchTerm", query.SearchTerm);
            dict.AddIfNotNullOrEmpty("MaxOfficialRating", query.MaxOfficialRating);
            dict.AddIfNotNullOrEmpty("MinOfficialRating", query.MinOfficialRating);

            return(GetApiUrl("Users/" + query.UserId + "/Items", dict));
        }
        private async Task <bool> GetLatestUnwatched()
        {
            try
            {
                SetProgressBar("Getting latest unwatched items...");

                var query = new ItemQuery
                {
                    UserId           = AuthenticationService.Current.LoggedInUser.Id,
                    SortBy           = new[] { "DateCreated" },
                    SortOrder        = SortOrder.Descending,
                    IncludeItemTypes = new[] { "Movie" },
                    Limit            = 9,
                    Fields           = new[] { ItemFields.PrimaryImageAspectRatio },
                    Filters          = new[] { ItemFilter.IsUnplayed },
                    Recursive        = true
                };

                Log.Info("Getting next up items");

                var itemResponse = await _apiClient.GetItemsAsync(query);

                return(SetLatestUnwatched(itemResponse));
            }
            catch (HttpException ex)
            {
                Log.ErrorException("GetLatestUnwatched()", ex);
            }

            SetProgressBar();

            return(false);
        }
예제 #22
0
 protected override void OnInitialized()
 {
     Query = new ItemQuery
     {
         ItemType = "Category"
     };
 }
        public ItemQuery GetSynchronizationQuery()
        {
            ItemQuery query      = m_data.Query;
            int       maxResults = (query.MaxResults) != null ? m_data.Query.MaxResults.Value : 0;

            return(ItemQuery.QueryForKeys(query.Filters, maxResults));
        }
예제 #24
0
 public void Query_ItemErrorTag()
 {
     Assert.IsTrue(ItemQuery.TryParseQuery("<af:item type=\"xxx_Repository\" id=\"F093C899A07D4BACAADE61B7CF6266D6\" />", out var query));
     Assert.AreEqual("xxx_Repository", query.Type);
     Assert.AreEqual("F093C899A07D4BACAADE61B7CF6266D6", query.Id);
     Assert.IsNull(query.ConfigId);
     Assert.AreEqual(ItemQueryType.ById, query.QueryType);
 }
예제 #25
0
 public void Query_JavascriptShowItem()
 {
     Assert.IsTrue(ItemQuery.TryParseQuery("javascript:top.aras.uiShowItem('xxx_Data', '14D5342627E14EFC93AC49D626D2ADDB')", out var query));
     Assert.AreEqual("xxx_Data", query.Type);
     Assert.AreEqual("14D5342627E14EFC93AC49D626D2ADDB", query.Id);
     Assert.IsNull(query.ConfigId);
     Assert.AreEqual(ItemQueryType.ById, query.QueryType);
 }
예제 #26
0
 public void Query_PermissionErrorTag()
 {
     Assert.IsTrue(ItemQuery.TryParseQuery("<af:permission type=\"can_update\" itemtype=\"ItemType\" id=\"45E899CD2859442982EB22BB2DF683E5\" />", out var query));
     Assert.AreEqual("ItemType", query.Type);
     Assert.AreEqual("45E899CD2859442982EB22BB2DF683E5", query.Id);
     Assert.IsNull(query.ConfigId);
     Assert.AreEqual(ItemQueryType.ById, query.QueryType);
 }
예제 #27
0
 public void Query_ItemTag()
 {
     Assert.IsTrue(ItemQuery.TryParseQuery("<Item type=\"CommandBarSection\" id=\"009B59BBA3F04901A70A6CB9C3FAF1D9\">", out var query));
     Assert.AreEqual("CommandBarSection", query.Type);
     Assert.AreEqual("009B59BBA3F04901A70A6CB9C3FAF1D9", query.Id);
     Assert.IsNull(query.ConfigId);
     Assert.AreEqual(ItemQueryType.ById, query.QueryType);
 }
예제 #28
0
 public void Query_ItemProperty()
 {
     Assert.IsTrue(ItemQuery.TryParseQuery("<related_id type=\"CommandBarButton\">D5B9AF7B219A4F1A8EC56ED2168A6345</related_id>", out var query));
     Assert.AreEqual("CommandBarButton", query.Type);
     Assert.AreEqual("D5B9AF7B219A4F1A8EC56ED2168A6345", query.Id);
     Assert.IsNull(query.ConfigId);
     Assert.AreEqual(ItemQueryType.ById, query.QueryType);
 }
예제 #29
0
 public void Query_ReleasedUrl()
 {
     Assert.IsTrue(ItemQuery.TryParseQuery("http://server/InnovatorServer/?StartItem=Method:DF8461A4421443879C31CE2D426B5673:released", out var query));
     Assert.AreEqual("Method", query.Type);
     Assert.IsNull(query.Id);
     Assert.AreEqual("DF8461A4421443879C31CE2D426B5673", query.ConfigId);
     Assert.AreEqual(ItemQueryType.Released, query.QueryType);
 }
예제 #30
0
 public void Query_SimpleUrl()
 {
     Assert.IsTrue(ItemQuery.TryParseQuery("http://server/InnovatorServer/?StartItem=Method:162592F32CAA4BDE830A56C500F53E91", out var query));
     Assert.AreEqual("Method", query.Type);
     Assert.AreEqual("162592F32CAA4BDE830A56C500F53E91", query.Id);
     Assert.IsNull(query.ConfigId);
     Assert.AreEqual(ItemQueryType.ById, query.QueryType);
 }