Jump to content

How to re-index a new RemoteImage of an item


Sludge Vohaul
Go to solution Solved by Luke,

Recommended Posts

Sludge Vohaul

Hi,

 

I want to programatically add a new backdrop image to an item and have it shown in the UI.

I have a problem to identify the image I've added, in order to re-index it to the first position.

 

That's what I do:

I add the image by providing it's type (e.g. backdrop) and it's URL:

var args = new Dictionary<string, string>
{
  {"Type", imageType.ToString()},
  {"ImageUrl", imageUrl.AbsoluteUri}
};

var url = client.GetApiUrl($"Items/{movieId}/RemoteImages/Download");
await client.PostAsync<EmptyRequestResult>(url, args)
There is no return value available. As an item can have multiple backdrop images, all I know is, that it has been appended to an internal list of backdrop images.

 

So in order to show the image in the UI, I have to move it to the first position of the backdrop list (index=0).

Therefore I need to get it's current index in the list:

var url = client.GetApiUrl($"Items/{movieId}/Images");
var imageInfos = await client.GetAsync<List<ImageInfo>>(url);
var lastBackdropIndex = imageInfos.Count(x => x.ImageType == ImageType.Backdrop) - 1;
After that, I have to move the image to index=0:

// Do not reindex if it's the only image (or no image at all).
if (lastBackdropIndex <= 0) return;

var args = new Dictionary<string, string>
{
  {"NewIndex", "0"}
};

var url = client.GetApiUrl($"Items/{movieId}/Images/{imageType}/{lastBackdropIndex}/Index");
await client.PostAsync<EmptyRequestResult>(url, args);
This seems to work, but, is based on the assumption, that the last image in the list is the one I have added. What if several users added an image in a small time frame? If I took the last one in the list it might not be "my" image.

 

How do I identify the image I have added, so that I don't have to assume "my" image is the last in the list?

Link to comment
Share on other sites

  • Solution

You can't currently. It's something we'd have to add to the api. For now the best you can do is just make that assumption.

  • Like 1
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...