A teenage paedophile was caught trying to rape a six-year-old girl after her suspicious big sister set up an iPad to record in the bedroom.

The girl, 12, was suspicious of the 17-year-old and his obsession with her six-year-old sister and set up her iPad in her sister's bedroom before setting it to record.

The High Court in Glasgow heard the footage captured on the iPad showed the 17-year-old, who cannot be named for legal reasons, attempting to rape the primary school pupil.

Prosecutor Paul Brown said: "During the incident the accused took out his mobile phone and appeared to be recording what he was doing.

"The 12-year-old girl retrieved the iPad a short time later. She reviewed the footage and showed her mother who in turn phoned the police.

"At one point in the footage the child is seen to flinch as if she was in pain."

In court, the teenage boy from Edinburgh admitted attempting to rape the six-year-old on April 9, 2016, at her home in the city.

He also pleaded guilty to sexually abusing her and having a cache of indecent photographs of children, some of them babies, being sexually abused.

The court heard the 17-year-old had 153 indecent photographs of children on his phone and a further 743 images of children were found on another phone belonging to him.

Mr Brown said: "The child abuse images located on the second phone generally show very young children indeed, some are clearly babies, and show images of mostly girls being sexually abused predominantly by adult males.

"Police also searched the accused's home and found a memory card with three videos of the six-year-old being sexually abused by the accused."

Solicitor advocate Iain Paterson said: "My client is someone who needs to get help while in custody to prevent his re-offending and will take all the courses he can."

Judge Lord Burns deferred sentence on the 17-year-old until next month for sentence at the High Court in Edinburgh and placed him on the sex offenders register.