Rorcraft Blog

Download youtube videos with ruby

As you might know, we’ve released Ankoder.net for while now. It lets anyone to download videos into their iPods and various other formats. Scraping the flv url from Youtube HTML isnt exactly easy.

This is how we do it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  def parse_youtube(url)
     youtube = "http://www.youtube.com/"
     # url =~ /(?:http\:\/\/.*youtube.com\/(?:watch\?v=|v\/))?(.*)$/
     url =~ /watch\?v=(.*)/ 
     video_id = $1
     video_id = video_id.split("&")[0]
     flv_url = nil
     open("#{youtube}watch\?v=#{video_id}") do |f|
       f.each_line do |line|
         if line =~ /watch_fullscreen\?(.*?)video_id=([\w-]+)&(.*?)&t=([\w-]+)&/
           # p line
           flv_url = "#{youtube}get_video?video_id=#{$2}&t=#{$4};auto"
           break
         end
       end
     end
     flv_url
  end

USER_AGENT = %{Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.11) 
Gecko/20071231 Firefox/2.0.0.11 Flock/1.0.5}

IO.popen("curl -o \"#{file_name}\" -L -A \"#{USER_AGENT}\" \"#{parse_youtube(url)}\"  2>&1")

Ankoder Architecture presentation

In March, we had a ruby on rails user group meetup in Hangzhou, China. It was exciting to meet more rails developers in China and shares some experience on our projects. Hangzhou is famous for it’s West Lake, it is just 1.5 hrs south of Shanghai. It is turning into the Silicon Valley of China, because several large internet companies are based in Hangzhou, such as Alibaba. They are also experimenting with Rails, because of its amazing productivity gains.

<img src=“http://devblog.rorcraft.com/assets/2008/3/28/IMG_1903.JPG”/ width="400">

We did a presentation on our architecture and how we host a fault tolerant system on Amazon’s EC2. We will already need to change this a little since Amazon has just released the long been waited feature Static IP. Now you don’t need to rely on DNS to failover to your new server, you can at least start a new instance and point your IP to the new host.

Contact

We love to hear about your web projects.
Email:
Sydney: +61 421 591 943
Hong Kong:+852 6901 2682

Categories