bakes82 159 Posted October 3, 2020 Posted October 3, 2020 Im making a schedule task to automate some collections till I move on to the UI. What service is used to find if a "Collection" exists by name, and then how do we add items to a collection. This is what I have so far which I think is correct. I assume Containers = Librarys which are Guids/strings from what I can tell based off the parent ID in the query string EX: &parentId=f137a2dd21bbc1b99aa5c0f6bf02a805 @chef var collectionsToProcess = new List<TraktCollectionsVideos>(); var numComplete = 0; var totalItems = 0; if (Plugin.Instance.Configuration.Collections.Any()) { foreach (var traktCollection in Plugin.Instance.Configuration.Collections) { var items = _libraryManager.GetItemList(new InternalItemsQuery { MediaTypes = new[] { MediaType.Video }, IsVirtualItem = false, Containers = traktCollection.LibraryList.ToArray() }).OfType<Video>().ToList(); collectionsToProcess.Add(new TraktCollectionsVideos() { TraktCollection = traktCollection, Videos = items }); totalItems += items.Count; } if (collectionsToProcess.Any()) { foreach (var collectionsVideos in collectionsToProcess) { //Find Collection By Name //If not found make new //Else append new items where Ids matched } } } 2
chef 3808 Posted October 7, 2020 Posted October 7, 2020 (edited) Hi @bakes82 That looks proper to me To query Collections I do this: var result = LibraryManager.GetItemIds(new InternalItemsQuery { IncludeItemTypes = new[] { "collections", "Boxset" }, User = user ////try using the user with policy.IsAdministator for testing }); Now get each of the collections items: var collectionQuery = LibraryManager.QueryItems(new InternalItemsQuery() { ListIds = new[] { result.InternalId }, EnableAutoSort = true, OrderBy = new[] { ItemSortBy.PremiereDate }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Ascending)).ToArray(), }); //To search By Name use "Name = " var result = LibraryManager.GetItemIds(new InternalItemsQuery { Name = "My_COLLECTION_NAME", IncludeItemTypes = new[] { "collections", "Boxset" }, User = user ////try using the user with policy.IsAdministator for testing }); There are different ways to handle collections. What I did for collections was create a dictionary object, to access, quickly, without having to query over and over again... I create the dictionary with the Key as the collection BaseItem, and then the Value being a List of the collection items. public Dictionary<BaseItem, List<BaseItem>> GetCollectionItems() { var result = LibraryManager.GetItemIds(new InternalItemsQuery { IncludeItemTypes = new[] { "collections", "Boxset" }, User = user //try using the user with policy.IsAdministator for testing }); var collectionQuery = LibraryManager.QueryItems(new InternalItemsQuery() { ListIds = new[] { result.InternalId }, EnableAutoSort = true, OrderBy = new[] { ItemSortBy.PremiereDate }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Ascending)).ToArray(), }); return new Dictionary<BaseItem, List<BaseItem>>() { { result, collectionQuery.Items.ToList() } }; } There may be a better way of doing this, but this way was easiest for me to move a collection object around quickly. I haven't tried to add things to a collection through the API... I'd have to take a look and see. EDIT: I'm just wondering about keeping collection data in the PluginConfiguration like that? I'm wondering if you can create a collection type and add it to the emby media dB? Edited October 7, 2020 by chef
bakes82 159 Posted October 20, 2020 Author Posted October 20, 2020 @chef How do you make a channel and add items to it like in the new release. I see in the new release you get a channel and return a list of items, but am I missing where it actually creates it? var channel = LibraryManager.GetItemList(new InternalItemsQuery() { Name = "New Releases" });
pünktchen 1350 Posted May 21, 2021 Posted May 21, 2021 On 10/7/2020 at 6:47 PM, chef said: To query Collections I do this: var result = LibraryManager.GetItemIds(new InternalItemsQuery { IncludeItemTypes = new[] { "collections", "Boxset" }, User = user ////try using the user with policy.IsAdministator for testing }); Now get each of the collections items: var collectionQuery = LibraryManager.QueryItems(new InternalItemsQuery() { ListIds = new[] { result.InternalId }, EnableAutoSort = true, OrderBy = new[] { ItemSortBy.PremiereDate }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Ascending)).ToArray(), }); @Luke @chef How to get the items that are part of a collection with the new 4.6.x release?
Luke 40086 Posted May 21, 2021 Posted May 21, 2021 On an InternalItemsQuery, use the CollectionIds filter. 1
pünktchen 1350 Posted May 21, 2021 Posted May 21, 2021 14 minutes ago, Luke said: On an InternalItemsQuery, use the CollectionIds filter. Aha, this is a new filter. Working! 1 1
chef 3808 Posted June 8, 2021 Posted June 8, 2021 @pünktchen Do you have a code sample here? Something has messed up my collection query code and I don't know what it is... It might be this... Maybe.
roaku 836 Posted June 8, 2021 Posted June 8, 2021 12 minutes ago, chef said: @pünktchen Do you have a code sample here? Something has messed up my collection query code and I don't know what it is... It might be this... Maybe. For 4.6, I had to update my querying for collection items to differentiate between collections and playlists. 'ListIds' still worked for Playlists, but the new collections had to be queried by 'CollectionIds'. long[] collectionItemIds = new long[]{}; if (isPlaylist) { collectionItemIds = _libraryManager.GetInternalItemIds(new InternalItemsQuery() { ListIds = new[] {collectionInternalId} }); } else { collectionItemIds = _libraryManager.GetInternalItemIds(new InternalItemsQuery() { //this is a new thing for 4.6 collections CollectionIds = new[] {collectionInternalId} }); } 1
chef 3808 Posted June 8, 2021 Posted June 8, 2021 15 minutes ago, roaku said: For 4.6, I had to update my querying for collection items to differentiate between collections and playlists. 'ListIds' still worked for Playlists, but the new collections had to be queried by 'CollectionIds'. long[] collectionItemIds = new long[]{}; if (isPlaylist) { collectionItemIds = _libraryManager.GetInternalItemIds(new InternalItemsQuery() { ListIds = new[] {collectionInternalId} }); } else { collectionItemIds = _libraryManager.GetInternalItemIds(new InternalItemsQuery() { //this is a new thing for 4.6 collections CollectionIds = new[] {collectionInternalId} }); } Did you notice a change in the "SupportsPositionTicksResume" as well. Looks like it changed to "SupportsPlayedStatus" with a minimum Duration value in seconds.
roaku 836 Posted June 8, 2021 Posted June 8, 2021 2 minutes ago, chef said: Did you notice a change in the "SupportsPositionTicksResume" as well. Looks like it changed to "SupportsPlayedStatus" with a minimum Duration value in seconds. Sorry, I've never used that myself, so I'm not familiar with how it might have changed. 1
chef 3808 Posted June 8, 2021 Posted June 8, 2021 3 minutes ago, roaku said: Sorry, I've never used that myself, so I'm not familiar with how it might have changed. That change did fix my issue. Thank you 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now