private async Task <bool> GetGenres()
        {
            var query = new ItemsByNameQuery
            {
                ParentId         = _parentId,
                SortBy           = new[] { "SortName" },
                SortOrder        = SortOrder.Ascending,
                IncludeItemTypes = new[] { "Audio", "MusicVideo" },
                Recursive        = true,
                Fields           = new[] { ItemFields.DateCreated, ItemFields.MediaSources, ItemFields.SyncInfo, },
                UserId           = AuthenticationService.Current.LoggedInUserId,
                ImageTypeLimit   = 1,
                EnableImageTypes = new[] { ImageType.Backdrop, ImageType.Primary, }
            };

            try
            {
                var genresResponse = await ApiClient.GetGenresAsync(query);

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

                Genres = genresResponse.Items.ToList();

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

            return(false);
        }
        /// <summary>
        /// Gets the item by name list URL.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="query">The query.</param>
        /// <returns>System.String.</returns>
        /// <exception cref="System.ArgumentNullException">query</exception>
        protected string GetItemByNameListUrl(string type, ItemsByNameQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            var dict = new QueryStringDictionary {
            };

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

            dict.Add("UserId", query.UserId);
            dict.AddIfNotNull("StartIndex", query.StartIndex);

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

            dict.AddIfNotNullOrEmpty("NameStartsWith", query.NameStartsWith);
            dict.AddIfNotNullOrEmpty("NameStartsWithOrGreater", query.NameStartsWithOrGreater);
            dict.AddIfNotNullOrEmpty("NameLessThan", query.NameLessThan);

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

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

            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()));
            }

            var personQuery = query as PersonsQuery;

            if (personQuery != null && personQuery.PersonTypes != null)
            {
                dict.Add("PersonTypes", personQuery.PersonTypes.Select(f => f.ToString()));
            }

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

            dict.AddIfNotNull("MediaTypes", query.MediaTypes);
            dict.AddIfNotNull("ExcludeItemTypes", query.ExcludeItemTypes);
            dict.AddIfNotNull("IncludeItemTypes", query.IncludeItemTypes);

            return(GetApiUrl(type, dict));
        }
