views:

143

answers:

2
+1  Q: 

RubyTorrent Issue

I am trying to create a script to help me move large files accross an internal Windows network, and was hoping that Ruby, in conjunction with BitTorrent would be ideal. However, my code doesnt seem to actually download anything.

I know the RubyTorrent project has been abandoned for a long time, so I was hoping one of my fellow Stackoverflow'ers could help me.

My code (so far is):

require 'rubytorrent'
bt = RubyTorrent::BitTorrent.new('http://www.mininova.org/get/2511754')
puts bt.tracker
puts bt.port
thread = Thread.new do
  while true
    puts bt.percent_completed
    sleep 15
  end
end
bt.on_event(self, :complete) { thread.kill }
thread.join

As you can see, the 'bt.tracker' line is coming up as nil, so it might be a problem passing the .torrent file, but then why does it pass the rest of the file ok?

Any help getting this to work would be greatly appreciated.

A: 

I think it expects a filename. Could it be as simple as needing to require 'open-uri' ?

Eli
+1  A: 

Your code is good, the only problem is that you try to print bt.tracker when you're still not connected to the tracker. If you try to print it after being connected there's no problem

begin
  bt = RubyTorrent::BitTorrent.new('yourtorrent')
rescue IOError
  puts "Can't open the torrent"
end

bt.on_event(self, :tracker_connected) { |s, url| puts "[tracker] connected to tracker #{url}" }

puts 'Tracker : '+bt.tracker.to_s
puts bt.port
thread = Thread.new do
  while true
    puts 'Tracker : '+bt.tracker.to_s
    puts bt.percent_completed
    sleep 10
  end
end
bt.on_event(self, :complete) { thread.kill }
thread.join
Yoann Le Touche
ok, thats sweet, but it still doesnt appear to be actually downloading the torrent, moreover, where is it being downloaded to?
Ash
Actually, thats not true it IS downloading now :) but where is it storing the data?
Ash
lol nm - i just found it :) in the directory that the rb file is run. thanks for your help.
Ash