-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
44 lines (33 loc) · 1.38 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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