diff --git a/medusa/queues/generic_queue.py b/medusa/queues/generic_queue.py index e891eb7943..b337381e8b 100644 --- a/medusa/queues/generic_queue.py +++ b/medusa/queues/generic_queue.py @@ -116,8 +116,9 @@ def __init__(self, name, action_id=0): self.queue_time = datetime.utcnow() self.start_time = None self.success = None + self.identifier = str(uuid4()) self._to_json = { - 'identifier': str(uuid4()), + 'identifier': self.identifier, 'name': self.name, 'priority': self.priority, 'actionId': self.action_id, diff --git a/medusa/server/api/v2/postprocess.py b/medusa/server/api/v2/postprocess.py new file mode 100644 index 0000000000..1ffd7b2fb6 --- /dev/null +++ b/medusa/server/api/v2/postprocess.py @@ -0,0 +1,71 @@ +# coding=utf-8 +"""Request handler for statistics.""" +from __future__ import unicode_literals + +from medusa import app +from medusa.process_tv import PostProcessQueueItem +from medusa.server.api.v2.base import BaseRequestHandler + +from tornado.escape import json_decode + + +class PostProcessHandler(BaseRequestHandler): + """Postprocess request handler.""" + + #: resource name + name = 'postprocess' + #: identifier + identifier = ('identifier', r'[0-9a-f-]+') + #: allowed HTTP methods + allowed_methods = ('GET', 'POST',) + + def get(self, identifier): + """Collect postprocess queue items. + + :param identifier: + """ + queue_history = app.post_processor_queue_scheduler.action.history + queue_history = [item for item in queue_history if item.name == 'POSTPROCESSQUEUE-POST-PROCESS'] + if identifier: + queue_history = [item for item in queue_history if item.identifier == identifier] + + if len(queue_history) == 1: + return self._ok(data=queue_history[0].to_json) + return self._ok(data=[item.to_json for item in queue_history]) + + def post(self, identifier=None): + """Queue a postprocess job.""" + data = json_decode(self.request.body) + + proc_dir = data.get('proc_dir', '') + resource = data.get('resource', '') + process_method = data.get('process_method', False) + force = data.get('force', False) + is_priority = data.get('is_priority', False) + delete_on = data.get('delete_on', False) + failed = data.get('failed', False) + proc_type = data.get('proc_type', False) + ignore_subs = data.get('is_priority', False) + + if not proc_dir: + return self._bad_request('Missing proc_dir') + + queue_item = PostProcessQueueItem( + path=proc_dir, + process_method=process_method, + info_hash=None, + resource_name=resource, + force=force, + is_priority=is_priority, + delete_on=delete_on, + failed=failed, + proc_type=proc_type, + ignore_subs=ignore_subs + ) + app.post_processor_queue_scheduler.action.add_item(queue_item) + + return self._created(data={ + 'status': 'success', + 'message': 'Post process action queued', + 'queueItem': queue_item.to_json + }) diff --git a/medusa/server/api/v2/providers.py b/medusa/server/api/v2/providers.py index 30472edf61..9920ded171 100644 --- a/medusa/server/api/v2/providers.py +++ b/medusa/server/api/v2/providers.py @@ -28,7 +28,7 @@ class ProvidersHandler(BaseRequestHandler): #: path param path_param = ('path_param', r'\w+') #: allowed HTTP methods - allowed_methods = ('GET', 'POST', 'PATCH', 'DELETE', ) + allowed_methods = ('GET',) def get(self, identifier, path_param=None): """ diff --git a/medusa/server/core.py b/medusa/server/core.py index 9c170565fc..7c30eec069 100644 --- a/medusa/server/core.py +++ b/medusa/server/core.py @@ -27,6 +27,7 @@ from medusa.server.api.v2.history import HistoryHandler from medusa.server.api.v2.internal import InternalHandler from medusa.server.api.v2.log import LogHandler +from medusa.server.api.v2.postprocess import PostProcessHandler from medusa.server.api.v2.providers import ProvidersHandler from medusa.server.api.v2.search import SearchHandler from medusa.server.api.v2.series import SeriesHandler @@ -83,6 +84,8 @@ def get_apiv2_handlers(base): return [ # Order: Most specific to most generic + # /api/v2/postprocess + PostProcessHandler.create_app_handler(base), # /api/v2/providers ProvidersHandler.create_app_handler(base),