Generally, it pulls down the HTML page for a site, parses it, and uses the results to pull down the video. The extractor for youtube itself is the most complex one, but there are plenty of others.
Last time I checked it had extractors for something like 700 different sites, along with a generic one that works on a bunch of sites. In general, you can just point it at any video page you see online and have a fairly high chance of it doing the right thing.