-
Notifications
You must be signed in to change notification settings - Fork 278
/
post_process.py
68 lines (50 loc) · 2.16 KB
/
post_process.py
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
68
# coding=utf-8
from __future__ import unicode_literals
from medusa import app
from medusa.server.web.core import PageTemplate
from medusa.server.web.home.handler import Home
from six import string_types, text_type
from tornroutes import route
@route('/home/postprocess(/?.*)')
class HomePostProcess(Home):
def __init__(self, *args, **kwargs):
super(HomePostProcess, self).__init__(*args, **kwargs)
def index(self):
t = PageTemplate(rh=self, filename='home_postprocess.mako')
return t.render(controller='home', action='postProcess')
def processEpisode(self, proc_dir=None, nzbName=None, jobName=None, quiet=None, process_method=None, force=None,
is_priority=None, delete_on='0', failed='0', proc_type='auto', ignore_subs=None, *args, **kwargs):
def argToBool(argument):
if isinstance(argument, string_types):
_arg = argument.strip().lower()
else:
_arg = argument
if _arg in ['1', 'on', 'true', True]:
return True
elif _arg in ['0', 'off', 'false', False]:
return False
return argument
def _decode(value):
if not value or isinstance(value, text_type):
return value
return text_type(value, 'utf-8')
if not proc_dir:
return self.redirect('/home/postprocess/')
else:
proc_dir = _decode(proc_dir)
resource_name = _decode(nzbName)
result = app.post_processor_scheduler.action.run(
path=proc_dir,
process_method=process_method,
resource_name=resource_name,
force=argToBool(force),
is_priority=argToBool(is_priority),
delete_on=argToBool(delete_on),
failed=argToBool(failed),
proc_type=proc_type,
ignore_subs=argToBool(ignore_subs)
)
if quiet is not None and int(quiet) == 1:
return result
result = result.replace('\n', '<br>\n')
return self._genericMessage('Post-processing results', result)