六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 47|回复: 0

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

[复制链接]

升级  68%

8

主题

8

主题

8

主题

童生

Rank: 1

积分
34
 楼主| 发表于 2013-1-15 03:15:01 | 显示全部楼层 |阅读模式
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)}}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表