Jump to content

Collection Set Primary Image c#


Recommended Posts

bakes82
Posted


I seem to be having some issue when creating a collection and setting the primary image, I seem to be able to set it, and sometime it takes and othertimes it says it takes but then it show the default emby one with 4 image posters.
Is there some  kind of delay I need to wait for after creation of the collection before setting the image?  Also the createcollection method doesnt take an image or any other options so I assume I have to use the library manager then pull the created collection
 

Logs show it running the dynamicimageprovider after me setting it.

2025-07-27 14:16:02.113 Debug SqliteItemRepository: GetitemById BoxSet 1591013 Netflix Top Shows
2025-07-27 14:16:02.117 Info MDBListCollectionsCreateCollectionsTask: Found Items Ids: 394976, 1585590, 1585782, 1589051
2025-07-27 14:16:02.121 Debug SqliteItemRepository: GetitemById BoxSet 1591013 Netflix Top Shows
2025-07-27 14:16:02.125 Debug SqliteItemRepository: GetitemById BoxSet 1591013 Netflix Top Shows
2025-07-27 14:16:02.125 Debug SqliteItemRepository: GetitemById BoxSet 1591013 Netflix Top Shows
2025-07-27 14:16:02.125 Debug App: Saving nfo metadata for Netflix Top Shows to /config/metadata/collections/Netflix Top Shows/collection.nfo.
2025-07-27 14:16:02.127 Info MDBListCollectionsCreateCollectionsTask: Applied custom image to collection Netflix Top Shows: /config/plugins/configurations/netflix_top_shows.png
2025-07-27 14:16:02.178 Debug App: Running CollectionNfoProvider for Netflix Top Shows
2025-07-27 14:16:02.180 Debug App: PlaylistDynamicImageProvider reports change to 1591013 - 
2025-07-27 14:16:02.180 Debug App: Running PlaylistDynamicImageProvider for Netflix Top Shows   /////// Why is it doing this?????
2025-07-27 14:16:02.180 Debug App: Setting image url into item 1591013
2025-07-27 14:16:02.182 Debug App: Saving nfo metadata for Netflix Top Shows to /config/metadata/collections/Netflix Top Shows/collection.nfo.

 

var collectionToModify = _libraryManager.GetItemById(collection.CollectionId);
collectionToModify.Overview = $"Modified: {DateTime.UtcNow} UTC {Environment.NewLine}<br/> {collection.Url}";

_libraryManager.UpdateItem(collectionToModify, collectionToModify.Parent, ItemUpdateType.MetadataEdit);  //Testing not sure if needed


if (!string.IsNullOrEmpty(collection.CollectionImagePath))
{
    try
    {
        if (File.Exists(collection.CollectionImagePath))
        {
            collectionToModify.SetImage(new ItemImageInfo()
                                        {
                                            DateModified = DateTimeOffset.UtcNow,
                                            Height = 0,
                                            Width = 0,
                                            Orientation = ImageOrientation.TopLeft,
                                            Path = collection.CollectionImagePath,
                                            Type = ImageType.Primary
                                        }, 0);
            _libraryManager.UpdateItem(collectionToModify, collectionToModify.Parent, ItemUpdateType.ImageUpdate); //Testing
            
            _logger.Info($"Applied custom image to collection {collection.Name}: {collection.CollectionImagePath}");
        }
        else
        {
            _logger.Warn($"Custom image file not found for collection {collection.Name}: {collection.CollectionImagePath}");
        }
    }
    catch (Exception ex)
    {
        _logger.ErrorException($"Error applying custom image to collection {collection.Name}", ex);
    }
}

_libraryManager.UpdateItem(collectionToModify, collectionToModify.Parent, ItemUpdateType.MetadataEdit); //Ideally just want this update, not the other two if not needed
Posted
Quote

2025-07-27 14:16:02.180 Debug App: Running PlaylistDynamicImageProvider for Netflix Top Shows /////// Why is it doing this?????

Anytime you add items to a collection, or create one, it will kick off a metadata refresh in the background in order to update the image. If you doing either of these two things, then you might want to use a delay to set the image to ensure that it happens after. Please note it will be hard to guarantee that you're running after because it goes into a background queue, and if that queue is long then it won't happen immediately. But right now that's all you can do.

To stop images from being created altogether you can change the library options, or lock the metadata of the item altogether.

bakes82
Posted

What library option to I change for the "collection", or do you mean I have to change it for all the items in the library?

bakes82
Posted
22 hours ago, Luke said:

To stop images from being created altogether you can change the library options

Is there a library option you set when creating a collection or modifying the item.

Posted

A library option to accomplish what?

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...