jelum 17 Posted February 17, 2023 Share Posted February 17, 2023 How I can add a movie to a collection using C#? I'm developing a plugin and want to be able to add a movie to a newly created collection during, for example, Refresh Metadata/Identify action. I tried: QueryResult<BaseItem> collections = _libraryManager.QueryItems(new InternalItemsQuery() { IncludeItemTypes = new[] { "collections", "Boxset" }, Name = collectionName }); // one collection item found if (movieItem.AddCollection((BoxSet)collections.Items[0])) { // once with UpdateToRepository, once without movieItem.UpdateToRepository(ItemUpdateType.None); // movieItem.UpdateToRepository(ItemUpdateType.MetadataEdit); } and this: _collectionManager.AddToCollection(newCollection.InternalId, internalIdMovieItemsArray); During the action, I can add another movie to the newly created collection, but not the one I'm currently updating. How I can add a movie to a collection using C#? Link to comment Share on other sites More sharing options...
Luke 37133 Posted February 17, 2023 Share Posted February 17, 2023 HI, where are you calling this from? Link to comment Share on other sites More sharing options...
jelum 17 Posted February 18, 2023 Author Share Posted February 18, 2023 Hi, As part of class implements IRemoteMetadataProvider<Movie, MovieInfo> interface from method Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MovieInfo, CancellationToken) Link to comment Share on other sites More sharing options...
Solution Luke 37133 Posted February 21, 2023 Solution Share Posted February 21, 2023 OK so you need to do two things: Use item.AddCollection from inside the metadata provider Have the provider also implement IHasMetadataFeatures Link to comment Share on other sites More sharing options...
jelum 17 Posted February 22, 2023 Author Share Posted February 22, 2023 Thanks, I'll try Link to comment Share on other sites More sharing options...
jelum 17 Posted February 22, 2023 Author Share Posted February 22, 2023 Didn't work. Provider: public class KpMovieProvider : IRemoteMetadataProvider<Movie, MovieInfo>, IHasMetadataFeatures { public MetadataFeatures[] Features => new[] { MetadataFeatures.Collections, MetadataFeatures.Adult, MetadataFeatures.RequiredSetup }; ... public async Task<MetadataResult<Movie>> GetMetadata(MovieInfo info, CancellationToken cancellationToken) { return await KinopoiskRuServiceFactory.GetService().GetMetadata(info, cancellationToken); } } Inside GetMetadata: public async Task<MetadataResult<Movie>> GetMetadata(MovieInfo info, CancellationToken cancellationToken) { Movie toReturn; ... QueryResult<BaseItem> collections = _libraryManager.QueryItems(new InternalItemsQuery() { IncludeItemTypes = new[] { "collections", "Boxset" }, Name = collectionName }); var isAdded = toReturn.AddCollection((BoxSet)collections.Items[0]); // iAdded is true ... } In another execution after "AddCollection" tried to use the following methods: // this toReturn.UpdateToRepository(ItemUpdateType.MetadataEdit); // or this toReturn.UpdateToRepository(ItemUpdateType.None); Link to comment Share on other sites More sharing options...
jelum 17 Posted March 4, 2023 Author Share Posted March 4, 2023 any ideas? Link to comment Share on other sites More sharing options...
Luke 37133 Posted March 5, 2023 Share Posted March 5, 2023 Did you enable importing collections in your library options? I'd probably also set the min collection size to 1 to make this easier to test. 1 1 Link to comment Share on other sites More sharing options...
jelum 17 Posted March 9, 2023 Author Share Posted March 9, 2023 It worked. thank you! 1 1 Link to comment Share on other sites More sharing options...
mickle026 401 Posted May 23, 2023 Share Posted May 23, 2023 I can add a collection via a local metadata provider by simply putting item.addCollection(stringName) to the Movie item and it builds the collection. This is fine. However, when doing the same thing by private Task<MetadataResult<Movie>> the collection doesn't create or build. So my movies have the line metadataResult.Item.AddCollection(CollectionName); and HasMetadata=true. It adds everything else, so I believe something needs setting to import collections to set it true. @mickle026 metadataResult.Item.AddCollection(newCollection); LogToMyFile(MyLog, DateTime.Now.ToString("dd.MMM.yyy - HH'.'mm'.'ss") + $" metadataResult.Item.SupportsCollections={metadataResult.Item.SupportsCollections}"); and this logs that they are supported 23.May.2023 - 16.00.49 metadataResult.Item.SupportsCollections=True I see that MovieDB when checked as a library provider adds some config to the Library Edit screen, I have included in my Provider a BoxSet Interface with the Same ProviderName, but I have nothing - it doesn't enter this ?? What do I need to do to enable collections to build for my remote provider? For My Provider And for TMDB extra config that I do not have Link to comment Share on other sites More sharing options...
mickle026 401 Posted May 23, 2023 Share Posted May 23, 2023 Thank you Simply these IHasMetadataFeatures public MetadataFeatures[] Features => new[] { MetadataFeatures.Collections, MetadataFeatures.Adult }; without the IHasMetadataFeatures, getting the library options and setting them killed ALL metadataproviders for all libraries from appearing in the Library Edit! var libopt = libraryManager.GetLibraryOptions(metadataResult.Item); libopt.ImportCollections = true; libopt.MinCollectionItems = 2; ie, doing the above without IHasMetadataFeatures completely knocks out all providers for all libraries Link to comment Share on other sites More sharing options...
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