damien.h

Downloading YouTube Videos with a Groovy one-liner, and convert it to mpeg4

Today I used LiveHTTPHeaders to take a closer look at how the youtube video streams are directed to the browser. And I found that my previous attempt actually has some redundency in it. To get the flv video stream, simply request the URL:

http://cache.googlevideo.com/get_video?video_id=${vid}

where vid is simply the v string in the original URL. e.g. http://www.youtube.com/watch?v=5C0I7Ef4gQI

So the simplified version is one line of code even shorter now.

def vid = (args[0] =~ (/(? new URL("http://cache.googlevideo.com/get_video?video_id=${vid}").openStream().eachByte{it -> os.write(it)}}

And now here’s a bonus. Grab ffmpeg and put the ffmpeg executable to your system path. Then add the following line to the Groovy script above, and the downloaded flv file will be converted to an mpeg4 format mpg file immediately. You can also play with many ffmpeg parameters to fine tune your convertion.

For Windows

Runtime.getRuntime().exec(['cmd', '/c', "ffmpeg -i ${vid}.flv ${vid}.mpg"] as String)

For Linux

Runtime.getRuntime().exec(['sh', '-c', "ffmpeg -i ${vid}.flv ${vid}.mpg"] as String)

准备搬新服务器了

2个礼拜没有更新了。

现在blog的服务器空间是和朋友一起办的另外一个网站autoers.org合用的,一年前在上海服务器合租网买的。说起来autoers.org已经换了好几个国内服务器空间了,也受够了国内服务器商的低劣质量和服务。最惨的一次,由于共享服务器上有其他未知的“非法网站”,流量还很大,服务器资源被大量占用导致我们的网站速度很慢而且不稳定。最后服务器整个被公安端走了,来不及备份的数据全部丢失。

所以这次决定搬到国外服务器了。最近调查了一下国外web hosting服务商的情况,在web hosting unleashed上对比了几家最热门的服务商,最后选定了hostgator,因为是100%好评的。月付每月9.95美元的baby方案,100G空间每月1T流量,在用了coupon以后,第一个月只要1美分。国内哪里找的到这么好的条件!其实用国外服务器的最大担心一个是IP被和谐,一个是速度比国内慢。但是目前试用下来这两点都不是问题。

不过买了hostgator后才看到讨论说,他们现在对中国用户审查的很严,这点在注册的时候已经体会到了;另外服务质量似乎也有下降趋势。lunarpages似乎是个不错的备选。对中国用户支持十分全面,访问速度也不比hostgator慢,Basic hosting方案350G空间每月3.5T流量,最低3月付每月9.95美元,还有coupon可以打72折。另外,media temple是个比较小众化的选择。很多名站酷站都是放在mt,比如我的rss必读techcrunch,所以服务质量应该是不错的。不过讲性价比的话肯定就不那么高了。

最后,希望搬到国外服务器以后IP坚持住不要被和谐掉吧。

Browse Happy logo

My tweets

 

2007 年八月
« 七   九 »
 12345
6789101112
13141516171819
20212223242526
2728293031  

分类目录

Articles

Fancy Stats