def item_list(req): try: ret = {} page = 1 page_size = 30 job_id = '' search = '' if 'page' in req.form: page = int(req.form['page']) if 'search_word' in req.form: search = req.form['search_word'] query = db.session.query(ModelManamoaItem) if search != '': query = query.filter( ModelManamoaItem.title.like('%' + search + '%')) query = query.order_by(desc(ModelManamoaItem.id)) count = query.count() query = query.limit(page_size).offset((page - 1) * page_size) lists = query.all() ret['list'] = [item.as_dict() for item in lists] ret['paging'] = Util.get_paging_info(count, page, page_size) return ret except Exception, e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def web_list(req): try: ret = {} page = 1 page_size = ModelSetting.get_int('web_page_size') job_id = '' search = '' if 'page' in req.form: page = int(req.form['page']) if 'search_word' in req.form: search = req.form['search_word'] option = req.form['option'] order = req.form['order'] if 'order' in req.form else 'desc' query = ModelMovieItem.make_query(search=search, option=option, order=order) count = query.count() query = query.limit(page_size).offset((page-1)*page_size) logger.debug('ModelMovieItem count:%s', count) lists = query.all() ret['list'] = [item.as_dict() for item in lists] ret['paging'] = Util.get_paging_info(count, page, page_size) return ret except Exception, e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def queue_append(queue_list): try: logger.debug(queue_list) new_queue_list = [] for q in queue_list: src, tar = q.split('|') tmps = tar.split('/') if len(tmps) > 1: for i in range(1, len(tmps)): tmps[i] = Util.change_text_for_use_filename( tmps[i]).replace(' ', ' ').replace( ' ', ' ').rstrip('.').strip() new_queue_list.append('%s|%s/%s' % (src, tmps[0], '/'.join(tmps[1:]))) else: new_queue_list.append(q) logger.debug(new_queue_list) tmp = ModelSetting.get('gclone_queue_list') tmp += '\n' + '\n'.join(new_queue_list) ModelSetting.set('gclone_queue_list', tmp) socketio_callback('refresh_queue', ModelSetting.get('gclone_queue_list')) return LogicGclone.start() except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def to_dict(): try: from framework.util import Util return Util.db_list_to_dict(db.session.query(ModelSetting).all()) except Exception as e: logger.error('Exception:%s %s', e, key) logger.error(traceback.format_exc())
def web_list(req): try: ret = {} page = 1 page_size = 30 job_id = '' search = '' if 'page' in req.form: page = int(req.form['page']) if 'search_word' in req.form: search = req.form['search_word'] content_type = 'all' if 'type' in req.form: content_type = req.form['type'] query = ModelOffcloud2Cache.make_query(content_type=content_type, search=search) count = query.count() query = (query.order_by(desc( ModelOffcloud2Cache.id)).limit(page_size).offset( (page - 1) * page_size)) logger.debug('ModelOffcloud2Cache count:%s', count) lists = query.all() ret['list'] = [item.as_dict() for item in lists] ret['paging'] = Util.get_paging_info(count, page, page_size) return ret except Exception as e: logger.debug('Exception:%s', e) logger.debug(traceback.format_exc())
def plugin_load(): try: logger.debug('%s plugin_load', package_name) Logic.db_init() #if ModelSetting.query.filter_by(key='auto_start').first().value == 'True': # Logic.scheduler_start() # 편의를 위해 json 파일 생성 from plugin import plugin_info Util.save_from_dict_to_json( plugin_info, os.path.join(os.path.dirname(__file__), 'info.json')) LogicNormal.proxy_init() except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def web_list(req): try: ret = {} page = 1 page_size = 30 job_id = '' search = '' option = req.form['option'] if 'page' in req.form: page = int(req.form['page']) if 'search_word' in req.form: search = req.form['search_word'] order = req.form['order'] if 'order' in req.form else 'desc' match_type = req.form['option'] query = ModelItem.make_query(search=search, match_type=match_type, order=order) count = query.count() query = query.limit(page_size).offset((page - 1) * page_size) lists = query.all() ret['list'] = [item.as_dict() for item in lists] ret['paging'] = Util.get_paging_info(count, page, page_size) return ret except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def plugin_load(): try: logger.debug('%s plugin_load', package_name) Logic.db_init() if ModelSetting.get_bool('auto_start'): Logic.scheduler_start() # 편의를 위해 json 파일 생성 from .plugin import plugin_info Util.save_from_dict_to_json( plugin_info, os.path.join(os.path.dirname(__file__), 'info.json')) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def item_list(req): try: logger.debug(req.form) ret = {} page = 1 page_size = 30 search = '' if 'sheet_id' in req.form: sheet_id = req.form['sheet_id'] if 'page' in req.form: page = int(req.form['page']) if 'search_word' in req.form: search = req.form['search_word'] if 'option' in req.form: option = req.form['option'] if 'copied' in req.form: copied = req.form['copied'] order = req.form['order'] if 'order' in req.form else 'desc' query = ListModelItem.make_query(sheet_id=sheet_id, search=search, option=option, copied=copied, order=order) if query is None: return ret count = query.count() logger.debug(count) query = query.limit(page_size).offset((page - 1) * page_size) lists = query.all() #logger.debug(lists) ret['list'] = [item.as_dict() for item in lists] ret['paging'] = Util.get_paging_info(count, page, page_size) return ret except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def change_filename_censored_by_save_original(include_original_filename, original_filename, new_filename, option='0', original_filepath=None): ''' 원본파일명 보존 옵션에 의해 파일명을 변경한다. ''' try: if include_original_filename: new_name, new_ext = os.path.splitext(new_filename) part = None match = re.search(r'(?P<part>cd\d+)$', new_name) if match: # cd1 앞에가 같아야함. return new_filename part = match.group('part') new_name = new_name.replace(part, '') ori_name, ori_ext = os.path.splitext(original_filename) # 2019-07-30 ori_name = ori_name.replace('[', '(').replace(']', ')').strip() if part is None: if option == '0': return '%s [%s]%s' % (new_name, ori_name, new_ext) elif option == '1': return '%s [%s(%s)]%s' % (new_name, ori_name, os.stat(original_filepath).st_size, new_ext) elif option == '2': from framework.util import Util return '%s [%s(%s)]%s' % (new_name, ori_name, Util.sizeof_fmt(os.stat(original_filepath).st_size, suffix='B'), new_ext) return '%s [%s]%s' % (new_name, ori_name, new_ext) else: #안씀 return '%s [%s] %s%s' % (new_name, ori_name, part, new_ext) else: return new_filename except Exception as exception: logger.debug('Exception:%s', exception) logger.debug(traceback.format_exc())
def process_telegram_data(data): try: logger.debug('receive data') logger.debug(data) type_list = ModelSetting.get('cache_save_type_list').split('|') type_list = Util.get_list_except_empty(type_list) if len(type_list) == 0 or data['t'] in type_list: ret = ModelOffcloud2Cache.add(data) if ret is not None: logger.debug('Offcloud2 %s append' % ret.name) if ModelSetting.get_bool( 'cache_receive_info_send_telegram'): msg = '😉 Offcloud2 캐쉬 정보 수신\n' msg += 'Type : %s\n' % data['t'] msg += '%s\n' % data['n'] from system.model import ModelSetting as SystemModelSetting ddns = SystemModelSetting.get('ddns') url = '%s/%s/api/cache_download?id=%s' % ( ddns, package_name, ret.id) if SystemModelSetting.get_bool('auth_use_apikey'): url += '&apikey=%s' % SystemModelSetting.get( 'auth_apikey') msg += '➕ 리모트 다운로드 추가\n<%s>' % url ToolBaseNotify.send_message( msg, message_id='offcloud2_cache_receive') except Exception as e: logger.error(e) logger.error(traceback.format_exc())
def detail(sub): logger.debug('DETAIL %s %s', package_name, sub) if sub == 'setting': setting_list = db.session.query(ModelSetting).all() arg = Util.db_list_to_dict(setting_list) arg['scheduler'] = str(scheduler.is_include(package_name)) arg['is_running'] = str(scheduler.is_running(package_name)) arg['path_rclone'] = Logic.path_rclone arg['default_rclone_setting'] = Logic.default_rclone_setting return render_template('rclone_setting.html', sub=sub, arg=arg) elif sub == 'status': return render_template('rclone_status.html') elif sub == 'list': return render_template('rclone_list.html') elif sub == 'log': return render_template('log.html', package=package_name) elif sub == 'mount': return redirect('/%s/mount_setting' % package_name) elif sub == 'mount_setting': arg = {} arg['option'] = '--allow-other --fast-list --drive-skip-gdocs --poll-interval=1m --buffer-size=32M --vfs-read-chunk-size=32M --vfs-read-chunk-size-limit 2048M --vfs-cache-mode writes --dir-cache-time=1m --log-level INFO' #if platform.system() != 'Windows': # arg['option'] += ' --daemon' return render_template('%s_%s.html' % (package_name, sub), arg=arg) elif sub == 'serve_setting': arg = {} arg['option'] = '--user sjva --pass sjva --fast-list --drive-skip-gdocs --poll-interval=1m --buffer-size=32M --vfs-read-chunk-size=32M --vfs-read-chunk-size-limit 2048M --vfs-cache-mode writes --dir-cache-time=1m --log-level INFO' return render_template('%s_%s.html' % (package_name, sub), arg=arg) else: return blueprint.send_static_file(sub) return render_template('sample.html', title='%s - %s' % (package_name, sub))
def detail(sub): if sub == 'search': try: setting_list = db.session.query(ModelSetting).all() arg = Util.db_list_to_dict(setting_list) # arg['wavve_plugin'] = request.args.get('wavve_plugin') # arg['tving_plugin'] = request.args.get('tving_plugin') # arg['code'] = request.args.get('code') # return render_template('%s_search.html' % package_name, sub=sub, arg=arg) return render_template('%s_search.html' % (package_name), arg=arg) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) if sub == 'ratings': try: setting_list = db.session.query(ModelSetting).all() arg = Util.db_list_to_dict(setting_list) return render_template('%s_ratings.html' % (package_name), arg=arg) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) if sub == 'whitelist': try: wavve_programs = Logic.wavve_programs() tving_programs = Logic.tving_programs() return render_template('%s_whitelist.html' % (package_name), wavve_programs=wavve_programs, tving_programs=tving_programs) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) if sub == 'tving4k': try: setting_list = db.session.query(ModelSetting).all() arg = Util.db_list_to_dict(setting_list) return render_template('%s_tving4k.html' % (package_name), arg=arg) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) elif sub == 'log': return render_template('log.html', package=package_name) return render_template('sample.html', title='%s - %s' % (package_name, sub))
def get_title_info(code): try: if LogicAni24.current_data is not None and LogicAni24.current_data['code'] == code and LogicAni24.current_data['ret']: return LogicAni24.current_data url = '%s/ani_list/%s.html' % (ModelSetting.get('ani24_url'), code) data = LogicAni24.get_html(url) tree = html.fromstring(data) data = {} data['code'] = code data['ret'] = False tmp = tree.xpath('//h1[@class="ani_info_title_font_box"]')[0].text_content().strip().encode('utf8') match = re.compile(r'(?P<season>\d+)기').search(tmp) if match: data['season'] = match.group('season') else: data['season'] = '1' data['title'] = tmp.replace(data['season']+u'기', '').strip() data['title'] = Util.change_text_for_use_filename(data['title']).replace('OVA', '').strip() try: data['poster_url'] = 'https:' + tree.xpath('//div[@class="ani_info_left_box"]/img')[0].attrib['src'] data['detail'] = [] tmp = tree.xpath('//div[@class="ani_info_right_box"]/div') for t in tmp: detail = t.xpath('.//span') data['detail'].append({detail[0].text_content().strip():detail[-1].text_content().strip()}) except: data['detail'] = [{'정보없음':''}] data['poster_url'] = None tmp = tree.xpath('//span[@class="episode_count"]')[0].text_content().strip() match = re.compile(r'\d+').search(tmp) if match: data['episode_count'] = match.group(0) else: data['episode_count'] = '0' data['episode'] = [] tags = tree.xpath('//div[@class="ani_video_list"]/a') re1 = re.compile(r'ani_view\/(?P<code>\d+)\.html') for t in tags: entity = {} entity['code'] = re1.search(t.attrib['href']).group('code') data['episode'].append(entity) tmp = t.xpath('.//img')[0] entity['image'] = 'https:' + tmp.attrib['src'] tmp = t.xpath('.//div[2]/div') entity['title'] = tmp[0].text_content().strip().encode('utf8') entity['date'] = tmp[1].text_content().strip() entity['filename'] = LogicAni24.get_filename(data['title'], entity['title'],entity['date']) data['ret'] = True LogicAni24.current_data = data return data except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) data['log'] = str(e) return data
def check_option_size(item): try: flag_download = True option_min_size = ModelSetting.get_int('option_min_size') option_max_size = ModelSetting.get_int('option_max_size') if option_min_size != 0 and item.total_size < option_min_size: flag_download = False item.log += u'17.최소크기 - %s : %s\n' % (Util.sizeof_fmt(item.total_size, suffix='B'), flag_download) if option_max_size != 0 and item.total_size > option_max_size: flag_download = False item.log += u'17.최대크기 - %s : %s\n' % (Util.sizeof_fmt(item.total_size, suffix='B'), flag_download) if flag_download: item.log += u'17.크기 - %s : %s\n' % (Util.sizeof_fmt(item.total_size, suffix='B'), flag_download) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) return flag_download
def plugin_load(): try: Logic.db_init() from .plugin import plugin_info Util.save_from_dict_to_json( plugin_info, os.path.join(os.path.dirname(__file__), 'info.json')) def func(): LogicKlive.channel_load_from_site() t = threading.Thread(target=func, args=()) t.setDaemon(True) t.start() except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def detail(sub): if sub == 'setting': setting_list = db.session.query(ModelSetting).all() arg = Util.db_list_to_dict(setting_list) arg['scheduler'] = str(scheduler.is_include(package_name)) arg['is_running'] = str(scheduler.is_running(package_name)) return render_template('%s_%s.html' % (package_name, sub), arg=arg) elif sub in ['request', 'queue', 'list']: setting_list = db.session.query(ModelSetting).all() arg = Util.db_list_to_dict(setting_list) arg['current_code'] = LogicAni24.current_data[ 'code'] if LogicAni24.current_data is not None else None return render_template('%s_%s.html' % (package_name, sub), arg=arg) elif sub == 'log': return render_template('log.html', package=package_name) return render_template('sample.html', title='%s - %s' % (package_name, sub))
def plugin_load(): try: logger.debug('%s plugin_load', package_name) Logic.db_init() # youtube-dl 업데이트 youtube_dl = LogicNormal.get_youtube_dl_package(ModelSetting.get('youtube_dl_package')) logger.debug('%s upgrade' % youtube_dl) logger.debug(subprocess.check_output([sys.executable, '-m', 'pip', 'install', '--upgrade', youtube_dl], universal_newlines=True)) # 편의를 위해 json 파일 생성 from .plugin import plugin_info Util.save_from_dict_to_json(plugin_info, os.path.join(os.path.dirname(__file__), 'info.json')) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def to_dict(): try: ret = Util.db_list_to_dict(db.session.query(ModelSetting).all()) ret['package_name'] = package_name return ret except Exception as e: logger.error('Exception:%s %s', e, key) logger.error(traceback.format_exc())
def kill(): try: command = ['/app/data/custom/launcher_ivViewer/files/kill.sh'] if not os.path.exists(command[0]): return Util.execute_command(command) if Logic.current_process is not None and Logic.current_process.poll( ) is None: import psutil process = psutil.Process(Logic.current_process.pid) for proc in process.children(recursive=True): proc.kill() process.kill() Logic.current_process = None except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def to_dict(): try: from framework.util import Util arg = Util.db_list_to_dict(db.session.query(ModelSetting).all()) arg['package_name'] = package_name return arg except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc())
def initialize(): try: app.config['SQLALCHEMY_BINDS'][ P.package_name] = 'sqlite:///%s' % (os.path.join( path_data, 'db', '{package_name}.db'.format(package_name=P.package_name))) from framework.util import Util Util.save_from_dict_to_json( P.plugin_info, os.path.join(os.path.dirname(__file__), 'info.json')) from .logic_ani365 import LogicAni365 from .logic_aniplus import LogicAniplus P.module_list = [LogicAni365(P), LogicAniplus(P)] P.logic = Logic(P) default_route(P) except Exception as e: P.logger.error('Exception:%s', e) P.logger.error(traceback.format_exc())
def plugin_load(): try: Logic.db_init() if ModelSetting.get_bool('auto_start'): Logic.scheduler_start() else: #Logic.one_execute() pass from .plugin import plugin_info Util.save_from_dict_to_json(plugin_info, os.path.join(os.path.dirname(__file__), 'info.json')) # 리턴안되는 문제 발생 #from framework.common.util import SJVASupportControl #tmp = SJVASupportControl.epg_refresh() #logger.debug('EPG 결과 : %s', tmp) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def process_image_mode(cls, image_mode, image_url, proxy_url=None): #logger.debug('process_image_mode : %s %s', image_mode, image_url) if image_url is None: return ret = image_url if image_mode == '1': tmp = '{ddns}/metadata/api/image_proxy?url=' + py_urllib.quote_plus( image_url) if proxy_url is not None: tmp += '&proxy_url=' + py_urllib.quote_plus(proxy_url) ret = Util.make_apikey(tmp) elif image_mode == '2': tmp = '{ddns}/metadata/api/discord_proxy?url=' + py_urllib.quote_plus( image_url) ret = Util.make_apikey(tmp) elif image_mode == '3': # 고정 디스코드 URL. ret = cls.discord_proxy_image(image_url) elif image_mode == '4': #landscape to poster #logger.debug(image_url) ret = '{ddns}/metadata/normal/image_process.jpg?mode=landscape_to_poster&url=' + py_urllib.quote_plus( image_url) ret = ret.format(ddns=SystemModelSetting.get('ddns')) #ret = Util.make_apikey(tmp) elif image_mode == '5': #로컬에 포스터를 만들고 # image_url : 디스코드에 올라간 표지 url 임. from PIL import Image im = Image.open(requests.get(image_url, stream=True).raw) width, height = im.size filename = 'proxy_%s.jpg' % str(time.time()) filepath = os.path.join(path_data, 'tmp', filename) if width > height: left = width / 1.895734597 top = 0 right = width bottom = height poster = im.crop((left, top, right, bottom)) poster.save(filepath) else: im.save(filepath) #poster_url = '{ddns}/file/data/tmp/%s' % filename #poster_url = Util.make_apikey(poster_url) #logger.debug('poster_url : %s', poster_url) ret = cls.discord_proxy_image_localfile(filepath) return ret
def get_list(key): try: value = ModelSetting.get(key) values = [x.strip().strip() for x in value.replace('\n', '|').split('|')] values = Util.get_list_except_empty(values) return values except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) logger.error('Error Key:%s Value:%s', key, value)
def initialize(): try: app.config['SQLALCHEMY_BINDS'][P.package_name] = 'sqlite:///%s' % (os.path.join(path_data, 'db', '{package_name}.db'.format(package_name=P.package_name))) from framework.util import Util Util.save_from_dict_to_json(P.plugin_info, os.path.join(os.path.dirname(__file__), 'info.json')) ############################################### from .logic_receive_av import LogicReceiveAV P.module_list = [LogicReceiveAV(P)] if app.config['config']['is_server'] == False and app.config['config']['is_debug'] == False: del P.menu['sub'][1] #else: # from .logic_vod import LogicVod # P.module_list.append(LogicVod(P)) ############################################### P.logic = Logic(P) default_route(P) except Exception as e: P.logger.error('Exception:%s', e) P.logger.error(traceback.format_exc())
def detail(sub): if sub == 'setting': setting_list = db.session.query(ModelSetting).all() arg = Util.db_list_to_dict(setting_list) arg['status'] = str(Logic.current_process is not None) arg['is_installed'] = 'Installed' if Logic.is_installed() else 'Not Installed' return render_template('%s_%s.html' % (package_name, sub), arg=arg) elif sub == 'log': return render_template('log.html', package=package_name) return render_template('sample.html', title='%s - %s' % (package_name, sub))
def condition_check_filename(self, item): try: condition_quality = ModelSetting.get('condition_quality') if condition_quality != '' and condition_quality is not None: condition_qualitys = [x.strip().replace(' ', '').strip() for x in condition_quality.replace(',', '|').split('|')] condition_qualitys = Util.get_list_except_empty(condition_qualitys) if item.filename_quality not in condition_qualitys: item.download_status = 'False_not_match_condition_quality' item.log += u'\n화질 조건에 맞지 않음. 다운:Off. 조건:%s' % ','.join(condition_qualitys) return False condition_include_keyword = ModelSetting.get('condition_include_keyword') if condition_include_keyword != '' and condition_include_keyword is not None: condition_include_keywords = [x.strip().replace(' ', '').strip() for x in condition_include_keyword.replace('\n', '|').split('|')] condition_include_keywords = Util.get_list_except_empty(condition_include_keywords) download_flag = False for t in condition_include_keywords: if item.filename.find(t) != -1: item.log += u'\n단어 포함 조건 만족 : %s' % t download_flag = True break if download_flag == False: item.download_status = 'False_not_match_condition_include_keyword' item.log += u'\n단어 포함 조건에 맞지 않음. 다운:Off. 조건:%s' % ','.join(condition_include_keywords) return False condition_except_keyword = ModelSetting.get('condition_except_keyword') if condition_except_keyword != '' and condition_except_keyword is not None: condition_except_keywords = [x.strip().replace(' ', '').strip() for x in condition_except_keyword.replace('\n', '|').split('|')] condition_except_keywords = Util.get_list_except_empty(condition_except_keywords) for t in condition_except_keywords: if item.filename.find(t) != -1: item.download_status = 'False_match_condition_except_keyword' item.log += u'\n단어 제외 조건. 다운:Off. 조건:%s' % t return False item.log += u'\n단어 제외 조건 해당사항 없음.' return True except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) return True
def plugin_load(): try: if platform.system() != 'Windows': custom = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'bin') os.system("chmod 777 -R %s" % custom) logger.debug('%s plugin_load', package_name) # DB 초기화 Logic.db_init() # 편의를 위해 json 파일 생성 from plugin import plugin_info Util.save_from_dict_to_json(plugin_info, os.path.join(os.path.dirname(__file__), 'info.json')) # 자동시작 옵션이 있으면 보통 여기서 if ModelSetting.query.filter_by(key='auto_start').first().value == 'True': Logic.scheduler_start() except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def detail(sub): if sub == 'setting': setting_list = db.session.query(ModelSetting).all() arg = Util.db_list_to_dict(setting_list) arg['scheduler'] = str(scheduler.is_include(package_name)) arg['is_running'] = str(scheduler.is_running(package_name)) return render_template('%s_%s.html' % (package_name, sub), arg=arg) elif sub == 'log': return render_template('log.html', package=package_name) return render_template('sample.html', title='%s - %s' % (package_name, sub))