Scott Lunn was handed an extended sentence which will see him spend two years in prison followed by two years under strict supervision in the community.
He was warned that if he breaches his licence conditions following his release he will be recalled to prison to serve the remainder of the four year sentence.
Police caught the paedophile with 4,298 indecent photographs of children when police searched his West Lothian home, Livingston Sheriff Court was told.
Stuart Peebles, defending, said Lunn had numerous health problems including cerebral palsy, diabetes and fits.
He admitted that the accused, who has previously been jailed for similar offences, had given “concerning explanations” for his behaviour.
He said social work supervision had helped to control Lunn's offending in the past but he struggled to overcome his urges once external supervision was removed.
He added: “He continues to pose a risk of sexual harm to children but a period of supervision would reduce that risk.”
The court was told that the majority of the 4,000 plus images on two hard drives found hidden behind Lunn's bedroom sofa had been deleted, but 333 explicit videos and 31 indecent images were still accessible.
Lunn, who has served the equivalent of a 20 months prison sentence on remand in Glasgow’s Barlinnie Prison since his arrest pleaded guilty on indictment to possessing indecent photographs of children at his home in Dixon Road, Whitburn. He was on bail for other charges at the time of the offence.
His not guilty pleas to three further allegations of sexually assaulting two pre-teenage schoolgirls by kissing and groping them and using lewd and indecent behaviour towards one of them by touching her private parts under her clothing – were accepted by the Crown.
Depute fiscal Callum Thomson said police had received intelligence that the IP address for Lunn’s home in Dixon Road, Whitburn, was being used to access indecent images of children.
Officers got a search warrant and raided the property at 7.55am on 15 January. Due to the accused having learning difficulties, an appropriate adult was in attendance to make sure Lunn fully understood the process.
Mr Thomson said the hard drives were forensically examined by Police Scotland’s cybercrime unit. One hard drive was found to contain 31 accessible indecent images, including eight category A, seven category B and 16 category C.
A further 3,811 “inaccessible” images, which had been deleted after being viewed, were also recovered. These included 1,640 category A, 1,206 category B and 965 category C images.
In addition 333 accessible videos were recovered from the devices, 245 of them category A, which shows children being raped or sexually penetrated, 53 category B showing less serious sexual abuse and 35 category C showing youngsters posing naked. A further 123 indecent videos which were no longer accessible were also recovered.
Mr Thomson said there was evidence that the accused had used ‘peer-to-peer’ applications to access files recovered from his electronic devices and that he had used specific search terms to find indecent images of children to download.
Passing sentence, Sheriff Douglas Kinloch told Lunn: “This is the third time you've been convicted of being in possession of indecent images of children and it appears these photographs were downloaded less than two weeks after you were out on bail for similar charges of a sexual nature.
“You appear to have gone to considerable lengths to hide your activity so it’s clear you were entirely aware of what you were doing.
“In my view a prison sentence must be imposed in order to deter you from this kind of activity. Given that you’re assessed as posing a risk to the public I consider that a period of supervision after your release is appropriate.”
He backdated the sentence to 18 January when Lunn was first remanded in custody and told the accused his name would remain on the sex offenders’ register indefinitely.