Beispiel #1
0
def rewrite_images():
    req_data = json.loads(request.get_data() or '{}')
    update_dict = req_data['update_dict']

    file_writer = EmbyFileStructure(return_default_config_string('file_path'))
    # we can directly call this since it only writes top level key fields
    file_writer.write_images(update_dict)

    return jsonify({'success': 'good'})
Beispiel #2
0
def remove_existing_tag():
    """
    This endpoint is used to scan javs already exist locally and update db
    """
    emby_folder = EmbyFileStructure(return_default_config_string('file_path'))
    # scan folder
    emby_folder.remove_tags()

    return 'ok'
Beispiel #3
0
def rescan_emby_folder():
    """
    This endpoint is used to scan javs already exist locally and update db
    """
    emby_folder = EmbyFileStructure(return_default_config_string('file_path'))
    # scan folder
    emby_folder.scan_emby_root_path()

    return jsonify({'success': [jav_obj['directory'] for jav_obj in emby_folder.file_list]})
Beispiel #4
0
def rewrite_nfo():
    req_data = json.loads(request.get_data() or '{}')
    update_dict = req_data['update_dict']

    JavManagerDB().upcreate_jav(update_dict)

    file_writer = EmbyFileStructure(return_default_config_string('file_path'))
    # we can directly call this since it only writes top level key fields
    file_writer.write_nfo(update_dict, verify=True)

    return jsonify({'success': 'good'})
Beispiel #5
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})
Beispiel #6
0
def update_jav_dict():
    # update db jav dict, also rewrite nfo and images

    req_data = json.loads(request.get_data() or '{}')
    update_dict = req_data['update_dict']

    # update db
    db_conn = JavManagerDB()
    db_conn.upcreate_jav(update_dict)

    file_writer = EmbyFileStructure(return_default_config_string('file_path'))
    # file structure operations
    try:
        jav_obj = file_writer.create_folder_for_existing_jav(update_dict)
    except KeyError as e:
        _car = update_dict.get('car', 'Unknown')
        update_dict.append(json.dumps({'log': f'error: {e}, skipping {_car}'}))
    # write images
    file_writer.write_images(jav_obj)
    # write nfo
    file_writer.write_nfo(jav_obj)
    # move video file
    jav_obj = file_writer.move_existing_file(jav_obj)

    return jsonify({'success': jav_obj})  # post updated jav_obj back to UI
Beispiel #7
0
def parse_emby_folder():
    path = request.args.get('path')
    sources = request.args.get('sources')

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

    emby_folder = EmbyFileStructure(path)
    # scan folder
    emby_folder.scan_emby_root_path()

    processed = []

    for each_jav in emby_folder.file_list:
        # scrape
        jav_obj = parse_single_jav(each_jav, sources)

        # file structure operations
        # write images
        emby_folder.write_images(jav_obj)
        # write nfo
        emby_folder.write_nfo(jav_obj)
        processed.append(each_jav['car'])

    return jsonify({'success': processed})
Beispiel #8
0
def rename_path_preview():
    path = request.args.get('path')

    # handle usual error
    if not os.path.exists(path):
        return jsonify({'response': [{
            'file_name': f'{path} does not exist'
        }]}), 400
    if not os.path.isdir(path):
        return jsonify({
            'response': [{
                'file_name':
                f'{path} is not a valid directory for scan'
            }]
        }), 400

    res = EmbyFileStructure(path).rename_directory_preview()

    return jsonify({
        'response':
        res,
        'header': [{
            'name': 'Current File Name',
            'selector': 'file_name',
            'sortable': True
        }, {
            'name': 'New File Name',
            'selector': 'new_file_name',
            'sortable': True
        }]
    })
Beispiel #9
0
def rename_single_file():
    req_data = json.loads(request.get_data() or '{}')
    file_objs = req_data['file_obj']

    res, old_file_name = EmbyFileStructure().rename_single_file_actual(
        file_objs)

    return jsonify({'success': {'msg': res, 'old_file_name': old_file_name}})
Beispiel #10
0
def restructure_jav():
    req_data = json.loads(request.get_data() or '{}')
    update_dict = req_data['update_dict']

    file_writer = EmbyFileStructure(return_default_config_string('file_path'))
    # file structure operations
    try:
        jav_obj = file_writer.create_folder_for_existing_jav(update_dict)
    except KeyError as e:
        _car = update_dict.get('car', 'Unknown')
        update_dict.append(json.dumps({'log': f'error: {e}, skipping {_car}'}))
    # write images
    file_writer.write_images(jav_obj)
    # write nfo
    file_writer.write_nfo(jav_obj)
    # move video file
    jav_obj = file_writer.move_existing_file(jav_obj)

    return jsonify({'success': 'good'})
Beispiel #11
0
def parse_unprocessed_folder():
    path = request.args.get('path')
    sources = request.args.get('sources')

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

    emby_folder = EmbyFileStructure(path)
    # scan folder
    emby_folder.scan_new_root_path()

    processed = []
    total = len(emby_folder.file_list)

    #print(emby_folder.file_list)

    def long_process():
        yield json.dumps({
            'log':
            'start bulk jav parses for {} items'.format(
                len(emby_folder.file_list))
        }) + '\n'
        for each_jav in emby_folder.file_list:
            # scrape
            jav_obj = parse_single_jav(each_jav, sources)

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

            # file structure operations
            try:
                jav_obj = emby_folder.create_new_folder(jav_obj)
            except KeyError as e:
                _car = each_jav.get('car', 'Unknown')
                yield json.dumps({'log': f'error: {e}, skipping {_car}'
                                  }) + '\n'
                continue
            # 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)

            processed.append(each_jav['car'])

            yield json.dumps({
                'log':
                '{} processed, {} to go'.format(each_jav['car'],
                                                total - len(processed))
            }) + '\n'
        yield json.dumps({'log': 'jav parse finishes'}) + '\n'

    return Response(long_process(), mimetype='text/event-stream')
Beispiel #12
0
 def long_process():
     for each_file_process in EmbyFileStructure.rename_directory(
             path, file_objs):
         yield json.dumps({'log': each_file_process}) + '\n'
Beispiel #13
0
def preview_single_rename():
    file_name = request.args.get('file_name')

    res = EmbyFileStructure().preview_rename_single_file(file_name)

    return jsonify({'success': res})