Esempio n. 1
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
Esempio n. 2
0
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})
Esempio n. 3
0
def partial_search():
    search_string = request.args.get('search_string')

    db_conn = JavManagerDB()
    rt = db_conn.partial_search(search_string)

    return jsonify({'success': [dict(x) for x in rt]})
Esempio n. 4
0
def local_set_page(page_template: str,
                   page_num=1,
                   url_parameter=None,
                   config=None):
    """
    local return func
    currently only support stat search
    """
    stat_type = parse_qs(page_template)
    _stat = str(stat_type.get('stat', [0])[0])
    db = JavManagerDB()

    print(f'searching jav with stat {_stat}')
    # search on both stat string and int
    s_result, max_page = db.query_on_filter({'stat': int(_stat)},
                                            page=int(page_num))
    for jav_obj in s_result:
        # get rid of invalid image url from javdb
        if 'jdbimgs' in jav_obj.get('image', ''):
            jav_obj.pop('image')
        elif 'jdbimgs' in jav_obj.get('img', ''):
            jav_obj.pop('img')

        if not jav_obj.get('image') and not jav_obj.get('img'):
            # need to refresh db to get image
            jav_obj.update(find_images(jav_obj['car']))

    return s_result, max_page
Esempio n. 5
0
def get_set_javs():
    lib_type = request.args.get('lib_type')
    set_type = request.args.get('set_type')
    page_num = request.args.get('page_num', 1)

    # check lib type exists
    if lib_type not in LIB_MAP:
        return jsonify({'error':
                        f'{lib_type} is not a supported jav library'}), 400
    else:
        _set_map = LIB_MAP[lib_type]['supported_set']
        _search_func = LIB_MAP[lib_type].get('search_func')
        _set_func = LIB_MAP[lib_type]['set_func']

    # optional search string
    search_string = request.args.get('search_string', '')
    _dedupe_car_list = []
    rt_jav_objs = []

    if not search_string:
        # parse set without search string
        # verify set type
        if set_type not in _set_map:
            set_type = list(_set_map)[0]

        jav_objs, max_page = _set_func(_set_map[set_type], page_num)
    else:
        # search by supplied string
        jav_objs, max_page = _search_func(set_type, search_string, page_num)

    for jav_obj in jav_objs:
        if jav_obj['car'] not in _dedupe_car_list:
            _dedupe_car_list.append(jav_obj['car'])
            rt_jav_objs.append(jav_obj)

    # looooop through DB
    db_conn = JavManagerDB()
    for jav_obj in rt_jav_objs:
        if db_conn.pk_exist(str(jav_obj.get('car'))):
            # we cannot use img stored in db if it was from javdb due to
            # dynamically verified id
            db_obj = dict(db_conn.get_by_pk(str(jav_obj.get('car'))))
            if db_obj.get('img') and 'jdbimgs' in db_obj['img']:
                db_obj.pop('img')

            jav_obj.update(db_obj)
        else:
            jav_obj['stat'] = 2
            db_conn.upcreate_jav(jav_obj)

    return jsonify(
        {'success': {
            'jav_objs': rt_jav_objs,
            'max_page': max_page
        }})
Esempio n. 6
0
def need_ikoa_credit(car: str):
    try:
        db = JavManagerDB()
        need = db.get_by_pk(car.upper()).get('need_ikoa_credit', '0') == "1"
        print(f'need ikoa credit: {need}')
        return need
    except DoesNotExist as e:
        # for any other error we return False
        return False
    except Exception as e:
        # for any other error we return False
        return False
