-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrutorrent.py
More file actions
67 lines (53 loc) · 2.21 KB
/
Copy pathrutorrent.py
File metadata and controls
67 lines (53 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from __future__ import unicode_literals, division, absolute_import
import os
__author__ = 'be4i'
__version__ = '0.1'
import logging
from flexget import plugin, validator
from flexget.entry import Entry
from flexget.event import event
from flexget.config_schema import one_or_more
from flexget.utils import requests, json
from flexget.utils.search import torrent_availability
from flexget.utils.template import RenderError
phpFile = 'php/addtorrent.php?json=1'
log = logging.getLogger('rutorrent')
class rutorrent(object):
schema = {
'type': 'object',
'properties': {
'user': {'type': 'string'},
'pass': {'type': 'string'},
'url': {'type': 'string'},
'path': {'type': 'string', 'format': 'path'},
'autostart': {'type': 'boolean', 'default': True}
},
'required': ['url'],
}
def on_task_output(self, task, config):
session = requests.Session()
auth = (config.get('user'), config.get('pass'))
url = config['url'] + '/' + phpFile
for entry in task.accepted:
path = entry.get('path', config.get('path', ''))
try:
path = os.path.normcase(os.path.expanduser(entry.render(path)))
except RenderError as e:
log.error('Could not render path for `%s` downloading to default directory.' % entry['title'])
# Add to default folder
path = ''
payload = {'dir_edit': path, 'url': entry['url']}
if(config['autostart'] == False):
payload.update({'torrents_start_stopped': '1'})
if task.options.test:
log.info('Would add `%s` to rutorrent' % entry['title'])
continue
result = session.get(url, params=payload, auth=auth)
if(result.json()['result'] == 'Success'):
log.info('Added `%s` to rutorrent' % entry['title'])
log.info('in folder %s ' % path)
else:
entry.fail('Fail to add `%s` to rutorrent' % entry['url'])
@event('plugin.register')
def register_plugin():
plugin.register(rutorrent, 'rutorrent', api_ver=2)