Ruby interface to libtransmission

Posted on September 15, 2006

One of my projects required a bittorrent integration. I've tried two available in Ruby options:

  1. rubytorrent is a pure Ruby bittorrent client.
  2. libtorrent-ruby is an inteface for libtorrent library.

Unfortunately, the first was not that stable and the latter I wasn't able to build at all. I am pretty sure that I was doing something wrong, but the time was pretty tight and I had to come up with a stable solution.

I remember there is a pretty decent open source application called Transmission. It didn't take me more than several hours to create a binding for Ruby. So here we go:

Transmission is a simple native bittorrent client for Ruby based on libtransmission library.

Installation

The only prerequisite for this library is that your Ruby must be compiled with pthread support enabled:

    $ ./configure --enable-pthread
    $ make
    $ sudo make install

Having done that, download gem and you should be able to install this gem without problems:

    $ sudo gem install transmission.gem

Synopsis

Assuming that you have progressbar gem installed:

    $ sudo gem install progressbar

You can use this script to download with a torrent file:

    require "rubygems"
    require "transmission"
    require "progressbar"

    # create a new session
    session = Transmission.new

    # open a torrent file
    torrent = session.open(ARGV[0])

    # set destination directory
    torrent.download_to File.expand_path('~/tmp')

    # starts a new native thread in background
    torrent.start

    progress = ProgressBar.new(" Downloading", 1.0)
    trap("INT") do
      torrent.stop
      progress.finish
      exit
    end

    # display progress bar
    until torrent.just_finished?
      progress.set(torrent.stat.progress)
      sleep 0.5
    end
    progress.finish

Known issues

  1. I have tested it only on Linux and Mac OSX. It definitely is not going to work on Windows.
  2. API is quite limited. For example, you can't create a new torrent file with it.

Enjoy.

Comments
  1. Christian von KleistJanuary 26, 2008 @ 12:44 PM

    Thanks for making this! I've just given it a try and it's working beautifully. It's going to be perfect for the project I have in mind.

    I, too, tried libtorrent-ruby and rubytorrent without success. I think their maintainers have lost interest since updates have been few and infrequent. I'm much more attracted to the idea of piggybacking on a torrent library from a very successful project like Transmission.

    Have you considered making a Google Code or RubyForge project for the transmission gem? If you do, please let me know! I'd love to contribute.

    Thanks for the awesome software!

    -Christian

  2. Matt SchickFebruary 10, 2008 @ 11:14 PM

    Thanks indeed! I just wasted an hour and a half on libtorrent-ruby. However everything is peachy with your gem. I was a little worried upon seeing skimpy rdoc but then I found the r_transmission.c file. Kudos to you good sir for such a wonderfully commented file. I'm working on a rails app that is a bittorrent client but has additional features to make it easy for a person to keep seeding their torrents and have the media all nice and organized for an xbox running xbmc to scan and stream. Thanks again for the great work!

Post a comment
Comment





You may use Markdown in your comments, so please give your code snippets a four-space indent.