Exemplo n.º 1
0
def create_media():
    data = request.json
    type = data.get('type')
    if not type:
        return jsonify(error='missing type')
    langs = data.get('langs') or []

    if 'id' in data:
        if not data.get('mode'):
            return jsonify(error='missing mode')
        id = ObjectId(data['id'])
        search = _get_object_search(id, type)
        if not search:
            return jsonify(error='%s %s does not exist' % (type, id))
        search['langs'] = langs
        search['mode'] = data['mode']
        search['safe'] = False
        if not Search.add(**search):
            return jsonify(error='failed to create search %s' % search)
        return jsonify(result=True)

    name = data.get('name')
    if not name:
        return jsonify(error='missing name')

    if type == 'url':
        dst = Settings.get_settings('paths')['finished_download']
        try:
            Transfer.add(name, dst)
        except Exception, e:
            return jsonify(error='failed to create transfer: %s' % str(e))
Exemplo n.º 2
0
def add_search(**search):
    # TODO: find algorithm for unsafe searches
    # if search['category'] in ['anime', 'tv']:
    #     search['safe'] = False
    search['safe'] = False
    if not _media_exists(**search) and Search.add(**search):
        logger.info('added search %s', search)
        return True
Exemplo n.º 3
0
        except Exception, e:
            logger.error('failed to create transfer for %s: %s', query, str(e))
            return -1
        count = 1
    else:
        try:
            searches = get_searches(query)
        except QueryError, e:
            logger.info(str(e))
            return -1
        count = len(searches)
        if not searches:
            logger.info('no result for query "%s', query)
        else:
            for search in searches:
                if Search.add(**search):
                    logger.info('created search %s', search)

    return count

def process_file_queries(body):
    '''Process the file queries and return a list of patterns and replacement strings.
    '''
    res = []
    tree = html.fromstring(body)
    for element in tree.cssselect('body p'):
        line = FileLine(element)
        query = line.get_query()
        if query is None:
            continue
        count = process_query(query)
Exemplo n.º 4
0
        search = {
            'name': clean(name, 1),
            'category': type,
            'mode': data['mode'],
            'langs': langs,
            'safe': False,
            }
        if type == 'music':
            search['album'] = data.get('album')
            if not search['album']:
                return jsonify(error='missing album')
        if type in ('tv', 'anime'):
            for attr in ('season', 'episode'):
                val = data.get(attr)
                search[attr] = int(val) if val else None
        if not Search.add(**search):
            return jsonify(error='failed to create search %s' % search)

    return jsonify(result=True)

@app.route('/media/create/similar', methods=['POST', 'OPTIONS'])
@crossdomain(origin='*')
def create_similar():
    data = request.json
    if not data.get('recurrence'):
        return jsonify(error='missing recurrence')

    if 'id' in data:
        id = ObjectId(data['id'])
        type = data.get('type')
        search = _get_object_search(id, type)
Exemplo n.º 5
0
 def _add_next(self, mode):
     '''Create a search for next episode or season.
     '''
     search = MSearch.get_next(self, mode=mode)
     if search and MSearch.add(**search):
         logger.info('added search %s', search)