How to generate unique materials

Our app is referencing the Materials that are set to the different objects.

Example: A teapod object has a Bitmap slot with a texture (Material #25). Another teapod object has the same Bitmap slot with the same texture (Also Material #25).

The problem here is that the app does not understand which of the two teapods we are referring to when clicking one of them (as they have the same material). We can add another material to the scene (Material #26) and connect the Bitmap node to this one, which will make them unique. However, there are houndreds of different objects like these, and adding new materials manually is very time consuming.

Is there any script or approach that generates a new material to an object while keeping its connected slots (Bitmap in our case)?