コード例 #1
0
ファイル: local_manager.py プロジェクト: windygu/JAVOneStop
def find_images():
    car = request.args.get('car')
    sources = request.args.get('sources')
    if not car:
        return jsonify({'error': 'cannot find car from request'}), 400

    db_conn = JavManagerDB()
    try:
        jav_obj = dict(db_conn.get_by_pk(car))
    except (DoesNotExist, TypeError) as e:
        # typeerror to catch dict(None)
        jav_obj = {'car': car}

    # verify sources
    if not sources:
        sources = return_default_config_string('jav_obj_priority').split(',')
    else:
        sources = str(sources).split(',')

    res = parse_single_jav({'car': car}, sources)

    if res != jav_obj:
        jav_obj.update(res)
        db_conn.upcreate_jav(jav_obj)
    return jsonify({'success': jav_obj})
コード例 #2
0
def single_scrape():
    req_data = json.loads(request.get_data() or '{}')
    each_jav = req_data['update_dict']
    sources = return_default_config_string('jav_obj_priority').split(',')
    errors = []
    emby_folder = EmbyFileStructure(return_default_config_string('file_path'))

    # some processing for postfixes
    postfix, car_str = emby_folder.extract_subtitle_postfix_filename(
        os.path.splitext(each_jav['file_name'])[0])
    _, car_str = emby_folder.extract_CDs_postfix_filename(car_str)
    each_jav.update({'car': car_str})

    # scrape
    jav_obj = parse_single_jav(each_jav, sources)
    # add chinese subtitle tag if any
    if postfix:
        jav_obj.setdefault('genres', []).append('中字')

    # handle error when all sources fail
    if jav_obj.get('errors') and isinstance(jav_obj['errors'], list) and len(
            jav_obj['errors']) == len(sources):
        errors.append(
            json.dumps({
                'log':
                '{} process failed, cannot find any info in all sources {}'.
                format(each_jav['car'], sources)
            }))
    elif jav_obj.get('error') and isinstance(jav_obj['error'], str):
        # handle one of the source is not valid
        errors.append(
            json.dumps({
                'log':
                '{} process failed, one of the source within {} is not valid on {}'
                .format(each_jav['car'], sources, jav_obj['error'])
            }))

    # file structure operations
    try:
        jav_obj = emby_folder.create_new_folder(jav_obj)
    except KeyError as e:
        _car = each_jav.get('car', 'Unknown')
        errors.append(json.dumps({'log': f'error: {e}, skipping {_car}'}))
    # write images
    emby_folder.write_images(jav_obj)
    # write nfo
    emby_folder.write_nfo(jav_obj)
    # move video file
    jav_obj = emby_folder.put_processed_file(jav_obj)

    return jsonify({'success': jav_obj, 'errors': errors})
コード例 #3
0
ファイル: local_db.py プロジェクト: windygu/JAVOneStop
def find_images(car: str):
    db_conn = JavManagerDB()
    try:
        jav_obj = dict(db_conn.get_by_pk(car))
    except (DoesNotExist, TypeError) as e:
        # typeerror to catch dict(None)
        jav_obj = {'car': car}

    sources = return_default_config_string('jav_obj_priority').split(',')

    res = parse_single_jav({'car': car}, sources)

    if res != jav_obj:
        jav_obj.update(res)
        db_conn.upcreate_jav(jav_obj)
    return jav_obj