This is the first step towards being able to just import youtube_dl and start using it. Apart from removing global state, this would fix problems like #1805.