Jump to content

Trigger BaseItem image fetching/processing from Plugin


roaku
Go to solution Solved by roaku,

Recommended Posts

roaku

I have a plugin that uses a BaseItem's parent images to generate images for the child BaseItem.

In some cases, Emby has already fully processed a remote image, and I can just use it to generate a child image.

In other cases, Emby only has the url for a remote image, presumably waiting for a client to request the image before putting in the effort to process it.

My question is, what's the best way for my plugin to handle the second case?

Is there a way for me to trigger the parent to process its pending image(s) from the plugin and await the result?

I imagine I can fetch the remote image from the plugin, if necessary, but it would be much cleaner if I could just utilize the parent images directly in all cases.

Thanks

 

        //grab the parent's images of a given type
        private static IEnumerable<ItemImageInfo> GetParentImages(BaseItem item, ImageType imageType) {
            return item.GetParent().GetImages(imageType);
        }

        public DynamicImageResponse GenerateImage(BaseItem item, ImageType type) {
            Nullable<long> libraryIdOption = GetLibraryId(item);
            if (libraryIdOption.HasValue) {

                IEnumerable<ItemImageInfo> parentImages = GetParentImages(item, type);
                //Emby has already downloaded and processed a parent image. Convenient!
                ItemImageInfo parentImageInfo = parentImages.AsQueryable().Where(l => l.IsLocalFile).FirstOrDefault();

                if (parentImageInfo == null) {
                    //Emby hasn't processed a parent image yet, but maybe it has an image url set
                    parentImageInfo = parentImages.AsQueryable().Where(l => l.Path != null).FirstOrDefault();

                    if (parentImageInfo != null) {
                      	//Great, an image url exists for the image
                        //Is there a way to trigger Emby to process the image on the parent in time for my plugin to use the processed image file?
                        logger.Info("Parent image path: "+parentImageInfo.Path);
                    } else {
                        //Emby doesn't have a parent image at all, so complain to the log
                        logger.Info("Still no parent image");
                        throw new ArgumentNullException("Parent Item does not have a compatible Poster");
                    }
                }

              ...

 

Link to comment
Share on other sites

  • Solution
roaku

Hmm, just found ILibraryManager.ConvertImageToLocal(BaseItem, ItemImageInfo, Int32, CancellationToken)

Let's find out what that does...

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