Esempio n. 7
0
    def handle_jav_download(self, car: str, magnet: 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}

        retry_num = 0
        e = None

        # create download using magnet link
        try:
            created_task = self.post_magnet_to_oof(magnet)
            if created_task.get('errcode') == 10008:
                #return {'error': self.translate_map['oof_magnet_exists'].format(car=car)}
                print(f'{car} magnet already exist continue')
        except Exception as create_magnet_e:
            return {'error': self.translate_map['oof_fail_magnet'].format(car=car, create_magnet_e=create_magnet_e)}

        while retry_num < 3:
            try:
                # get task detail from list page
                search_hash = created_task['info_hash']
                task_detail = self.get_task_detail_from_hash(search_hash)
                # filter out unwanted files
                download_files = self.filter_task_details(task_detail)
                if not download_files:
                    return {'error': self.translate_map['oof_no_file'] + f' {car}'}
                break
            except NoTaskException as _e:
                return {'error': self.translate_map['oof_no_task_found'].format(car)}
            except Exception as _e:
                retry_num += 1
                sleep(15)
                print(f'current error: {_e}, retrying')
                e = _e

        # send download info to aria2
        try:
            for download_file in download_files:
                self.download_aria_on_pcode(download_file['cid'], 
                    download_file['pickup_code'])

            # if everything went well, update stat
            jav_obj['stat'] = 4
            db_conn.upcreate_jav(jav_obj)
            return jav_obj
        except Exception as _e:
            print_exc()
            e = _e
                
        return {'error': self.translate_map['oof_general_failure'].format(car=car, retry_num=retry_num, e=e)}
Esempio n. 8
0
def update_car_ikoa_stat():
    car = request.args.get('car').upper()
    stat = request.args.get('stat')
    need_ikoa_credit = request.args.get('need_ikoa_credit') or "0"

    db_conn = JavManagerDB()
    db_conn.upcreate_jav({
        'car': car,
        'stat': int(stat),
        'need_ikoa_credit': need_ikoa_credit
    })

    return jsonify({'success': 'ok'})
Esempio n. 9
0
    def search_by_car(car: str, **kwargs):
        car = car.upper()
        jav_obj = JavLibraryScraper({'car': car}).scrape_jav()
        db_conn = JavManagerDB()

        if db_conn.pk_exist(str(jav_obj.get('car'))):
            jav_obj.update(dict(db_conn.get_by_pk(str(jav_obj.get('car')))))
        else:
            jav_obj['stat'] = 2
            db_conn.upcreate_jav(jav_obj)

        # use the full image (image key) instead of img (much smaller)
        jav_obj['img'] = jav_obj.get('image', '')

        return [jav_obj], 1
Esempio n. 10
0
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
Esempio n. 11
0
    def search_for_actress(javlib_actress_code: str, page_num=1):
        search_url = 'actors/{url_parameter}?page={page_num}'
        db_conn = JavManagerDB()

        # get actress first page
        jav_objs, max_page = javdb_set_page(search_url,
                                            page_num=page_num,
                                            url_parameter=javlib_actress_code)

        for jav_obj in jav_objs:
            if db_conn.pk_exist(str(jav_obj.get('car'))):
                jav_obj.update(dict(db_conn.get_by_pk(str(
                    jav_obj.get('car')))))
            else:
                jav_obj['stat'] = 2
                db_conn.upcreate_jav(jav_obj)

        return jav_objs, max_page
Esempio n. 12
0
def clean_up_directory():
    original_root = request.args.get('original_root') or None
    if not original_root:
        return jsonify({'error': 'original_root is required parameter'})

    db_conn = JavManagerDB()
    jav_objs = db_conn.bulk_list()

    for jav_obj in jav_objs:
        if jav_obj.get('directory') and original_root in jav_obj['directory']:
            _temp = jav_obj['directory']
            _temp = _temp.replace(original_root, '')
            print('updating {} to {}'.format(jav_obj['directory'], _temp))
            jav_obj['directory'] = _temp
            db_conn.upcreate_jav(dict(jav_obj))
            #break

    return jsonify({'success': 'ok'})
Esempio n. 13
0
def update_db_jav():
    req_data = json.loads(request.get_data() or '{}')
    jav_pk = req_data.get('pk')
    update_data = req_data.get('data')

    if not jav_pk:
        return jsonify({'error': 'no pk found in posted json'}), 400

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

    current_jav_obj.update(update_data)
    db_conn.upcreate_jav(current_jav_obj)

    return jsonify({'success': dict(current_jav_obj)})
