Is it possible to get a live stream programmatically?

The ads are not part of the actual stream, just overlayed in the same player.

Speaking for myself, the reason I stress the consequences is that I don’t want to be accessory in breaking any rules set up by your school. Most importantly, your solution is most likely in violation of Twitch ToS.