예제 #3
0
        private async Task ProcessGenresFromEmby(string id, IEnumerable <string> genresNeeded, CancellationToken cancellationToken)
        {
            var query = new ItemsByNameQuery
            {
                ParentId  = id,
                Recursive = true
            };

            var embyGenres = await _embyClient.GetGenresAsync(query, cancellationToken);

            var existingGenres = _genreRepository.GetIds();

            var newGenres = embyGenres
                            .Items
                            .Where(x => genresNeeded.Any(y => y == x.Id))
                            .Where(x => existingGenres.All(y => y != x.Id))
                            .ToList();

            if (newGenres.Any())
            {
                Log.Information($"Need to add {newGenres.Count} genres first ({string.Join(", ", newGenres.Select(x => x.Name))})");
                var genres = newGenres.Select(GenreHelper.ConvertToGenre);
                _genreRepository.AddRangeIfMissing(genres);
            }
            else
            {
                Log.Information("No new genres to add");
            }
        }
        private async Task <bool> GetGenres()
        {
            var query = new ItemsByNameQuery
            {
                SortBy           = new[] { "SortName" },
                SortOrder        = SortOrder.Ascending,
                IncludeItemTypes = new[] { "Audio", "MusicVideo" },
                Recursive        = true,
                Fields           = new[] { ItemFields.DateCreated },
                UserId           = AuthenticationService.Current.LoggedInUser.Id
            };

            try
            {
                var genresResponse = await _apiClient.GetGenresAsync(query);

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

                Genres = genresResponse.Items.ToList();

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

            return(false);
        }
        /// <summary>
        /// Gets the item by name list URL.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="query">The query.</param>
        /// <returns>System.String.</returns>
        /// <exception cref="System.ArgumentNullException">query</exception>
        protected Uri GetItemByNameListUrl(string type, ItemsByNameQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            var dict = new NameValueCollection {
            };

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

            dict.Add("UserId", query.UserId);
            dict.AddIfNotNull("StartIndex", query.StartIndex);

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

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

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

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

            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("MediaTypes", query.MediaTypes);
            dict.AddIfNotNull("ExcludeItemTypes", query.ExcludeItemTypes);
            dict.AddIfNotNull("IncludeItemTypes", query.IncludeItemTypes);

            dict.AddIfNotNullOrEmpty("NameLessThan", query.NameLessThan);
            dict.AddIfNotNullOrEmpty("NameStartsWithOrGreater", query.NameStartsWithOrGreater);

            dict.AddIfNotNull("EnableImages", query.EnableImages);
            if (query.EnableImageTypes != null)
            {
                dict.Add("EnableImageTypes", query.EnableImageTypes.Select(f => f.ToString()));
            }
            dict.AddIfNotNull("ImageTypeLimit", query.ImageTypeLimit);

            return(GetApiUrl(new Uri(type, UriKind.Relative), dict));
        }
예제 #6
0
        public async Task <QueryResult <BaseItemDto> > GetGenresAsync(ItemsByNameQuery query, CancellationToken cancellationToken = default(CancellationToken))
        {
            var url = GetItemByNameListUrl("Genres", query);

            using (var stream = await GetSerializedStreamAsync(url, cancellationToken))
            {
                return(DeserializeFromStream <QueryResult <BaseItemDto> >(stream));
            }
        }
예제 #7
0
        /// <summary>
        /// Gets the studios.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="onSuccess">The on success.</param>
        /// <param name="onError">The on error.</param>
        /// <exception cref="System.ArgumentNullException">query</exception>
        public void GetStudios(ItemsByNameQuery query, Action <ItemsResult> onSuccess, Action <Exception> onError)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            string url = base.GetItemByNameListUrl("Studios", query);

            GetSerializedData(url, onSuccess, onError);
        }
        private async Task <bool> GetGenres()
        {
            try
            {
                SetProgressBar(AppResources.SysTrayGettingGenres);

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

                var items = await ApiClient.GetGenresAsync(query);

                if (!items.Items.IsNullOrEmpty())
                {
                    var genres = items.Items.ToList();
                    genres.ForEach(genre => genre.Type = "Genre - " + AppResources.LabelMovies.ToUpper());

                    Genres = genres;

                    SetProgressBar();

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

            SetProgressBar();

            return(false);
        }
        private async Task <bool> GetGenres()
        {
            try
            {
                SetProgressBar("Getting genres...");

                var query = new ItemsByNameQuery
                {
                    SortBy           = new[] { "SortName" },
                    SortOrder        = SortOrder.Ascending,
                    IncludeItemTypes = new[] { "Series" },
                    Recursive        = true,
                    Fields           = new[] { ItemFields.DateCreated },
                    UserId           = AuthenticationService.Current.LoggedInUser.Id
                };

                var items = await _apiClient.GetGenresAsync(query);

                if (!items.Items.IsNullOrEmpty())
                {
                    var genres = items.Items.ToList();
                    genres.ForEach(genre => genre.Type = "Genre - TV");

                    Genres = genres;

                    SetProgressBar();

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

            SetProgressBar();

            return(false);
        }
예제 #10
0
        /// <summary>
        /// Gets the item by name list URL.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="query">The query.</param>
        /// <returns>System.String.</returns>
        /// <exception cref="System.ArgumentNullException">query</exception>
        protected string GetItemByNameListUrl(string type, ItemsByNameQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            var dict = new QueryStringDictionary {
            };

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

            dict.Add("UserId", query.UserId);
            dict.AddIfNotNull("StartIndex", query.StartIndex);

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

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

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

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

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

            dict.AddIfNotNull("MediaTypes", query.MediaTypes);
            dict.AddIfNotNull("ExcludeItemTypes", query.ExcludeItemTypes);
            dict.AddIfNotNull("IncludeItemTypes", query.IncludeItemTypes);

            return(GetApiUrl(type, dict));
        }
        public IEnumerable <BaseItem> RetrieveMusicArtists(ItemsByNameQuery query)
        {
            var dtos = Kernel.ApiClient.GetArtists(query);

            return(dtos == null ? new BaseItem[] {} : dtos.Items.Select(dto => GetItem(dto, dto.Type)).Where(item => item != null));
        }
        public IEnumerable <BaseItem> RetrieveIbnItems(string ibnName, ItemsByNameQuery query)
        {
            var dtos = Kernel.ApiClient.GetIbnItems(ibnName, query);

            return(dtos == null ? new BaseItem[] {} : dtos.Items.Select(dto => GetItem(dto, dto.Type)).Where(item => item != null));
        }
예제 #13
0
        public virtual IEnumerable <BaseItem> IndexBy(string property)
        {
            if (string.IsNullOrEmpty(property))
            {
                throw new ArgumentException("Index type should not be none!");
            }

            if (property == LocalizedStrings.Instance.GetString("GenreDispPref"))
            {
                var query = new ItemQuery
                {
                    UserId    = Kernel.CurrentUser.ApiId,
                    ParentId  = ApiId,
                    Recursive = true,
                    Fields    = new[] { ItemFields.SortName },
                    SortBy    = new[] { "SortName" }
                };

                var ret = CollectionType == "Music" || ContainsMusic?
                          Kernel.Instance.MB3ApiRepository.RetrieveMusicGenres(query).Select(g => new ApiGenreFolder(g, ApiId, new[] { "MusicAlbum" }, null, this)).Cast <BaseItem>().ToList() :
                              Kernel.Instance.MB3ApiRepository.RetrieveGenres(query).Select(g => new ApiGenreFolder(g, ApiId, null, null, this)).Cast <BaseItem>().ToList();

                ApiRecursiveItemCount = ret.Count;
                Logger.ReportVerbose("=========== Indexing with new technique...");
                return(ret);
            }
            else if (property == LocalizedStrings.Instance.GetString("ActorDispPref"))
            {
                var personTypes = new[] { PersonType.Actor, PersonType.GuestStar };
                var ret         = LocalizedStrings.Instance.GetString("StartingLetters").Select(c => new PersonLetterFolder(c.ToString(), false, ApiId, personTypes, null, null, this)).Cast <BaseItem>().ToList();
                ret.Add(new PersonLetterFolder("#", true, ApiId, personTypes, null, null, this));
                ApiRecursiveItemCount = ret.Count;
                return(ret);
            }
            else if (property == LocalizedStrings.Instance.GetString("DirectorDispPref"))
            {
                var personTypes = new[] { PersonType.Director };
                var ret         = LocalizedStrings.Instance.GetString("StartingLetters").Select(c => new PersonLetterFolder(c.ToString(), false, ApiId, personTypes, null, null, this)).Cast <BaseItem>().ToList();
                ret.Add(new PersonLetterFolder("#", true, ApiId, personTypes, null, null, this));
                ApiRecursiveItemCount = ret.Count;
                return(ret);
            }
            else if (property == LocalizedStrings.Instance.GetString("YearDispPref"))
            {
                var query = new ItemsByNameQuery
                {
                    UserId    = Kernel.CurrentUser.ApiId,
                    ParentId  = ApiId,
                    Recursive = true,
                    Fields    = new[] { ItemFields.SortName },
                    SortBy    = new[] { "SortName" },
                };
                var ret = Kernel.Instance.MB3ApiRepository.RetrieveIbnItems("Years", query).Select(p => new ApiYearFolder(p, ApiId, null, new[] { "Audio" }, this)).Cast <BaseItem>().ToList();
                ApiRecursiveItemCount = ret.Count;
                return(ret);
            }
            else if (property == LocalizedStrings.Instance.GetString("StudioDispPref"))
            {
                var query = new ItemsByNameQuery
                {
                    UserId    = Kernel.CurrentUser.ApiId,
                    ParentId  = ApiId,
                    Recursive = true,
                    Fields    = new[] { ItemFields.SortName },
                    SortBy    = new[] { "SortName" },
                };
                var ret = Kernel.Instance.MB3ApiRepository.RetrieveIbnItems("Studios", query).Select(p => new ApiStudioFolder(p, ApiId, null, new[] { "Audio" }, this)).Cast <BaseItem>().ToList();
                ApiRecursiveItemCount = ret.Count;
                return(ret);
            }

            return(Kernel.Instance.MB3ApiRepository.RetrieveChildren(this.ApiId));
        }