transmission-rss 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/transmission-add-file +86 -0
- data/bin/transmission-rss +1 -1
- data/lib/transmission-rss.rb +1 -1
- data/lib/transmission-rss/client.rb +21 -8
- metadata +13 -11
@@ -0,0 +1,86 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'getoptlong'
|
4
|
+
|
5
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
6
|
+
require 'transmission-rss'
|
7
|
+
|
8
|
+
include TransmissionRSS
|
9
|
+
|
10
|
+
# Default config file path.
|
11
|
+
config_file = '/etc/transmission-rss.conf'
|
12
|
+
|
13
|
+
# Shows a summary of the command line options.
|
14
|
+
def usage_message( config_file )
|
15
|
+
$stderr << "#{File.basename($0)} [options]
|
16
|
+
Adds torrents from rss feeds to transmission web frontend.
|
17
|
+
|
18
|
+
-c <file> Custom config file path. Default: #{config_file}
|
19
|
+
-h This help.
|
20
|
+
|
21
|
+
"
|
22
|
+
exit(1)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Define command-line options.
|
26
|
+
options = GetoptLong.new(
|
27
|
+
[ '-c', GetoptLong::REQUIRED_ARGUMENT ],
|
28
|
+
[ '-h', GetoptLong::NO_ARGUMENT ]
|
29
|
+
)
|
30
|
+
|
31
|
+
# Parse given options.
|
32
|
+
options.each do |option, argument|
|
33
|
+
case(option)
|
34
|
+
when '-c'
|
35
|
+
config_file = argument
|
36
|
+
when '-e'
|
37
|
+
edit_config = true
|
38
|
+
when '-f'
|
39
|
+
dofork = true
|
40
|
+
when '-h'
|
41
|
+
usage_message(config_file)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Seems to be necessary when called from gem installation.
|
46
|
+
# Otherwise Config is somehow mixed up with RbConfig.
|
47
|
+
config = TransmissionRSS::Config.instance
|
48
|
+
|
49
|
+
# Default configuration.
|
50
|
+
config.load({
|
51
|
+
'feeds' => [],
|
52
|
+
'update_interval' => 600,
|
53
|
+
'add_paused' => false,
|
54
|
+
'server' => {
|
55
|
+
'host' => 'localhost',
|
56
|
+
'port' => 9091
|
57
|
+
},
|
58
|
+
'log_target' => $stderr,
|
59
|
+
'privileges' => {}
|
60
|
+
})
|
61
|
+
|
62
|
+
# Initialize a log instance and configure it.
|
63
|
+
log = Log.instance
|
64
|
+
log.target = config.log_target
|
65
|
+
log.level = Logger::DEBUG
|
66
|
+
log.formatter = proc do |sev, time, prog, msg|
|
67
|
+
"#{time.to_i}(#{sev.downcase}) #{msg}\n"
|
68
|
+
end
|
69
|
+
|
70
|
+
# Load config file (default or given by argument).
|
71
|
+
begin
|
72
|
+
config.load(config_file)
|
73
|
+
log.target = config.log_target
|
74
|
+
rescue Errno::ENOENT
|
75
|
+
log.error(config_file + ' not found')
|
76
|
+
end
|
77
|
+
log.debug(config)
|
78
|
+
|
79
|
+
# Initialize communication to transmission.
|
80
|
+
client = Client.new(config.server.host, config.server.port)
|
81
|
+
|
82
|
+
ARGV.each do |torrent_file|
|
83
|
+
client.add_torrent(torrent_file, :file, config.add_paused)
|
84
|
+
end
|
85
|
+
|
86
|
+
log.close
|
data/bin/transmission-rss
CHANGED
@@ -142,7 +142,7 @@ aggregator.feeds.concat(config.feeds)
|
|
142
142
|
# Callback for a new item on one of the feeds.
|
143
143
|
aggregator.on_new_item do |torrent_file|
|
144
144
|
Thread.start do
|
145
|
-
client.add_torrent(torrent_file, config.add_paused)
|
145
|
+
client.add_torrent(torrent_file, :url, config.add_paused)
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
data/lib/transmission-rss.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'json'
|
3
3
|
require 'timeout'
|
4
|
+
require 'base64'
|
4
5
|
|
5
6
|
# TODO
|
6
7
|
# * Why the hell do timeouts in get_session_id and add_torrent not work?!
|
@@ -46,7 +47,25 @@ class TransmissionRSS::Client
|
|
46
47
|
end
|
47
48
|
|
48
49
|
# POST json packed torrent add command.
|
49
|
-
def add_torrent(
|
50
|
+
def add_torrent(file, type, paused = false)
|
51
|
+
hash = {
|
52
|
+
"method" => "torrent-add",
|
53
|
+
"arguments" => {
|
54
|
+
"paused" => paused
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
case type
|
59
|
+
when :url
|
60
|
+
hash.arguments.filename = file
|
61
|
+
when :file
|
62
|
+
hash.arguments.metainfo = Base64.encode64(
|
63
|
+
File.readlines(file).join
|
64
|
+
)
|
65
|
+
else
|
66
|
+
raise ArgumentError.new('type has to be :url or :file.')
|
67
|
+
end
|
68
|
+
|
50
69
|
post = Net::HTTP::Post.new(
|
51
70
|
'/transmission/rpc',
|
52
71
|
initheader = {
|
@@ -55,13 +74,7 @@ class TransmissionRSS::Client
|
|
55
74
|
}
|
56
75
|
)
|
57
76
|
|
58
|
-
post.body =
|
59
|
-
"method" => "torrent-add",
|
60
|
-
"arguments" => {
|
61
|
-
"paused" => paused,
|
62
|
-
"filename" => torrent_file
|
63
|
-
}
|
64
|
-
}.to_json
|
77
|
+
post.body = hash.to_json
|
65
78
|
|
66
79
|
# retries = 3
|
67
80
|
# begin
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 7
|
9
|
+
version: 0.1.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- henning mueller
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-10-15 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -25,23 +25,25 @@ description: |-
|
|
25
25
|
email: henning@orgizm.net
|
26
26
|
executables:
|
27
27
|
- transmission-rss
|
28
|
+
- transmission-add-file
|
28
29
|
extensions: []
|
29
30
|
|
30
31
|
extra_rdoc_files: []
|
31
32
|
|
32
33
|
files:
|
33
34
|
- bin/transmission-rss
|
34
|
-
-
|
35
|
+
- bin/transmission-add-file
|
36
|
+
- lib/transmission-rss.rb
|
37
|
+
- lib/transmission-rss/aggregator.rb
|
38
|
+
- lib/transmission-rss/client.rb
|
39
|
+
- lib/transmission-rss/config-editor.rb
|
40
|
+
- lib/transmission-rss/config-editor/listbox-original.rb
|
35
41
|
- lib/transmission-rss/config-editor/listbox.rb
|
42
|
+
- lib/transmission-rss/config-editor/main.glade
|
36
43
|
- lib/transmission-rss/config-editor/main.rb
|
37
|
-
- lib/transmission-rss/config-editor/listbox-original.rb
|
38
|
-
- lib/transmission-rss/client.rb
|
39
|
-
- lib/transmission-rss/log.rb
|
40
|
-
- lib/transmission-rss/aggregator.rb
|
41
|
-
- lib/transmission-rss/hash.rb
|
42
44
|
- lib/transmission-rss/config.rb
|
43
|
-
- lib/transmission-rss/
|
44
|
-
- lib/transmission-rss.rb
|
45
|
+
- lib/transmission-rss/hash.rb
|
46
|
+
- lib/transmission-rss/log.rb
|
45
47
|
- README.rdoc
|
46
48
|
has_rdoc: true
|
47
49
|
homepage:
|