jelum 29 Posted February 17, 2023 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#?
jelum 29 Posted February 18, 2023 Author Posted February 18, 2023 Hi, As part of class implements IRemoteMetadataProvider<Movie, MovieInfo> interface from method Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MovieInfo, CancellationToken)
Solution Luke 38535 Posted February 21, 2023 Solution 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
jelum 29 Posted February 22, 2023 Author 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);
Luke 38535 Posted March 5, 2023 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
mickle026 480 Posted May 23, 2023 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
mickle026 480 Posted May 23, 2023 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
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