A giant buyout firm in Silicon Valley is looking to acquire major stakes in the New York Knicks and New York Rangers, The Post has learned.

Silver Lake Partners — a firm that’s better known for its investments in Tesla and Alibaba — is angling to buy a big stake in both teams before they’re spun off into a publicly traded company, sources close to the situation said.

Silver Lake owns close to 10 percent in the teams’ owner, Madison Square Garden — making it the largest outside investor in the entertainment conglomerate controlled by billionaire James Dolan.

Now, Silver Lake wants more, but only when it comes to the sports teams — not MSG’s other assets, like Radio City Music Hall and the Tao nightclub empire, these sources said.

Dolan will continue to control the Knicks and Rangers for the foreseeable future, even as MSG spins off about two-thirds of the value of the teams to current MSG shareholders. Nevertheless, MSG has said it is open to selling some of the one-third stake it plans to retain so it can invest the proceeds in its remaining businesses, including the futuristic, orb-like entertainment globes Dolan is building in Las Vegas and London.

Silver Lake, which is also a major investor in the Fanatics sports-licensing business, has approached MSG with multiple plans to take a bigger stake of the sports teams, said one source. One plan would result in a private sale to Silver Lake at the time of the spinout, this person added.

Watchers say Silver Lake could be seeking a front seat to the Knicks and Rangers if it anticipates a potential sale of the teams by Dolan, who is notoriously unpopular with fans. Dolan, whose father founded Cablevision, has repeatedly denied plans to sell the teams but has also complained about owning them, including in a November 2017 video he made for news site Deadspin.

“You know I own a basketball team. For most people that would be a dream,” Dolan sang in the video with lyrics he made up. “For a trust fund kid, it’s a living hell. Always some a—hole telling me to sell.”

Analysts and sources say the teams could fetch a 20 premium in any sale, which they attribute in part to the “Dolan Discount,” or perceived mismanagement by Dolan.

The Knicks, valued at $4 billion by Forbes, and the Rangers, valued at $1.55 billion, have the distinction of being the priciest sports franchise in their respective leagues — despite being losing teams with disgruntled fans.

The Knicks, Rangers and MSG’s smaller sports assets, including the Westchester Knicks and e-sports franchise Counter Logic Gaming, are expected to carry a $4.7 billion price tag in the spin, analyst LightShed Partners said in an Oct. 28 report.

Silver Lake’s grab for a bigger stake at what is expected to be a premium price would likely boost the value of MSG’s sports teams the day they start trading, sources said. The planned spinout, announced in June 2018, was initially expected to take place this year but is now slated for early 2020, sources said.

MSG and Silver Lake both declined to comment.

MSG reiterated its spinoff plans in a public filing last week, saying it would separate MSG into two separately traded public companies without giving a timetable.

Silver Lake retired co-founder Glenn Hutchins, is a part-owner of the Boston Celtics. Silver Lake also has a big stake in Endeavor, which owns half of the Ultimate Fighting Championship.