New York’s subway system drives many of us crazy, but for one man, it’s a lifelong love affair he’s willing to go to prison for — over and over and over.

Rikers Island convict Darius McCollum, known as the “train bandit,” has been arrested 32 times for impersonating transit employees, stealing trains and buses, and driving their routes — complete with making safety announcements and passenger stops.

McCollum, who has been diagnosed with Asperger’s syndrome, got his start as a lonely, subway-fascinated kid in Queens, when MTA workers at the 179th Street F train station took him under their wing.

“My mother used to come down there looking for me,” McCollum tells The Post via phone from prison at Rikers Island. “She used to tell them, ‘I don’t want my son hanging out with you! If you see him, send him home!’ Then they would see me and tell me, ‘I just saw your mother, go hide someplace!’ They protected me. They would say, ‘Don’t worry about your mother, she’ll be fine.’”

McCollum, whose autism fuels his obsession with transit, is awaiting sentencing later this month for taking a Greyhound bus from Port Authority for a 24-hour ride until he was arrested in Brooklyn; it’s a crime for which he faces a sentence of up to 15 years to life if he does not take a plea deal. The 51-year-old has already spent 18 years of his life, cumulatively, behind bars for his deftly executed capers, in which he’s worn purloined MTA uniforms and falsified IDs to drive trains and buses as if he was a paid employee.

He is the subject of a new documentary, “Off the Rails,” which chronicles his decades of infamy as one of the city’s most beloved criminals. Friday’s 7:30 screening at the Metrograph will be followed by a Q&A with the director: Adam Irving, making his feature debut, says he was drawn to McCollum’s story. McCollum’s condition, which puts him on the high-functioning end of the autism spectrum, is characterized by obsession with specific topics and difficulty with normal socialization and communication.

“The Asperger’s added this childlike innocence to his crimes,” says the 34-year-old Irving, who adds that part of the reason McCollum got away with so much was because his crimes were so head-scratching in nature. “Why would someone pretend to drive a bus? You’ve got to make the stops, make all the announcements. It’s not, like, a pleasurable thing. Who would do that for free?”

He exchanged more than 100 letters with McCollum before going to meet him in March 2013 at Rikers. “I didn’t know what to expect,” says Irving, a Toronto native who now lives in LA. “Because of the Asperger’s, I thought maybe he’d talk oddly. But he was a shockingly normal, nice guy.”

Irving had to delay filming for six months so McCollum could finish his sentence, which at the time was for taking an empty Trailways bus from the Hoboken terminal in 2010. “He took it on a joyride,” says Irving, “and stopped at the Hotel Pennsylvania near Penn Station to use the bathroom. He met some flight attendants in the lobby, and told them he was driving a free shuttle to JFK — and then refused a tip!” He was nabbed on his return trip to Hoboken.

By that point, getting arrested was second nature to McCollum, whose first clash with the law was at 15 years old. As Irving’s film details, he was riding along in the conductor’s booth of an E train when the conductor asked him if he wanted to take over the route — then handed him the controls and left, confident the teen could handle the job. McCollum drove from 34th Street to the World Trade Center, where transit cops stopped him and asked where the conductor was. “I am the conductor,” he told them.

“It just seemed natural to me,” recalls McCollum of that day. “I felt like I was providing a service. I knew how to do everything. I’d been operating trains since two-and-a-half years before that.”

“Off the Rails” explores the frustrating cycle in which McCollum is trapped: Despite his requests for therapy for his condition, none is available in jail. After he’s released from prison, he’s forbidden from leaving New York due to the terms of his parole. Unable to get a job because of his record, and unable to live with his mother in North Carolina, he ends up homeless and depressed — a condition only relieved by stealing another train or bus for a few hours of bliss. Eventually the cops get him, and the cycle begins again.

At one point, McCollum found temporary relief from his train-snatching urges by volunteering at Brooklyn’s Transit Museum, where his encyclopedic knowledge was appreciated by the staffers. But higher-ups got wind of it, and he was asked to leave. “The transit police told me it would be good for me there,” he says. “But the bosses said no.”

Meanwhile, his requests for counseling fall on deaf ears in prison. “I would definitely like to go to therapy,” McCollum says. “I would like to get all the therapy I can! Jail doesn’t give you that.” He also doesn’t have many friends behind bars. “I pretty much keep to myself,” he says. “I try not to be involved in any of the chaos that goes on.”

But Irving says it’s more than that: McCollum is often actively kept apart from other prisoners because of the fear he’ll be viewed as a snitch. “He’s widely known for having cooperated with the FBI to teach them what he knows: Here are the gaps in your transit network, this fence should be higher, this fence should have a camera,” says Irving. “He’ll tell them, ‘If you follow these measures, I won’t be able to take your vehicles anymore, and by extension, terrorists won’t be able to take them.’”

In this, Irving says, McCollum is like Frank Abagnale Jr., the pilot impostor and master check forger played by Leonardo DiCaprio in the 2002 film “Catch Me If You Can.” “He got caught, and now he’s showing the government how he does what he does. But that information has circulated in jail, and he’s perceived as a rat who cooperated, and it’s assumed he gave up names.”

That assumption couldn’t be further from the truth, McCollum says. MTA employees were instrumental in helping him get away with his train and bus sprees, sometimes asking him if he wanted to take over their shifts for the day. But he never revealed their names. “I don’t want people to get hurt or fired,” he says. “People have families.”

His dedication to the MTA workers was so strong, he once attended a strike-planning meeting, voicing his support for employees’ rights. “They asked me to be a union rep,” he says proudly, though he had to turn down the gig for obvious reasons.

In all his years of joyriding, McCollum has never harmed a passenger, though in one incident, he forgot to put a parking brake on a bus, causing it to roll into a car; in another, he is thought to have remotely tripped the emergency brake on a train, which he then flew into action to rescue (though McCollum has never admitted to this, contrary to his usual policy of owning up to his crimes).

The train bandit sees himself as a protector and defender of New York transit — a subway superhero of sorts. He’s already been the subject of a 2003 play called “Boy Steals Train,” followed by Irving’s documentary. And his life story is on track to become Hollywood fare, too: Julia Roberts is reportedly attached to play his lawyer in a film called “Train Man.” No one’s been cast as McCollum, though if he could choose someone, the bandit would like to request Forest Whitaker.

But MTA’s board members have made it clear they don’t share McCollum’s excitement about the project, vowing to sue to stop him from receiving any sort of compensation for his life story under the “Son of Sam” law, which prevents criminals from making profits from their crimes.

Still, McCollum says his main priority isn’t profit but public safety. “I just hope people ride the MTA in the safest manner possible,” he says when asked what he’d most want to tell the people of New York. “The main thing I want people to understand is that even though I’m here, I have never given up my love for the MTA.”

As for his favorite train line? That’s easy: “The D. For Darius.”