Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add postprocess apiv2 endpoint #9212

Merged
merged 1 commit into from
Feb 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion medusa/queues/generic_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
71 changes: 71 additions & 0 deletions medusa/server/api/v2/postprocess.py
Original file line number Diff line number Diff line change
@@ -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
})
2 changes: 1 addition & 1 deletion medusa/server/api/v2/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
3 changes: 3 additions & 0 deletions medusa/server/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down