mktorrent 1.0.0 → 1.1.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 +4 -4
- data/lib/mktorrent.rb +13 -7
- data/test/mktorrent_test.rb +20 -6
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24c89cf5bda2e0a13113f67d8edfe1fa0a9ce16b
|
4
|
+
data.tar.gz: 8a069ce3dd0c5679dc9f802a7c96c6dcf351509e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 021db7bb59be186ff270de9b5f142efa4dedd66ee3ec36af1ab7c7c8540b05c391902bbf03fb96636c5e3088e68c2f14957af05febcd3061fd684251039b63b6
|
7
|
+
data.tar.gz: a1419d33ed0bb33060ebc78c370fba58c5f3a9ee5414d2eaa45ec1477fbb68925768c080327d980691b4798c0e3e4bae67dc618ee19bfcf3e413d88f47b1541a
|
data/lib/mktorrent.rb
CHANGED
@@ -11,7 +11,7 @@ require 'date'
|
|
11
11
|
# Support tracker-list
|
12
12
|
|
13
13
|
class Torrent
|
14
|
-
attr_accessor :info, :filehashes, :piecelength, :files, :defaultdir, :tracker, :size
|
14
|
+
attr_accessor :info, :filehashes, :piecelength, :files, :defaultdir, :tracker, :size, :privacy
|
15
15
|
|
16
16
|
# optionally initialize filename
|
17
17
|
def initialize(tracker)
|
@@ -21,6 +21,7 @@ class Torrent
|
|
21
21
|
@filehashes = []
|
22
22
|
@size = 0
|
23
23
|
@defaultdir = "torrent"
|
24
|
+
@privacy = 0
|
24
25
|
build_the_torrent
|
25
26
|
end
|
26
27
|
|
@@ -63,8 +64,8 @@ class Torrent
|
|
63
64
|
:'creation date' => DateTime.now.strftime("%s"),
|
64
65
|
:info => { :name => @defaultdir,
|
65
66
|
:'piece length' => @piecelength,
|
66
|
-
:files => @files
|
67
|
-
|
67
|
+
:files => @files,
|
68
|
+
:private => @privacy
|
68
69
|
}
|
69
70
|
}
|
70
71
|
@info[:info][:pieces] = ""
|
@@ -84,7 +85,6 @@ class Torrent
|
|
84
85
|
build_the_torrent
|
85
86
|
open(filename, 'w') do |torrentfile|
|
86
87
|
torrentfile.write self.to_s
|
87
|
-
#torrentfile.puts self.to_s
|
88
88
|
end
|
89
89
|
torrent_file = "#{`pwd`.chomp}/#{filename}"
|
90
90
|
puts "Wrote #{torrent_file}"
|
@@ -103,7 +103,7 @@ class Torrent
|
|
103
103
|
raise IOError, "Can't add duplicate file #{File.basename(filepath)}"
|
104
104
|
end
|
105
105
|
|
106
|
-
if File.
|
106
|
+
if File.exist?(filepath)
|
107
107
|
#filesize = hash_pieces(filepath)
|
108
108
|
# TODO tidy the path up...
|
109
109
|
@files << { path: filepath.split('/'), length: File::open(filepath, "rb").size }
|
@@ -118,8 +118,6 @@ class Torrent
|
|
118
118
|
f = File::open(file, "rb")
|
119
119
|
@size += f.size
|
120
120
|
while offset < f.size do
|
121
|
-
# This is wrong :(
|
122
|
-
#@filehashes << Digest::SHA1.digest(IO::binread(f, offset, @piecelength))
|
123
121
|
offset += @piecelength
|
124
122
|
STDOUT.write "\r#{File.basename(file)}: hashed #{(offset.to_f / f.size.to_f)*100}%"
|
125
123
|
STDOUT.flush
|
@@ -127,5 +125,13 @@ class Torrent
|
|
127
125
|
return f.size
|
128
126
|
end
|
129
127
|
|
128
|
+
def set_private
|
129
|
+
@privacy = 1
|
130
|
+
end
|
131
|
+
|
132
|
+
def set_public
|
133
|
+
@privacy = 0
|
134
|
+
end
|
135
|
+
|
130
136
|
alias build_the_torrent build
|
131
137
|
end
|
data/test/mktorrent_test.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
|
-
require '
|
1
|
+
require 'minitest/autorun'
|
2
2
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'mktorrent')
|
3
3
|
|
4
|
-
class MktorrentTest < Test
|
4
|
+
class MktorrentTest < Minitest::Test
|
5
5
|
TRACKER = "http://test.example.com"
|
6
|
-
VALIDFILEPATH = File.expand_path("#{File.dirname(__FILE__)}
|
6
|
+
VALIDFILEPATH = File.expand_path("#{File.dirname(__FILE__)}/test_data/sample_file1.vhd")
|
7
|
+
VALIDFILE2PATH = File.expand_path("#{File.dirname(__FILE__)}/test_data/sample_file2.vhd")
|
7
8
|
VALIDFILENAME = "randomfile.vhd"
|
8
|
-
VALIDFILE2PATH = File.expand_path("#{File.dirname(__FILE__)}/../tmp/randomfile2.vhd")
|
9
9
|
|
10
10
|
def setup
|
11
11
|
@torrent = Torrent.new(TRACKER)
|
12
|
+
# Lol. This is pretty bad :)
|
13
|
+
fail "Could not find #{VALIDFILEPATH}" unless File.exist? VALIDFILEPATH
|
14
|
+
fail "Could not find #{VALIDFILE2PATH}" unless File.exist? VALIDFILE2PATH
|
12
15
|
end
|
13
16
|
|
14
17
|
def test_create_torrent
|
@@ -16,7 +19,7 @@ class MktorrentTest < Test::Unit::TestCase
|
|
16
19
|
end
|
17
20
|
|
18
21
|
def test_add_file_with_invalid_file
|
19
|
-
|
22
|
+
assert_raises(IOError) { @torrent.add_file("../tmp/bogusfile.vhd") }
|
20
23
|
end
|
21
24
|
|
22
25
|
def test_add_single_valid_file
|
@@ -33,7 +36,18 @@ class MktorrentTest < Test::Unit::TestCase
|
|
33
36
|
|
34
37
|
def test_prevent_duplicate_file_from_being_added
|
35
38
|
@torrent.add_file(VALIDFILEPATH)
|
36
|
-
|
39
|
+
assert_raises(IOError) { @torrent.add_file(VALIDFILEPATH) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_default_privacy
|
43
|
+
@torrent.add_file(VALIDFILEPATH)
|
44
|
+
assert_equal 0, @torrent.privacy
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_set_privacy
|
48
|
+
test_default_privacy
|
49
|
+
@torrent.set_private
|
50
|
+
assert_equal 1, @torrent.privacy
|
37
51
|
end
|
38
52
|
|
39
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mktorrent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timothy Mukaibo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bencode
|
@@ -42,17 +42,17 @@ require_paths:
|
|
42
42
|
- lib
|
43
43
|
required_ruby_version: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
|
-
- -
|
50
|
+
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '0'
|
53
53
|
requirements: []
|
54
54
|
rubyforge_project:
|
55
|
-
rubygems_version: 2.
|
55
|
+
rubygems_version: 2.2.2
|
56
56
|
signing_key:
|
57
57
|
specification_version: 4
|
58
58
|
summary: Create .torrent files easily with this gem
|