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
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})
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'})
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})
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'})