DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Tamilbeat.com Mp3 Crawler

03.14.2007
| 13346 views |
  • submit to reddit
        create a file called links.dat and put the songs link from tamilbeat.com

#!/usr/bin/env ruby
require 'net/http'
require 'socket'
                                                                                                                            
Thread.abort_on_exception = true
threads = []
                                                                                                                            
line = File.open("links.dat")
IO.foreach("links.dat") {|line|
  if %r{http://([^/]+)/([^/]+/+.+)}i =~ line
    domain,path = $1, $2
  end
  web = TCPSocket.new(domain,"http")
  web.print "GET /"+path+" HTTP/1.0\n\n"
  web.print "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070220 Firefox/2.0.0.2"
  answer = web.gets(nil)
  web.close
                                                                                                                            
  # for mp3
  arr = answer.scan(/http:\/\/www.+mp3/)
                                                                                                                            
  arr.each do |e|
    threads << Thread.new(e){|mp3|
      if %r{http://([^/]+)/([^/]+/+.+)/(.+mp3)}i =~ mp3
        website,song,name = $1, $2, $3
      end
      a=Net::HTTP.new(website,80)
      song_get = "/"+song+"/"+name
      puts "Fetching #{website}#{song_get}"
      resp, data = a.get(song_get,nil)
      puts "Got #{website}#{song_get}: #{resp.message}"
      open(name,'w'){|f| f.write(data)}
    }
  end
}
threads.each {|aThread| aThread.join}