metalink 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +11 -0
- data/Rakefile +2 -0
- data/lib/metalink.rb +2 -0
- data/lib/metalink/file.rb +53 -0
- data/lib/metalink/metalink.rb +26 -0
- data/lib/metalink/version.rb +3 -0
- data/metalink.gemspec +21 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#Metalink Ruby
|
2
|
+
|
3
|
+
Metalink Ruby is a pure ruby library which, at the moment, requires no other gems and can spit out a metalink file with any number of files in it, each with any number of links, and uses md5, sha256 and sha1pieces for verification. At the moment this is completely unconfigurable and to add a torrent magnet link you would have to create it yourself. This might change in the future. It also happens to be ever so slightly faster than the metalink binary. (with ruby 1.8.7)
|
4
|
+
|
5
|
+
Usage
|
6
|
+
|
7
|
+
t = Metalink::Metalink.new
|
8
|
+
t.add_file("/path/to/some/file.txt", [{ :type => "http", :url => "http://example.com/some/file.txt" }]
|
9
|
+
puts t.to_s
|
10
|
+
|
11
|
+
Add file takes 2 parameters. The first is the local path to the file. The second is an array of hashes, each hash being one url, with a type and a full url path
|
data/Rakefile
ADDED
data/lib/metalink.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
require 'digest/sha2'
|
3
|
+
require 'digest/sha1'
|
4
|
+
|
5
|
+
module Metalink
|
6
|
+
class MetalinkFile
|
7
|
+
|
8
|
+
def initialize(path, urls)
|
9
|
+
@path = path
|
10
|
+
@urls = urls
|
11
|
+
@piece_length = 2097152
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
out = ""
|
16
|
+
out << " <file name=\"#{File.basename(@path)}\">\n"
|
17
|
+
out << " <size>#{File.size?(@path)}</size>\n"
|
18
|
+
out << " <verification>\n"
|
19
|
+
|
20
|
+
md5_digest = Digest::MD5.new
|
21
|
+
sha256_digest = Digest::SHA2.new
|
22
|
+
sha1_hashes = []
|
23
|
+
f = File.open(@path)
|
24
|
+
while chunk = f.read(@piece_length)
|
25
|
+
md5_digest << chunk
|
26
|
+
sha256_digest << chunk
|
27
|
+
sha1_hashes << Digest::SHA1.hexdigest(chunk)
|
28
|
+
end
|
29
|
+
f.close
|
30
|
+
|
31
|
+
out << " <hash type=\"md5\">#{md5_digest.hexdigest}</hash>\n"
|
32
|
+
out << " <hash type=\"sha256\">#{sha256_digest.hexdigest}</hash>\n"
|
33
|
+
|
34
|
+
out << " <pieces length=\"#{@piece_length}\" type=\"sha1\">\n"
|
35
|
+
sha1_hashes.each_with_index do |hash, index|
|
36
|
+
out << " <hash piece=\"#{index}\">#{hash}</hash>\n"
|
37
|
+
end
|
38
|
+
out << " </pieces>\n"
|
39
|
+
|
40
|
+
out << " </verification>\n"
|
41
|
+
out << " <resources>\n"
|
42
|
+
|
43
|
+
@urls.each do |url_hash|
|
44
|
+
out << " <url type=\"#{url_hash[:type]}\">#{url_hash[:url]}</url>\n"
|
45
|
+
end
|
46
|
+
|
47
|
+
out << " </resources>\n </file>\n"
|
48
|
+
|
49
|
+
out
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "file")
|
2
|
+
|
3
|
+
module Metalink
|
4
|
+
class Metalink
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@version = 3
|
8
|
+
@files = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_file(path, urls)
|
12
|
+
@files << MetalinkFile.new(path, urls)
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
out = ""
|
17
|
+
out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
18
|
+
out << "<metalink version=\"3.0\"\n xmlns=\"http://www.metalinker.org/\"\n generator=\"https://github.com/timsjoberg/metalink-ruby/\"\n >\n<files>\n"
|
19
|
+
@files.each do |file|
|
20
|
+
out << file.to_s
|
21
|
+
end
|
22
|
+
out << "</files>\n</metalink>"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/metalink.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "metalink/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "metalink"
|
7
|
+
s.version = Metalink::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Tim Sjoberg"]
|
10
|
+
s.email = ["timothysjoberg@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/timsjoberg/metalink-ruby"
|
12
|
+
s.summary = %q{Simple library for creating metalink files}
|
13
|
+
s.description = %q{Horribly simple, completely unconfigurable library for creating metalink (version 3) files}
|
14
|
+
|
15
|
+
s.rubyforge_project = "metalink-ruby"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: metalink
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Tim Sjoberg
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-22 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Horribly simple, completely unconfigurable library for creating metalink (version 3) files
|
23
|
+
email:
|
24
|
+
- timothysjoberg@gmail.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- lib/metalink.rb
|
37
|
+
- lib/metalink/file.rb
|
38
|
+
- lib/metalink/metalink.rb
|
39
|
+
- lib/metalink/version.rb
|
40
|
+
- metalink.gemspec
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: https://github.com/timsjoberg/metalink-ruby
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project: metalink-ruby
|
71
|
+
rubygems_version: 1.3.7
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Simple library for creating metalink files
|
75
|
+
test_files: []
|
76
|
+
|