'Adds accepted entries'

def add_entries(self, task, config):

    apiurl = config.get(u'api', self.DEFAULT_API)
    api = PyloadApi(task.requests, apiurl)
    try:
        session = api.get_session(config)
    except IOError:
        raise plugin.PluginError(u'pyLoad    not    reachable', log)
    except plugin.PluginError:
        raise
    except Exception as e:
        raise plugin.PluginError((u'Unknown    error:    %s' % str(e)), log)
    hoster = config.get(u'hoster', self.DEFAULT_HOSTER)
    for entry in task.accepted:
        content = ((entry.get(u'description', u'') + u'    ') + quote(entry[u'url']))
        content = json.dumps(content)
        url = (json.dumps(entry[u'url']) if config.get(u'parse_url', self.DEFAULT_PARSE_URL) else u"''")
        log.debug(u'Parsing    url    %s', url)
        data = {u'html': content, u'url': url, u'session': session}
        result = api.post(u'parseURLs', data=data)
        parsed = result.json()
        urls = []
        for name in hoster:
            if (name in parsed):
                urls.extend(parsed[name])
                if (not config.get(u'multiple_hoster', self.DEFAULT_MULTIPLE_HOSTER)):
                    break
        if ((not urls) and (not config.get(u'preferred_hoster_only', self.DEFAULT_PREFERRED_HOSTER_ONLY))):
            for (name, purls) in parsed.items():
                if (name != u'BasePlugin'):
                    urls.extend(purls)
        if task.options.test:
            log.info(u'Would    add    `%s`    to    pyload', urls)
            continue
        if (not urls):
            if config.get(u'handle_no_url_as_failure', self.DEFAULT_HANDLE_NO_URL_AS_FAILURE):
                entry.fail((u'No    suited    urls    in    entry    %s' % entry[u'title']))
            else:
                log.info(u'No    suited    urls    in    entry    %s', entry[u'title'])
            continue
        log.debug(u'Add    %d    urls    to    pyLoad', len(urls))
        try:
            dest = (1 if config.get(u'queue', self.DEFAULT_QUEUE) else 0)
            name = config.get(u'package', entry[u'title'])
            try:
                name = entry.render(name)
            except RenderError as e:
                name = entry[u'title']
                log.error(u'Error    rendering    jinja    event:    %s', e)
            data = {u'name': json.dumps(name.encode(u'ascii', u'ignore').decode()), u'links': json.dumps(urls), u'dest': json.dumps(dest), u'session': session}
            pid = api.post(u'addPackage', data=data).text
            log.debug(u'added    package    pid:    %s', pid)
            folder = config.get(u'folder', self.DEFAULT_FOLDER)
            folder = entry.get(u'path', folder)
            if folder:
                try:
                    folder = entry.render(folder)
                except RenderError as e:
                    folder = self.DEFAULT_FOLDER
                    log.error(u'Error    rendering    jinja    event:    %s', e)
                data = json.dumps({u'folder': folder})
                api.post(u'setPackageData', data={u'pid': pid, u'data': data, u'session': session})
            package_password = config.get(u'package_password')
            if package_password:
                data = json.dumps({u'password': package_password})
                api.post(u'setPackageData', data={u'pid': pid, u'data': data, u'session': session})
        except Exception as e:
            entry.fail(str(e))