Esempio n. 14
0
    def search_for_actress(javlib_actress_code: str, page_num=1):
        """
        This only support javlibrary actress code
        """
        search_url = 'vl_star.php?&mode=&s={url_parameter}&page={page_num}'
        db_conn = JavManagerDB()

        # get actress first page
        jav_objs, max_page = javlib_set_page(search_url,
                                             page_num=page_num,
                                             url_parameter=javlib_actress_code)

        for jav_obj in jav_objs:
            if db_conn.pk_exist(str(jav_obj.get('car'))):
                jav_obj.update(dict(db_conn.get_by_pk(str(
                    jav_obj.get('car')))))
            else:
                jav_obj['stat'] = 2
                db_conn.upcreate_jav(jav_obj)

        return jav_objs, max_page
Esempio n. 15
0
def new_pick_index_rescrape():
    car = request.args.get('car')
    source = request.args.get('source')
    pick_index = request.args.get('pick_index')
    if not car:
        return jsonify({'error': 'cannot find car from request'}), 400
    if not pick_index.isdigit():
        return jsonify({'error': f'{pick_index} is not a valid index'}), 400

    # incremental pick index jav obj must exists currently
    db_conn = JavManagerDB()
    db_jav_obj = dict(db_conn.get_by_pk(car))
    db_jav_obj_old = deepcopy(db_jav_obj)

    # verify sources
    sources = return_default_config_string('jav_obj_priority').split(',')
    if source not in sources:
        raise Exception(
            f'{source} is not a valid source for pick index update')

    try:
        scraped_info = SOURCES_MAP[source](
            {
                'car': car
            }, pick_index=int(pick_index)).scrape_jav()
    except JAVNotFoundException:
        errors = (db_jav_obj.get('errors') or [])
        errors.append('{} cannot be found in {}'.format(
            db_jav_obj['car'], source))
        scraped_info = {'errors': errors}
        print(scraped_info)
    db_jav_obj.update(scraped_info)
    # also save it separate key
    db_jav_obj[source] = scraped_info

    if db_jav_obj_old != db_jav_obj:
        db_conn.upcreate_jav(db_jav_obj)
    return jsonify({'success': db_jav_obj})
Esempio n. 16
0
def create_app():
    # initialize local db and index
    _db = JavManagerDB()
    _db.create_indexes()

    # create and configure the app
    app = Flask(__name__, template_folder='templates')
    cache.init_app(app)

    app.register_blueprint(emby_actress)
    app.register_blueprint(parse_jav)
    app.register_blueprint(jav_browser)
    app.register_blueprint(directory_scan)
    app.register_blueprint(local_manager)

    app.config['JSON_AS_ASCII'] = False

    # a simple page that says hello
    @app.route('/p/<path:path>')
    @app.route('/')
    def hello(*args, **kwargs):
        return render_template('home.html')

    @app.route('/demo/<path:path>')
    def serve_demo_images(path):
        return send_from_directory(resource_path('demo'), path)

    @app.errorhandler(Exception)
    def handle_exception(e):
        # pass through HTTP errors
        if isinstance(e, HTTPException):
            return e

        print_exc()
        # now you're handling non-HTTP exceptions only
        return jsonify({'error': format_exc()}), 500

    return app
Esempio n. 17
0
    def handle_jav_download(self, car: str, magnet: 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}

        retry_num = 0
        e = None

        # send download info to aria2
        try:
            res = requests.post(self.deluge_address,
                                json={
                                    'id': 0,
                                    'method': 'core.add_torrent_magnet',
                                    'params': [magnet, {}]
                                },
                                cookies=self.cookies).json()

            if res.get('result'):
                # if everything went well, update stat
                jav_obj['stat'] = 4
                db_conn.upcreate_jav(jav_obj)
                return jav_obj
            else:
                raise Exception(res.get('error', {}).get('message'))
        except Exception as _e:
            print_exc()
            e = _e

        return {
            'error':
            self.translate_map['oof_general_failure'].format(
                car=car, retry_num=retry_num, e=e)
        }