示例#1
0
 def _postprocess(self, path, info_hash, resource_name, failed=False):
     """Queue a postprocess action."""
     # TODO: Add a check for if not already queued or run.
     # queue a postprocess action
     queue_item = PostProcessQueueItem(path,
                                       info_hash,
                                       resource_name=resource_name,
                                       failed=failed)
     app.post_processor_queue_scheduler.action.add_item(queue_item)
示例#2
0
    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', app.PROCESS_METHOD)
        force = bool(data.get('force', False))
        is_priority = bool(data.get('is_priority', False))
        delete_on = bool(data.get('delete_on', False))
        failed = bool(data.get('failed', False))
        proc_type = bool(data.get('proc_type', False))
        ignore_subs = bool(data.get('is_priority', False))

        if not proc_dir:
            if app.PROCESS_AUTOMATICALLY and app.TV_DOWNLOAD_DIR:
                proc_dir = app.TV_DOWNLOAD_DIR
                log.info('')
            return self._bad_request(
                'Missing attribute `proc_dir`. '
                'Provide a proc_dir. Or configure Scheduled postprocessing icw. a Post processing directory.'
            )

        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
        })
示例#3
0
    def _postprocess(self, path, info_hash, resource_name, failed=False, client_type=None):
        """Queue a postprocess action."""
        # Use the info hash get a segment of episodes.
        history_items = self.main_db_con.select(
            'SELECT * FROM history WHERE info_hash = ?',
            [info_hash]
        )

        episodes = []
        for history_item in history_items:
            # Search for show in library
            show = Show.find_by_id(app.showList, history_item['indexer_id'], history_item['showid'])
            if not show:
                # Show is "no longer" available in library.
                continue
            episodes.append(show.get_episode(history_item['season'], history_item['episode']))

        queue_item = PostProcessQueueItem(
            path, info_hash, resource_name=resource_name,
            failed=failed, episodes=episodes, client_type=client_type
        )
        app.post_processor_queue_scheduler.action.add_item(queue_item)
示例#4
0
    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 json.dumps({
                'status': 'failed',
                'message': 'Missing Post-Processing dir'
            })
        else:
            proc_dir = _decode(proc_dir)
            resource_name = _decode(nzbName)

            log.info(
                'Post processing called with:\npath: {path}\nresource: {resource}',
                {
                    'path': proc_dir,
                    'resource': resource_name
                })

            # Might look strange to explicitly check both. But, it's so I have a third option.
            # And that is that neither of both is passed. For example when called by legacy third parties.
            # Like nzbToMedia.
            run_async = argToBool(kwargs.pop('run_async', '0'))
            run_sync = argToBool(kwargs.pop('run_sync', '0'))

            if run_async:
                queue_item = PostProcessQueueItem(
                    path=proc_dir,
                    process_method=process_method,
                    info_hash=None,
                    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))
                app.post_processor_queue_scheduler.action.add_item(queue_item)

                return json.dumps({
                    'status': 'success',
                    'message': 'Post process action queued',
                    'queueItem': queue_item.to_json
                })

            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

            if run_sync:
                return json.dumps({
                    'status': 'success',
                    'message': result.replace('\n', '<br>\n'),
                    'output': result.split('\n')
                })

            result = result.replace('\n', '<br>\n')
            return self._genericMessage('Post-processing results', result)