mktorrent 0.8.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/mktorrent.rb +53 -8
- metadata +9 -28
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 22f0156acd8ad036cc4ca9cf7e95287c3397261d
|
4
|
+
data.tar.gz: 7600dab3997a9bda87b6ee57b60b6a1878137ca1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6c30391db7f9542c5fed7c46e1d917d99de6e7bce8a0d8fff6e5c2c9a41b6f62d888e5b4aaad8f119255679d1123a916daf269439f1117f9ddfe2a54269fb284
|
7
|
+
data.tar.gz: 6aec4ef17e999b554029e0c1cb994a04732527a2a222dc17d1b6a12650e1f6242ddeda61864db5cc692ab8fda51c54fad6ad93233148a75b2557081894bff745
|
data/lib/mktorrent.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'bencode'
|
2
2
|
require 'digest/sha1'
|
3
|
-
require '
|
3
|
+
require 'date'
|
4
4
|
|
5
5
|
# Sample usage
|
6
6
|
#t = Torrent.new("http://your.tracker.com")
|
@@ -16,7 +16,7 @@ class Torrent
|
|
16
16
|
# optionally initialize filename
|
17
17
|
def initialize(tracker)
|
18
18
|
@tracker = tracker
|
19
|
-
@piecelength = 512
|
19
|
+
@piecelength = 512 * 1024 # 512 KB
|
20
20
|
@files = []
|
21
21
|
@filehashes = []
|
22
22
|
@size = 0
|
@@ -24,19 +24,60 @@ class Torrent
|
|
24
24
|
build_the_torrent
|
25
25
|
end
|
26
26
|
|
27
|
+
def all_files
|
28
|
+
unless @files.count < 1
|
29
|
+
all_files = []
|
30
|
+
@files.each do |f|
|
31
|
+
all_files << f[:path]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
all_files
|
35
|
+
end
|
36
|
+
|
27
37
|
def count
|
28
38
|
@files.count
|
29
39
|
end
|
30
40
|
|
41
|
+
def read_pieces(files, length)
|
42
|
+
buffer = ""
|
43
|
+
files.each do |f|
|
44
|
+
puts "hashing #{f.join("/")}"
|
45
|
+
File.open(f.join("/")) do |fh|
|
46
|
+
begin
|
47
|
+
read = fh.read(length - buffer.length)
|
48
|
+
if (buffer.length + read.length) == length
|
49
|
+
yield(buffer + read)
|
50
|
+
buffer = ""
|
51
|
+
else
|
52
|
+
buffer += read
|
53
|
+
end
|
54
|
+
end until fh.eof?
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
yield buffer
|
59
|
+
end
|
60
|
+
|
31
61
|
def build
|
32
62
|
@info = { :announce => @tracker,
|
63
|
+
:'creation date' => DateTime.now.strftime("%s"),
|
33
64
|
:info => { :name => @defaultdir,
|
34
65
|
:'piece length' => @piecelength,
|
35
|
-
:pieces => @filehashes.join,
|
36
66
|
:files => @files
|
37
67
|
#:private => 1,
|
38
68
|
}
|
39
69
|
}
|
70
|
+
@info[:info][:pieces] = ""
|
71
|
+
if @files.count > 0
|
72
|
+
i = 0
|
73
|
+
read_pieces(all_files, @piecelength) do |piece|
|
74
|
+
@info[:info][:pieces] += Digest::SHA1.digest(piece)
|
75
|
+
i += 1
|
76
|
+
if (i % 100) == 0
|
77
|
+
#print "#{(i.to_f / num_pieces * 100.0).round}%... "; $stdout.flush
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
40
81
|
end
|
41
82
|
|
42
83
|
def write_torrent(filename)
|
@@ -45,7 +86,9 @@ class Torrent
|
|
45
86
|
torrentfile.write self.to_s
|
46
87
|
#torrentfile.puts self.to_s
|
47
88
|
end
|
48
|
-
|
89
|
+
torrent_file = "#{`pwd`.chomp}/#{filename}"
|
90
|
+
puts "Wrote #{torrent_file}"
|
91
|
+
torrent_file
|
49
92
|
end
|
50
93
|
|
51
94
|
# Return the .torrent file as a string
|
@@ -61,20 +104,22 @@ class Torrent
|
|
61
104
|
end
|
62
105
|
|
63
106
|
if File.exists?(filepath)
|
64
|
-
filesize = hash_pieces(filepath)
|
107
|
+
#filesize = hash_pieces(filepath)
|
65
108
|
# TODO tidy the path up...
|
66
|
-
@files << { path: filepath.split('/'), length:
|
109
|
+
@files << { path: filepath.split('/'), length: File::open(filepath, "rb").size }
|
67
110
|
else
|
68
111
|
raise IOError, "Couldn't access #{filepath}"
|
69
112
|
end
|
70
113
|
end
|
71
114
|
|
72
|
-
|
115
|
+
# Need to read the files in @piecelength chunks and hash against that
|
116
|
+
def hash_pieces(files)
|
73
117
|
offset = 0
|
74
118
|
f = File::open(file, "rb")
|
75
119
|
@size += f.size
|
76
120
|
while offset < f.size do
|
77
|
-
|
121
|
+
# This is wrong :(
|
122
|
+
#@filehashes << Digest::SHA1.digest(IO::binread(f, offset, @piecelength))
|
78
123
|
offset += @piecelength
|
79
124
|
STDOUT.write "\r#{File.basename(file)}: hashed #{(offset.to_f / f.size.to_f)*100}%"
|
80
125
|
STDOUT.flush
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mktorrent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Timothy Mukaibo
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-04-21 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bencode
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - '='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,28 +20,12 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - '='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 0.7.0
|
30
|
-
|
31
|
-
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 3.0.0
|
38
|
-
type: :runtime
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 3.0.0
|
46
|
-
description: Create .torrent files easily with this gem
|
27
|
+
description: Create .torrent files easily with this gem. The code is ugly, but it
|
28
|
+
works :)
|
47
29
|
email: timothy@mukaibo.com
|
48
30
|
executables: []
|
49
31
|
extensions: []
|
@@ -53,27 +35,26 @@ files:
|
|
53
35
|
- test/mktorrent_test.rb
|
54
36
|
homepage: https://github.com/mukaibot/mktorrent
|
55
37
|
licenses: []
|
38
|
+
metadata: {}
|
56
39
|
post_install_message:
|
57
40
|
rdoc_options: []
|
58
41
|
require_paths:
|
59
42
|
- lib
|
60
43
|
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
44
|
requirements:
|
63
|
-
- -
|
45
|
+
- - '>='
|
64
46
|
- !ruby/object:Gem::Version
|
65
47
|
version: '0'
|
66
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
68
49
|
requirements:
|
69
|
-
- -
|
50
|
+
- - '>='
|
70
51
|
- !ruby/object:Gem::Version
|
71
52
|
version: '0'
|
72
53
|
requirements: []
|
73
54
|
rubyforge_project:
|
74
|
-
rubygems_version:
|
55
|
+
rubygems_version: 2.0.0.rc.2
|
75
56
|
signing_key:
|
76
|
-
specification_version:
|
57
|
+
specification_version: 4
|
77
58
|
summary: Create .torrent files easily with this gem
|
78
59
|
test_files:
|
79
60
|
- test/mktorrent_test.rb
|