Jump to content

Add movie to collection with C#


jelum
Go to solution Solved by Luke,

Recommended Posts

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

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

  • Solution

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

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

  • 2 weeks later...

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.

  • Agree 1
  • Thanks 1
Link to comment
Share on other sites

  • 2 months later...
mickle026

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

Screenshot2023-05-23at11-51-04MIKE-PC.png.9b0fc7c750d074e7bf884b347587c42a.png

And for TMDB extra config that I do not have

Screenshot2023-05-23at15-40-52Emby.png.d0c4f1981aa74a58a2655b5dacb3e959.png

 

 

 

Link to comment
Share on other sites

mickle026

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...