|
|
Inspired by Downloading YouTube videos with a Perl one-liner, I’ve put together a piece of code to do the same thing with Groovy. Not as succinct as Perl. But figure out how much noise there will be in plain Java.
<div style=""><div style=""> 1: HttpURLConnection.setFollowRedirects(false) 2: def vid = (args[0] =~ (/(?<=v=).*$/)).collect{it}[0] 3: def uri = ((HttpURLConnection)new URL(“http://www.youtube.com/v/$vid”).openConnection()).getHeaderField(‘Location’) 4: HttpURLConnection.setFollowRedirects(true) 5: new File(“${vid}.flv”).withOutputStream{os -> new URL(“http://www.youtube.com/get_video?video_id=$vid&t=${(uri =~ (/(?<=.*&t=).*$/)).collect{it}[0]}”).openStream().eachByte{it -> os.write(it)}} |
|