huginn_transmission_agent 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +7 -0
- data/lib/huginn_transmission_agent.rb +5 -0
- data/lib/huginn_transmission_agent/transmission_agent.rb +58 -0
- data/lib/torrents_fake.json +104 -0
- data/lib/transmission_api.rb +10 -0
- data/lib/transmission_api/client.rb +151 -0
- data/lib/transmission_api/client_fake.rb +39 -0
- data/lib/transmission_api/exception.rb +2 -0
- data/lib/transmission_api/version.rb +3 -0
- data/spec/transmission_agent_spec.rb +13 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4dd56e509b4db548ddcca46c50d74c7f9abbb738
|
4
|
+
data.tar.gz: c2035a7dabe6dd21f13cb163ce4a4863eaa36ee4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a8c0a401299b9235b9bf97e29a4fe5af58e542046d829d5848ddecb39fe39087cfe7e54d9130cfb6277c4bf372320a22470bf81ab168743b6473a596a267c003
|
7
|
+
data.tar.gz: b827c2f47ffea404852ea3bcce77da8d1f4ff1b419d8e1b145206f0aa493eb3c04a8fdcb80149a959455e0eb13c2b882db4d4862bbe164c51642ad08e98ed317
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2017 Luiz Felipe G. Pereira
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Agents
|
2
|
+
class TransmissionAgent < Agent
|
3
|
+
|
4
|
+
default_schedule 'never'
|
5
|
+
|
6
|
+
can_dry_run!
|
7
|
+
|
8
|
+
description <<-MD
|
9
|
+
Add a Agent description here
|
10
|
+
MD
|
11
|
+
|
12
|
+
include FormConfigurable
|
13
|
+
|
14
|
+
form_configurable :username
|
15
|
+
form_configurable :password
|
16
|
+
form_configurable :url
|
17
|
+
|
18
|
+
def default_options
|
19
|
+
{
|
20
|
+
username: "username",
|
21
|
+
password: "password",
|
22
|
+
url: "http://127.0.0.1:9091/transmission/rpc"
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def validate_options
|
27
|
+
%i(username password url).all? { |key| options[:key].present? }
|
28
|
+
end
|
29
|
+
|
30
|
+
def working?
|
31
|
+
!recent_error_logs?
|
32
|
+
end
|
33
|
+
|
34
|
+
def check
|
35
|
+
begin
|
36
|
+
client.all
|
37
|
+
rescue => e
|
38
|
+
error("Error connecting to transmission: #{e.class} - #{e.message}")
|
39
|
+
raise e
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def receive(incoming_events)
|
44
|
+
incoming_events.each do |event|
|
45
|
+
log "Adding torrent: #{event.payload['description']}"
|
46
|
+
client.create(event.payload['url'])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def client
|
51
|
+
@client ||= TransmissionApi::Client.new(
|
52
|
+
username: options[:username],
|
53
|
+
password: options[:password],
|
54
|
+
url: options[:url]
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
[ { "files" : [ { "bytesCompleted" : 27062831,
|
2
|
+
"length" : 52146735,
|
3
|
+
"name" : "No Media Kings - Ghosts With Shit Jobs trailer/Content/TRAILER_3_Cinetic.mov"
|
4
|
+
},
|
5
|
+
{ "bytesCompleted" : 718,
|
6
|
+
"length" : 718,
|
7
|
+
"name" : "No Media Kings - Ghosts With Shit Jobs trailer/Description.txt"
|
8
|
+
},
|
9
|
+
{ "bytesCompleted" : 51,
|
10
|
+
"length" : 51,
|
11
|
+
"name" : "No Media Kings - Ghosts With Shit Jobs trailer/License.txt"
|
12
|
+
}
|
13
|
+
],
|
14
|
+
"hashString" : "77831ec368308f1031434c5581a76fd0c3e06cfd",
|
15
|
+
"name" : "No Media Kings - Ghosts With Shit Jobs trailer",
|
16
|
+
"percentDone" : 0.51890000000000003,
|
17
|
+
"rateDownload" : 0,
|
18
|
+
"rateUpload" : 0,
|
19
|
+
"totalSize" : 52147504
|
20
|
+
},
|
21
|
+
{ "files" : [ { "bytesCompleted" : 24892844,
|
22
|
+
"length" : 24892844,
|
23
|
+
"name" : "Michael Mandiberg - Old News/Content/mandiberg_oldnews.mov"
|
24
|
+
},
|
25
|
+
{ "bytesCompleted" : 237,
|
26
|
+
"length" : 237,
|
27
|
+
"name" : "Michael Mandiberg - Old News/Description.txt"
|
28
|
+
},
|
29
|
+
{ "bytesCompleted" : 669,
|
30
|
+
"length" : 669,
|
31
|
+
"name" : "Michael Mandiberg - Old News/LegalTorrents.txt"
|
32
|
+
},
|
33
|
+
{ "bytesCompleted" : 101,
|
34
|
+
"length" : 101,
|
35
|
+
"name" : "Michael Mandiberg - Old News/License.txt"
|
36
|
+
}
|
37
|
+
],
|
38
|
+
"hashString" : "5f888e119ecb0cf8c25e68925164f533b1007038",
|
39
|
+
"name" : "Michael Mandiberg - Old News",
|
40
|
+
"percentDone" : 1,
|
41
|
+
"rateDownload" : 0,
|
42
|
+
"rateUpload" : 0,
|
43
|
+
"totalSize" : 24893851
|
44
|
+
},
|
45
|
+
{ "files" : [ { "bytesCompleted" : 31103230,
|
46
|
+
"length" : 31103230,
|
47
|
+
"name" : "pearl-jam-life-wasted-video/PearlJamLifeWasted.avi"
|
48
|
+
} ],
|
49
|
+
"hashString" : "1b2162c33001cb3c51d917441e74e313996dff96",
|
50
|
+
"name" : "pearl-jam-life-wasted-video",
|
51
|
+
"percentDone" : 1,
|
52
|
+
"rateDownload" : 0,
|
53
|
+
"rateUpload" : 0,
|
54
|
+
"totalSize" : 31103230
|
55
|
+
},
|
56
|
+
{ "files" : [ { "bytesCompleted" : 31772861,
|
57
|
+
"length" : 31772861,
|
58
|
+
"name" : "thewoolleyman - cinabox-screencast/Content/Cinabox_Screencast.mov"
|
59
|
+
},
|
60
|
+
{ "bytesCompleted" : 309,
|
61
|
+
"length" : 309,
|
62
|
+
"name" : "thewoolleyman - cinabox-screencast/Description.txt"
|
63
|
+
},
|
64
|
+
{ "bytesCompleted" : 669,
|
65
|
+
"length" : 669,
|
66
|
+
"name" : "thewoolleyman - cinabox-screencast/LegalTorrents.txt"
|
67
|
+
},
|
68
|
+
{ "bytesCompleted" : 52,
|
69
|
+
"length" : 52,
|
70
|
+
"name" : "thewoolleyman - cinabox-screencast/License.txt"
|
71
|
+
}
|
72
|
+
],
|
73
|
+
"hashString" : "0032886cdb4b0dcd6e75b5ac6901afda64367e0c",
|
74
|
+
"name" : "thewoolleyman - cinabox-screencast",
|
75
|
+
"percentDone" : 1,
|
76
|
+
"rateDownload" : 0,
|
77
|
+
"rateUpload" : 0,
|
78
|
+
"totalSize" : 31773891
|
79
|
+
},
|
80
|
+
{ "files" : [ { "bytesCompleted" : 0,
|
81
|
+
"length" : 13894821,
|
82
|
+
"name" : "Von Allan Studio - the road to god knows___ trailer/Content/the road to god knows... graphic novel trailer.wmv"
|
83
|
+
},
|
84
|
+
{ "bytesCompleted" : 0,
|
85
|
+
"length" : 1114,
|
86
|
+
"name" : "Von Allan Studio - the road to god knows___ trailer/Description.txt"
|
87
|
+
},
|
88
|
+
{ "bytesCompleted" : 0,
|
89
|
+
"length" : 669,
|
90
|
+
"name" : "Von Allan Studio - the road to god knows___ trailer/LegalTorrents.txt"
|
91
|
+
},
|
92
|
+
{ "bytesCompleted" : 0,
|
93
|
+
"length" : 127,
|
94
|
+
"name" : "Von Allan Studio - the road to god knows___ trailer/License.txt"
|
95
|
+
}
|
96
|
+
],
|
97
|
+
"hashString" : "6d97bb6424d048fe605d3fe558c5c5333cdd6227",
|
98
|
+
"name" : "Von Allan Studio - the road to god knows___ trailer",
|
99
|
+
"percentDone" : 0,
|
100
|
+
"rateDownload" : 0,
|
101
|
+
"rateUpload" : 0,
|
102
|
+
"totalSize" : 13896731
|
103
|
+
}
|
104
|
+
]
|
@@ -0,0 +1,151 @@
|
|
1
|
+
class TransmissionApi::Client
|
2
|
+
attr_accessor :session_id
|
3
|
+
attr_accessor :url
|
4
|
+
attr_accessor :basic_auth
|
5
|
+
attr_accessor :fields
|
6
|
+
attr_accessor :debug_mode
|
7
|
+
|
8
|
+
TORRENT_FIELDS = [
|
9
|
+
"id",
|
10
|
+
"name",
|
11
|
+
"totalSize",
|
12
|
+
"addedDate",
|
13
|
+
"isFinished",
|
14
|
+
"rateDownload",
|
15
|
+
"rateUpload",
|
16
|
+
"percentDone",
|
17
|
+
"files"
|
18
|
+
]
|
19
|
+
|
20
|
+
def initialize(opts)
|
21
|
+
@url = opts[:url]
|
22
|
+
@fields = opts[:fields] || TORRENT_FIELDS
|
23
|
+
@basic_auth = { :username => opts[:username], :password => opts[:password] } if opts[:username]
|
24
|
+
@session_id = "NOT-INITIALIZED"
|
25
|
+
@debug_mode = opts[:debug_mode] || false
|
26
|
+
end
|
27
|
+
|
28
|
+
def all
|
29
|
+
log "get_torrents"
|
30
|
+
|
31
|
+
response =
|
32
|
+
post(
|
33
|
+
:method => "torrent-get",
|
34
|
+
:arguments => {
|
35
|
+
:fields => fields
|
36
|
+
}
|
37
|
+
)
|
38
|
+
|
39
|
+
response["arguments"]["torrents"]
|
40
|
+
end
|
41
|
+
|
42
|
+
def find(id)
|
43
|
+
log "get_torrent: #{id}"
|
44
|
+
|
45
|
+
response =
|
46
|
+
post(
|
47
|
+
:method => "torrent-get",
|
48
|
+
:arguments => {
|
49
|
+
:fields => fields,
|
50
|
+
:ids => [id]
|
51
|
+
}
|
52
|
+
)
|
53
|
+
|
54
|
+
response["arguments"]["torrents"].first
|
55
|
+
end
|
56
|
+
|
57
|
+
def create(filename)
|
58
|
+
log "add_torrent: #{filename}"
|
59
|
+
|
60
|
+
response =
|
61
|
+
post(
|
62
|
+
:method => "torrent-add",
|
63
|
+
:arguments => {
|
64
|
+
:filename => filename
|
65
|
+
}
|
66
|
+
)
|
67
|
+
|
68
|
+
response["arguments"]["torrent-added"]
|
69
|
+
end
|
70
|
+
|
71
|
+
def destroy(id)
|
72
|
+
log "remove_torrent: #{id}"
|
73
|
+
|
74
|
+
response =
|
75
|
+
post(
|
76
|
+
:method => "torrent-remove",
|
77
|
+
:arguments => {
|
78
|
+
:ids => [id],
|
79
|
+
:"delete-local-data" => true
|
80
|
+
}
|
81
|
+
)
|
82
|
+
|
83
|
+
response
|
84
|
+
end
|
85
|
+
|
86
|
+
def post(opts)
|
87
|
+
response_parsed = JSON::parse( http_post(opts).body )
|
88
|
+
|
89
|
+
if response_parsed["result"] != "success"
|
90
|
+
raise TransmissionApi::Exception, response_parsed["result"]
|
91
|
+
end
|
92
|
+
|
93
|
+
response_parsed
|
94
|
+
end
|
95
|
+
|
96
|
+
def http_post(opts)
|
97
|
+
post_options = {
|
98
|
+
:body => opts.to_json,
|
99
|
+
:headers => { "x-transmission-session-id" => session_id }
|
100
|
+
}
|
101
|
+
post_options.merge!( :basic_auth => basic_auth ) if basic_auth
|
102
|
+
|
103
|
+
log "url: #{url}"
|
104
|
+
log "post_body:"
|
105
|
+
log JSON.parse(post_options[:body]).to_yaml
|
106
|
+
log "------------------"
|
107
|
+
|
108
|
+
response = HTTParty.post( url, post_options )
|
109
|
+
|
110
|
+
log_response response
|
111
|
+
|
112
|
+
# retry connection if session_id incorrect
|
113
|
+
if( response.code == 409 )
|
114
|
+
log "changing session_id"
|
115
|
+
@session_id = response.headers["x-transmission-session-id"]
|
116
|
+
response = http_post(opts)
|
117
|
+
end
|
118
|
+
|
119
|
+
response
|
120
|
+
end
|
121
|
+
|
122
|
+
def log(message)
|
123
|
+
Kernel.puts "[TransmissionApi #{Time.now.strftime( "%F %T" )}] #{message}" if debug_mode
|
124
|
+
end
|
125
|
+
|
126
|
+
def log_response(response)
|
127
|
+
body = nil
|
128
|
+
begin
|
129
|
+
body = JSON.parse(response.body).to_yaml
|
130
|
+
rescue
|
131
|
+
body = response.body
|
132
|
+
end
|
133
|
+
|
134
|
+
headers = response.headers.to_yaml
|
135
|
+
|
136
|
+
log "response.code: #{response.code}"
|
137
|
+
log "response.message: #{response.message}"
|
138
|
+
|
139
|
+
log "response.body_raw:"
|
140
|
+
log response.body
|
141
|
+
log "-----------------"
|
142
|
+
|
143
|
+
log "response.body:"
|
144
|
+
log body
|
145
|
+
log "-----------------"
|
146
|
+
|
147
|
+
log "response.headers:"
|
148
|
+
log headers
|
149
|
+
log "------------------"
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class TransmissionApi::ClientFake < TransmissionApi::Client
|
2
|
+
|
3
|
+
attr_reader :torrents
|
4
|
+
|
5
|
+
def initialize(opts)
|
6
|
+
super
|
7
|
+
torrents_path = opts[:torrents_path] || "#{File.dirname(__FILE__)}/../torrents_fake.json"
|
8
|
+
@torrents = JSON.parse(File.read(torrents_path))
|
9
|
+
end
|
10
|
+
|
11
|
+
def all
|
12
|
+
torrents
|
13
|
+
end
|
14
|
+
|
15
|
+
def find(id)
|
16
|
+
torrents.select { |e| e["hashString"] == id }.first
|
17
|
+
end
|
18
|
+
|
19
|
+
def create(filename)
|
20
|
+
torrent = {
|
21
|
+
"files" => [],
|
22
|
+
"hashString" => "77831ec368308f1031434c5581a76fd0c3e06cfd",
|
23
|
+
"name" => "No Media Kings - Ghosts With Shit Jobs trailer",
|
24
|
+
"percentDone" => 0,
|
25
|
+
"rateUpload" => 0,
|
26
|
+
"rateDownload" => 0,
|
27
|
+
"totalSize" => 100
|
28
|
+
}
|
29
|
+
|
30
|
+
torrents << torrent
|
31
|
+
|
32
|
+
torrent
|
33
|
+
end
|
34
|
+
|
35
|
+
def destroy(id)
|
36
|
+
torrents.delete_if { |e| e["hashString"] == id }
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'huginn_agent/spec_helper'
|
3
|
+
|
4
|
+
describe Agents::TransmissionAgent do
|
5
|
+
before(:each) do
|
6
|
+
@valid_options = Agents::TransmissionAgent.new.default_options
|
7
|
+
@checker = Agents::TransmissionAgent.new(:name => "TransmissionAgent", :options => @valid_options)
|
8
|
+
@checker.user = users(:bob)
|
9
|
+
@checker.save!
|
10
|
+
end
|
11
|
+
|
12
|
+
pending "add specs here"
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: huginn_transmission_agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luiz Felipe G. Pereira
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: huginn_agent
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.14.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.14.0
|
69
|
+
description: This agent provides an interface between Huginn and the Transmission
|
70
|
+
torrent client
|
71
|
+
email:
|
72
|
+
- luiz.felipe.gp@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- LICENSE.txt
|
78
|
+
- lib/huginn_transmission_agent.rb
|
79
|
+
- lib/huginn_transmission_agent/transmission_agent.rb
|
80
|
+
- lib/torrents_fake.json
|
81
|
+
- lib/transmission_api.rb
|
82
|
+
- lib/transmission_api/client.rb
|
83
|
+
- lib/transmission_api/client_fake.rb
|
84
|
+
- lib/transmission_api/exception.rb
|
85
|
+
- lib/transmission_api/version.rb
|
86
|
+
- spec/transmission_agent_spec.rb
|
87
|
+
homepage: https://github.com/Draiken/huginn_transmission_agent
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.6.12
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Huginn Agent for integration with Transmission
|
111
|
+
test_files:
|
112
|
+
- spec/transmission_agent_spec.rb
|