Wait just sec. Why are you using this script instead of using youtube-dl? youtube-dl supports proxy too.
--proxy URL Use the specified HTTP/HTTPS/SOCKS proxy. To enable experimental SOCKS proxy, specify a proper scheme. For example socks5://127.0.0.1:1080/. Pass in an empty string (--proxy "") for direct connection