def process_censored(): try: source = LogicNormal.get_path_list('censored_download_path') target = LogicNormal.get_path_list('censored_target_path') no_censored_path = ModelSetting.get('censored_temp_path') if len(source) == 0 or len(target) == 0 or no_censored_path == '': logger.info('Error censored. path info is empty') return # 쓰레기 정리 for path in source: FileProcess.remove_small_file_and_move_target( path, ModelSetting.get_int('censored_min_size')) include_original_filename = ModelSetting.get_bool( 'include_original_filename') count = 0 for path in source: filelist = os.listdir(path.strip()) for filename in filelist: file_path = os.path.join(path, filename) if os.path.isdir(file_path): continue try: entity = ModelItem('censored', path, filename) newfilename = FileProcess.change_filename_censored( filename) logger.debug('newfilename : %s', newfilename) if newfilename is None: dest_filepath = os.path.join( no_censored_path, filename) entity.move_type = 1 entity.target_dir = no_censored_path entity.target_filename = filename else: # 이미 파일처리를 한거라면.. # newfilename 과 filename 이 [] 제외하고 같다면 처리한파일로 보자 # 그런 파일은 다시 원본파일명 옵션을 적용하지 않아야한다. logger.debug(filename) logger.debug(newfilename) # adn-091-uncenrosed.mp4 # 같이 시작하더라도 [] 가 없다면... 변경 # [] 없거나, 시작이 다르면.. 완벽히 일치 하지 않으면 if filename != newfilename and (( filename.find('[') == -1 or filename.find(']') == -1 ) or not os.path.splitext(filename)[0].startswith( os.path.splitext(newfilename)[0])): newfilename = FileProcess.change_filename_censored_by_save_original( include_original_filename, filename, newfilename) else: # 이미 한번 파일처리를 한것으로 가정하여 변경하지 않는다. newfilename = filename # 기존에 cd1 [..].mp4 는 []를 제거한다 match = re.search(r'cd\d(?P<remove>\s\[.*?\])', newfilename) if match: newfilename = newfilename.replace( match.group('remove'), '') logger.debug('%s => %s', filename, newfilename) folder_name = newfilename.split('-')[0].upper() censored_use_meta = ModelSetting.get( 'censored_use_meta') target_folder = '' use_meta_1_need = False if censored_use_meta == '0' or censored_use_meta == '1': for tmp in target: if os.path.exists( os.path.join( tmp.strip(), folder_name)): target_folder = os.path.join( tmp.strip(), folder_name) break if target_folder == '': if censored_use_meta == '0': target_folder = os.path.join( target[0].strip(), folder_name) else: use_meta_1_need = True if use_meta_1_need or censored_use_meta == '2': search_name = FileProcess.change_filename_censored( newfilename) search_name = os.path.splitext( search_name)[0].replace('-', ' ') search_name = re.sub('\s*\[.*?\]', '', search_name).strip() match = re.search(r'(?P<cd>cd\d{1,2})$', search_name) if match: search_name = search_name.replace( match.group('cd'), '') logger.debug(search_name) data = FileProcess.search(search_name, do_trans=False) #logger.debug(data) #if (len(data) == 1 and data[0]['score'] >= 95) or (len(data)>1 and data[0]['score']==100): if data and ((len(data) == 1 and data[0]['score'] >= 95) or (len(data) > 1 and data[0]['score'] == 100)): #if score_100_last_index != -1: find_meta = True if data[0]['meta'] == 'dmm': target_folder = os.path.join( ModelSetting.get( 'censored_meta_dmm_path'), folder_name) elif data[0]['meta'] == 'javdb': target_folder = os.path.join( ModelSetting.get( 'censored_meta_javdb_path'), folder_name) else: target_folder = os.path.join( ModelSetting.get( 'censored_meta_no_path'), folder_name) if not os.path.exists(target_folder): os.makedirs(target_folder) dest_filepath = os.path.join( target_folder, newfilename) logger.debug('MOVE : %s %s' % (filename, dest_filepath)) entity.move_type = 0 entity.target_dir = target_folder entity.target_filename = newfilename if os.path.exists(dest_filepath): logger.debug('EXISTS : %s', dest_filepath) os.remove(file_path) entity.move_type = 2 if os.path.exists(file_path): shutil.move(os.path.join(path, filename), dest_filepath) count += 1 except Exception as e: logger.debug('Exception:%s', e) logger.debug(traceback.format_exc()) finally: entity.save() pass except Exception as e: logger.debug('Exception:%s', e) logger.debug(traceback.format_exc())
def process_western(): try: source = LogicNormal.get_path_list('western_download_path') target = LogicNormal.get_path_list('western_target_path') logger.debug('source1 : %s', ModelSetting.get('western_download_path')) logger.debug('source2 : %s', source) target_child_list = [] for t in target: listdirs = os.listdir(t) for tt in listdirs: #2020-06-16 tmp = os.path.join(t, tt) if os.path.isdir(tmp): target_child_list.append(tmp) #target_child_list.append(os.path.join(t, tt)) no_type_path = ModelSetting.get('western_temp_path') if len(source) == 0 or len(target) == 0 or no_type_path == '': logger.info('Error western. path info is empty') return # 쓰레기 정리 ext_list = ModelSetting.get_list('western_remove_ext') if ext_list: for path in source: FileProcess.remove_match_ext(path, ext_list) use_meta = ModelSetting.get('western_use_meta') for path in source: filelist = os.listdir(path.strip()) for filename in filelist: target_folder = None file_path = os.path.join(path, filename) entity = ModelItem('western', path, filename) try: if use_meta == '1': data = FileProcess.search(filename, only_javdb=True) if data and ( (len(data) == 1 and data[0]['score'] >= 95) or (len(data) > 1 and data[0]['score'] == 100)): target_folder = os.path.join( ModelSetting.get( 'western_meta_match_path'), data[0]['id_show'].split('.')[0]) #logger.debug() entity.move_type = 0 entity.target_dir = target_folder entity.target_filename = filename if not os.path.exists(target_folder): os.makedirs(target_folder) if target_folder is None: for t in target_child_list: dirname = os.path.basename(t) if filename.find(dirname) != -1: target_folder = t entity.move_type = 3 break if target_folder is None: logger.debug('NOT WESTERN!!!! : %s ' % filename) target_folder = no_type_path entity.move_type = 1 #if target_folder is None: entity.target_dir = target_folder entity.target_filename = filename dest_filepath = os.path.join(target_folder, filename) if os.path.exists(dest_filepath): logger.debug('EXISTS : %s', dest_filepath) os.remove(file_path) entity.move_type = 2 continue logger.debug('MOVE : %s => %s', filename, dest_filepath) shutil.move(os.path.join(path, filename), dest_filepath) except Exception as e: logger.debug('Exception:%s', e) logger.debug(traceback.format_exc()) finally: entity.save() pass except Exception as e: logger.debug('Exception:%s', e) logger.debug(traceback.format_exc())
def api(sub): try: if sub == 'search': arg = request.args.get('code') ret = FileProcess.search(arg) ret = list(reversed(ret)) elif sub == 'update': arg = request.args.get('code') ret = FileProcess.update( arg, use_discord_proxy=ModelSetting.get_bool('use_discord_proxy')) elif sub == 'image': from PIL import Image import requests # 2020-06-02 proxy 사용시 포스터처리 image_url = request.args.get('url') logger.debug(image_url) method = ModelSetting.get('javdb_landscape_poster') if method == '0': if FileProcess.Vars.proxies is None: return redirect(image_url) else: im = Image.open( requests.get(image_url, stream=True, proxies=FileProcess.Vars.proxies).raw) filename = os.path.join(path_data, 'tmp', 'rotate.jpg') im.save(filename) return send_file(filename, mimetype='image/jpeg') im = Image.open( requests.get(image_url, stream=True, proxies=FileProcess.Vars.proxies).raw) width, height = im.size logger.debug(width) logger.debug(height) if height > width * 1.5: return redirect(image_url) if method == '1': if width > height: im = im.rotate(-90, expand=True) elif method == '2': if width > height: im = im.rotate(90, expand=True) elif method == '3': new_height = int(width * 1.5) new_im = Image.new('RGB', (width, new_height)) new_im.paste(im, (0, int((new_height - height) / 2))) im = new_im filename = os.path.join(path_data, 'tmp', 'rotate.jpg') im.save(filename) return send_file(filename, mimetype='image/jpeg') elif sub == 'image_proxy': from PIL import Image import requests #requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = 'DES-CBC3-SHA' image_url = request.args.get('url') logger.debug('image_url : %s', image_url) #2020-09-21 핸드쉐이크 에러 from system.logic_command import SystemLogicCommand filename = os.path.join(path_data, 'tmp', 'proxy_%s.jpg' % str(time.time())) #im = Image.open(requests.get(image_url, stream=True, verify=False, proxies=FileProcess.Vars.proxies).raw) #im.save(filename) if ModelSetting.get_bool('use_proxy'): # 알파인 도커 wget 에 -e 옵션 안먹음 #tmp = image_url.split('//') #if len(tmp) == 2: # image_url = tmp[1] #command = ['wget', '-O', filename, image_url, '-e', 'use_proxy=yes', '-e', 'http_proxy=%s' % ModelSetting.get('proxy_url').replace('https://', '').replace('http://', '')] command = [ 'curl', '-o', filename, image_url, '-x', ModelSetting.get('proxy_url').replace('https://', '').replace( 'http://', '') ] logger.debug(' '.join(command)) ret = SystemLogicCommand.execute_command_return(command) else: tmp = image_url.split('//') if len(tmp) == 2: image_url = tmp[1] ret = SystemLogicCommand.execute_command_return( ['curl', '-o', filename, image_url]) return send_file(filename, mimetype='image/jpeg') elif sub == 'discord_proxy': from tool_expand import ToolExpandDiscord image_url = request.args.get('url') ret = ToolExpandDiscord.discord_proxy_image( image_url, webhook_url=ModelSetting.get('discord_proxy_webhook_url')) #logger.debug(ret) #return redirect(ret) from PIL import Image import requests im = Image.open(requests.get(ret, stream=True, verify=False).raw) filename = os.path.join(path_data, 'tmp', 'proxy.jpg') im.save(filename) return send_file(filename, mimetype='image/jpeg') return jsonify(ret) except Exception as e: logger.debug('Exception:%s', e) logger.debug(traceback.format_exc())
def process_uncensored(): try: source = LogicNormal.get_path_list('uncensored_download_path') target = LogicNormal.get_path_list('uncensored_target_path') # 폴더목록 넣기 target_child_list = [] for t in target: listdirs = os.listdir(t) for tt in listdirs: #2020-06-16 tmp = os.path.join(t, tt) if os.path.isdir(tmp): target_child_list.append(tmp) no_type_path = ModelSetting.get('uncensored_temp_path') if len(source) == 0 or len(target) == 0 or no_type_path == '': logger.info('Error censored. path info is empty') return # 쓰레기 정리 for path in source: FileProcess.remove_small_file_and_move_target( path, ModelSetting.get_int('uncensored_min_size')) count = 0 for path in source: filelist = os.listdir(path.strip()) for filename in filelist: file_path = os.path.join(path, filename) if os.path.isdir(file_path): continue try: entity = ModelItem('uncensored', path, filename) use_meta = ModelSetting.get('uncensored_use_meta') tmp = None target_folder = None if os.path.splitext(filename)[1] in [ '.mp4', '.avi', '.mkv', '.ts', '.wmv', '.m2ts', '.smi', ',srt', '.ass' ]: tmp = FileProcess.uncensored_filename_analyze( filename) if tmp is None or use_meta == '0': logger.debug('tmp:%s use_meta:%s' % (tmp, use_meta)) #continue for t in target_child_list: dirname = os.path.basename(t) #logger.debug(dirname) if filename.find(dirname) != -1: target_folder = t dest_filepath = os.path.join( target_folder, filename) entity.move_type = 3 entity.target_dir = target_folder entity.target_filename = filename break if target_folder is None: logger.debug('NOT UNCENSORED!!!! : %s ' % filename) dest_filepath = os.path.join( no_type_path, filename) entity.move_type = 1 entity.target_dir = no_type_path entity.target_filename = filename else: logger.debug(filename) logger.debug(tmp) folder_name = tmp[0] newfilename = filename if use_meta == '1': target_folder = os.path.join( ModelSetting.get( 'uncensored_meta_unmatch_path'), folder_name) if tmp[1] is not None: data = FileProcess.search(filename, only_javdb=True) logger.debug(data) if data and ( (len(data) == 1 and data[0]['score'] >= 95) or (len(data) > 1 and data[0]['score'] == 100)): #if data and len(data) == 1 and data[0]['score'] >= 95 or len(data)>1 and data[0]['score']==100: target_folder = os.path.join( ModelSetting.get( 'uncensored_meta_match_path'), folder_name) if not os.path.exists(target_folder): os.makedirs(target_folder) if tmp[0] == 'fc2': code = tmp[1].split('-')[1] match = re.search( r'[-_](?P<no>\d)$', os.path.splitext(filename)[0]) if match: newfilename = filename.replace( '%s%s' % (code, match.group(0)), '%scd%s' % (code, match.group('no'))) logger.debug('filename : %s', newfilename) match = re.search( r'[-_](?P<no>[A-Z])$', os.path.splitext(filename)[0]) if match: no = ord(match.group('no')) - ord('A') + 1 newfilename = filename.replace( '%s%s' % (code, match.group(0)), '%scd%s' % (code, no)) logger.debug('filename : %s', newfilename) dest_filepath = os.path.join( target_folder, newfilename) logger.debug('MOVE : %s %s' % (filename, dest_filepath)) entity.move_type = 0 entity.target_dir = target_folder entity.target_filename = newfilename if os.path.exists(dest_filepath): logger.debug('EXISTS : %s', dest_filepath) os.remove(file_path) entity.move_type = 2 continue logger.debug('MOVE : %s => %s', filename, dest_filepath) shutil.move(os.path.join(path, filename), dest_filepath) count += 1 except Exception as e: logger.debug('Exception:%s', e) logger.debug(traceback.format_exc()) finally: entity.save() pass except Exception as e: logger.debug('Exception:%s', e) logger.debug(traceback.format_exc())
def api(sub): try: if sub == 'search': arg = request.args.get('code') ret = FileProcess.search(arg) ret = list(reversed(ret)) elif sub == 'update': arg = request.args.get('code') ret = FileProcess.update( arg, use_discord_proxy=ModelSetting.get_bool('use_discord_proxy')) elif sub == 'image': from PIL import Image import requests # 2020-06-02 proxy 사용시 포스터처리 image_url = request.args.get('url') logger.debug(image_url) method = ModelSetting.get('javdb_landscape_poster') if method == '0': if FileProcess.Vars.proxies is None: return redirect(image_url) else: im = Image.open( requests.get(image_url, stream=True, proxies=FileProcess.Vars.proxies).raw) filename = os.path.join(path_data, 'tmp', 'rotate.jpg') im.save(filename) return send_file(filename, mimetype='image/jpeg') im = Image.open( requests.get(image_url, stream=True, proxies=FileProcess.Vars.proxies).raw) width, height = im.size logger.debug(width) logger.debug(height) if height > width * 1.5: return redirect(image_url) if method == '1': if width > height: im = im.rotate(-90, expand=True) elif method == '2': if width > height: im = im.rotate(90, expand=True) elif method == '3': new_height = int(width * 1.5) new_im = Image.new('RGB', (width, new_height)) new_im.paste(im, (0, int((new_height - height) / 2))) im = new_im filename = os.path.join(path_data, 'tmp', 'rotate.jpg') im.save(filename) return send_file(filename, mimetype='image/jpeg') elif sub == 'image_proxy': from PIL import Image import requests image_url = request.args.get('url') #logger.debug('image_url : %s', image_url) im = Image.open( requests.get(image_url, stream=True, verify=False, proxies=FileProcess.Vars.proxies).raw) filename = os.path.join(path_data, 'tmp', 'proxy.jpg') im.save(filename) return send_file(filename, mimetype='image/jpeg') elif sub == 'discord_proxy': from framework.common.notify import discord_proxy_image image_url = request.args.get('url') ret = discord_proxy_image( image_url, webhook_url=ModelSetting.get('discord_proxy_webhook_url')) #logger.debug(ret) #return redirect(ret) from PIL import Image import requests im = Image.open(requests.get(ret, stream=True, verify=False).raw) filename = os.path.join(path_data, 'tmp', 'proxy.jpg') im.save(filename) return send_file(filename, mimetype='image/jpeg') return jsonify(ret) except Exception as e: logger.debug('Exception:%s', e) logger.debug(traceback.format_exc())