Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- task :default do
- blogs = Blog.all
- blogs.each do |blog|
- scrape = Hpricot(open(blog.url))
- scrape.search('//a[@href$=.mp3]').each do |link|
- url = link.attributes['href'].scan(/http:\/\/(?:www\.)?([^\/]+?)(\/.*?\.mp3)/) do |host, path|
- request = "GET #{path} HTTP/1.0\r\n\r\n"
- socket = TCPSocket.open(host,80)
- socket.print(request)
- # find beginning of response body
- buffer = ""
- while !buffer.match("\r\n\r\n") do
- buffer += socket.read(1)
- end
- @id3_tags = socket.read(100) #read first 100 bytes of body
- Mp3Info.open(@id3_tags) do |mp3Info|
- @artist = mp3Info.tag.artist
- @title = mp3Info.tag.title
- end
- end
- @mp3 = Mp3File.new(:url => link.attributes['href'], :file_name => link.attributes['href'].split('/').last, :band => @artist, :title => @title)
- @mp3.save
- end
- end
- end
Add Comment
Please, Sign In to add comment