ev0 发表于 2013-1-15 03:15:01

Downloading YouTube Videos with a Groovy one-liner, kind of

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 =~ (/(?<=v=).*$/)).collect{it}   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}}”).openStream().eachByte{it -> os.write(it)}}
页: [1]
查看完整版本: Downloading YouTube Videos with a Groovy one-liner, kind of