https://github.com/mikhailvs/torrent-ruby
A Ruby library for dealing with .torrent files and trackers.
https://github.com/mikhailvs/torrent-ruby
Last synced: about 1 year ago
JSON representation
A Ruby library for dealing with .torrent files and trackers.
- Host: GitHub
- URL: https://github.com/mikhailvs/torrent-ruby
- Owner: mikhailvs
- License: gpl-3.0
- Created: 2011-07-14T22:24:29.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2014-02-16T23:53:54.000Z (over 12 years ago)
- Last Synced: 2023-03-27T15:52:06.461Z (over 3 years ago)
- Language: Ruby
- Homepage:
- Size: 2.7 MB
- Stars: 46
- Watchers: 3
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README
- License: LICENSE
Awesome Lists containing this project
README
A Ruby library for dealing with .torrent files and trackers.
Examples:
require 'torrent-ruby'
# bencoding data
{'a' => 'animal', 'b' => ['banana', 'bologna', 42]}.bencode
#=> "d1:a6:animal1:bl6:banana7:bolognai42eee"
# bdecoding data
"ld3:one1:a3:two1:b5:threei3eed4:fourd4:five3:sixeee".bdecode
#=> [{"one"=>"a", "two"=>"b", "three"=>3}, {"four"=>{"five"=>"six"}}]
# get a TorrentFile object from a torrent file
file = TorrentFile.open 'somefile.torrent'
# get original contents of file
file.bencoded #=> some bencoded string
# get dictionary from .torrent file as ruby hash
file.to_h #=> dictionary from .torrent file
# save as new .torrent file
file.save 'newname.torrent'
# initialize a TrackerHandler object
handler = TrackerHandler.new( TorrentFile.open('somefile.torrent'),
:tracker_timeout => 5, :port => 42309)
# get list of available trackers (as an array)
trackers = handler.trackers
# establish connection to tracker from index of a tracker
# from the above 'trackers' array
success = handler.establish_connection 0
connected_tracker = handler.connected_trackers.last
# send request to a connected tracker
if success
response = handler.request( :uploaded => 1, :downloaded => 10,
:left => 100, :compact = 0,
:no_peer_id => 0, :event => 'started',
:index => 0)
end