Sludge Vohaul 22 Posted September 7, 2017 Share Posted September 7, 2017 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 More sharing options...
Solution Luke 38342 Posted September 7, 2017 Solution Share Posted September 7, 2017 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. 1 Link to comment Share on other sites More sharing options...
Sludge Vohaul 22 Posted September 7, 2017 Author Share Posted September 7, 2017 Ok, thanks for the info. Link to comment Share on other sites More sharing options...
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