rb2k/viddl-rb — pull request #11 by kl (2011-11-11 17:21:12+00:00)
Title: Fixed an URI.parse bug and improved Windows support

There was a bug in the youtube plugin where the download url that was returned looked something like this:

http://o-o.preferred.arn06s03.v5.lscache3.c.youtube.com/videoplayback?sparams=id,expire,ip,ipbits,itag,source,ratebypass,cp&fexp=907611,905241,906424&itag=37&ip=79.0.0.0&signature=9E058AEA1ACDA5B5E0075543BE55045ADA92A83C.22F3896EFB43909B0A2FF29D750D2AC9D4421730&sver=3&ratebypass=yes&source=youtube&expire=1321041600&key=yt1&ipbits=8&cp=U0hRRlBPT19FSkNOMV9ISVNHOnpqTVYtSnRIN2pF&id=a34c74229a7db4f5&quality=hd1080&fallback_host=tc.v5.cache3.c.youtube.com&type=video/mp4; codecs="avc1.64001F, mp4a.40.2"&itag=37

Only trying to parse this string with URI.parse (when the client is not using wget or curl) gives an error because of this part: "; codecs="avc1.64001F, mp4a.40.2"&itag=37"

This information is not used after the itag value is parsed, so I removed it from the returned download_url string. Now it can be parsed by URI.parse and downloading a youtube video using open-uri works.

The second thing I did was to improve on the Windows support. The 'which' command that is used to check whether the user has wget and curl is not a Windows command and running that code on a standard Windows install (i.e. without Cygwin) will give you an error. I extracted that code to a helper method that works in Windows too.