This may help:
http
/joeywhelan.blogspot.com/2015/04/taming-youtube.html
This is for networks though, and assumes your router runs Cisco IOS.
If this is for an individual machine, something like this may work:
http
/lartc.org/howto/lartc.ratelimit.single.html
The problem is that this is for traffic shaping, which applies to packets *leaving* the interface. For controlling the packets *entering* the interface, you need policing:
http
/blog.stevedoria.net/20050906/ingress-policing-with-linux-and-tc
There may be a way to use rule sets like these to drop packets selectively if bandwidth usage has gotten too high. It's inelegant, but if youtube sees that packets are being dropped, it *should* drop the quality of the video being watched automatically. It may also just stop playing the video if it doesn't have a low enough resolution available.
The problem is that the *rate* of ingress is not determined at your end, but on youtube's side. You will be relying on youtube behaving the way you want it to.
If at all possible, you should do this traffic policing at the router. Cisco IOS likely has a means of doing this on a per machine basis. Other routers should have analogous features to IOS if they are expensive, business class routers. If you are stuck just doing this on your own machine though, you can probably get away with using rule sets for tc.