From dd32e8a04e5b88bf05396df37b5578f57c76b56e Mon Sep 17 00:00:00 2001 From: flaskfarm Date: Sat, 22 Oct 2022 23:10:07 +0900 Subject: [PATCH] update --- lib/framework/init_main.py | 10 ++++++-- lib/framework/init_plugin.py | 27 ++++++++++++-------- lib/framework/init_route.py | 10 +++++--- lib/framework/static/js/ff_ui1.js | 18 ++++++++++--- lib/framework/version.py | 2 +- lib/plugin/create_plugin.py | 2 +- lib/support/expand/ffmpeg.py | 42 +++++++++++++++++++++++++------ 7 files changed, 81 insertions(+), 30 deletions(-) diff --git a/lib/framework/init_main.py b/lib/framework/init_main.py index 50cb278..c1c8dc8 100644 --- a/lib/framework/init_main.py +++ b/lib/framework/init_main.py @@ -113,8 +113,14 @@ class Framework: if os.path.exists(_): plugins = os.listdir(_) - if self.config['path_dev'] != None and os.path.exists(self.config['path_dev']): - plugins += os.listdir(self.config['path_dev']) + if self.config['path_dev'] != None: + if type(self.config['path_dev']) == type(''): + plugin_path_list = [self.config['path_dev']] + elif type(self.config['path_dev']) == type([]): + plugin_path_list = self.config['path_dev'] + for __ in plugin_path_list: + if os.path.exists(__): + plugins += os.listdir(__) for package_name in plugins: db_path = os.path.join(self.config['path_data'], 'db', f'{package_name}.db') diff --git a/lib/framework/init_plugin.py b/lib/framework/init_plugin.py index 6ef627f..7501eaf 100644 --- a/lib/framework/init_plugin.py +++ b/lib/framework/init_plugin.py @@ -46,16 +46,23 @@ class PluginManager: try: #plugin_path = F.SystemModelSetting.get('plugin_dev_path') plugin_path = F.config['path_dev'] - if plugin_path != None and plugin_path != '': - if os.path.exists(plugin_path): - sys.path.insert(0, plugin_path) - tmps = os.listdir(plugin_path) - add_plugin_list = [] - for t in tmps: - if not t.startswith('_') and os.path.isdir(os.path.join(plugin_path, t)): - add_plugin_list.append(t) - cls.all_package_list[t] = {'pos':'dev', 'path':os.path.join(plugin_path, t), 'loading':True} - plugins = plugins + add_plugin_list + + if type(plugin_path) == type(''): + plugin_path_list = [plugin_path] + elif type(plugin_path) == type([]): + plugin_path_list = plugin_path + + for __ in plugin_path_list: + if __ != None and __ != '': + if os.path.exists(__): + sys.path.insert(0, __) + tmps = os.listdir(__) + add_plugin_list = [] + for t in tmps: + if not t.startswith('_') and os.path.isdir(os.path.join(__, t)): + add_plugin_list.append(t) + cls.all_package_list[t] = {'pos':'dev', 'path':os.path.join(__, t), 'loading':True} + plugins = plugins + add_plugin_list except Exception as exception: F.logger.error('Exception:%s', exception) F.logger.error(traceback.format_exc()) diff --git a/lib/framework/init_route.py b/lib/framework/init_route.py index ac4cf5c..9e25526 100644 --- a/lib/framework/init_route.py +++ b/lib/framework/init_route.py @@ -118,10 +118,12 @@ def videojs(): - - - - +@F.app.route("/headers", methods=['GET', 'POST']) +def headers(): + from support import d + F.logger.info(d(request.headers)) + return jsonify(d(request.headers)) + # 3.10에서 이거 필수 @F.socketio.on('connect', namespace=f'/framework') diff --git a/lib/framework/static/js/ff_ui1.js b/lib/framework/static/js/ff_ui1.js index 771c95e..eb2006d 100644 --- a/lib/framework/static/js/ff_ui1.js +++ b/lib/framework/static/js/ff_ui1.js @@ -57,10 +57,6 @@ function j_row_end() { return str; } - - - - function j_hr(margin='5') { var str = '
'; return str; @@ -73,6 +69,20 @@ function j_hr_black() { +// 한줄 왼쪽 +function j_row_info(left, right, l=2, r=8) { + var str =' \ +
\ +
\ +
\ + '+ left +' \ +
\ +
\ + '+right +' \ +
\ +
'; + return str; +} diff --git a/lib/framework/version.py b/lib/framework/version.py index 1abd467..19ed8ec 100644 --- a/lib/framework/version.py +++ b/lib/framework/version.py @@ -1 +1 @@ -VERSION="4.0.28" \ No newline at end of file +VERSION="4.0.29" \ No newline at end of file diff --git a/lib/plugin/create_plugin.py b/lib/plugin/create_plugin.py index 088f5fa..0b840e6 100644 --- a/lib/plugin/create_plugin.py +++ b/lib/plugin/create_plugin.py @@ -64,7 +64,7 @@ class PluginBase(object): self.module_list.append(mod_ins) except Exception as e: - F.logger.error(f'Exception:{str(e)}') + F.logger.error(f'[{self.package_name}] Exception:{str(e)}') F.logger.error(traceback.format_exc()) diff --git a/lib/support/expand/ffmpeg.py b/lib/support/expand/ffmpeg.py index 01c854e..5b0a1cb 100644 --- a/lib/support/expand/ffmpeg.py +++ b/lib/support/expand/ffmpeg.py @@ -5,10 +5,11 @@ import re import shutil import subprocess import threading +import time import traceback from datetime import datetime -from support import SupportSubprocess, SupportUtil, logger +from support import SupportFile, SupportSubprocess, SupportUtil, logger class SupportFfmpeg(object): @@ -92,6 +93,7 @@ class SupportFfmpeg(object): try: self.status = SupportFfmpeg.Status.USER_STOP self.kill() + logger.warning('stop') except Exception as e: logger.error(f'Exception:{str(e)}') logger.error(traceback.format_exc()) @@ -111,22 +113,29 @@ class SupportFfmpeg(object): def thread_fuction(self): try: + header_count = 0 if self.proxy is None: if self.headers is None: command = [self.__ffmpeg_path, '-y', '-i', self.url, '-c', 'copy', '-bsf:a', 'aac_adtstoasc'] else: headers_command = [] + tmp = "" for key, value in self.headers.items(): if key.lower() == 'user-agent': headers_command.append('-user_agent') - headers_command.append(value) + headers_command.append(f"{value}") pass else: - headers_command.append('-headers') + #headers_command.append('-headers') if platform.system() == 'Windows': - headers_command.append('\'%s:%s\''%(key,value)) + tmp += f'{key}:{value}\r\n' + header_count += 1 else: - headers_command.append(f'{key}:{value}') + #tmp.append(f'{key}:{value}') + tmp += f'{key}:{value}\r\n' + if len(tmp) > 0: + headers_command.append('-headers') + headers_command.append(f'{tmp}') command = [self.__ffmpeg_path, '-y'] + headers_command + ['-i', self.url, '-c', 'copy', '-bsf:a', 'aac_adtstoasc'] else: command = [self.__ffmpeg_path, '-y', '-http_proxy', self.proxy, '-i', self.url, '-c', 'copy', '-bsf:a', 'aac_adtstoasc'] @@ -140,8 +149,9 @@ class SupportFfmpeg(object): else: command.append(self.temp_fullpath) + try: - logger.debug(' '.join(command)) + #logger.debug(' '.join(command)) if os.path.exists(self.temp_fullpath): for f in SupportFfmpeg.__instance_list: if f.__idx != self.__idx and f.temp_fullpath == self.temp_fullpath and f.status in [SupportFfmpeg.Status.DOWNLOADING, SupportFfmpeg.Status.READY]: @@ -149,8 +159,24 @@ class SupportFfmpeg(object): return except: pass - logger.error(' '.join(command)) + #logger.error(' '.join(command)) command = SupportSubprocess.command_for_windows(command) + + if platform.system() == 'Windows' and header_count > 1: + if os.environ.get('FF'): + from framework import F + batfilepath = os.path.join(F.config['path_data'], 'tmp', f"{time.time()}.bat") + else: + batfilepath = f"{time.time()}.bat" + tmp = command.replace('\r\n', '!CRLF!') + text = f"""setlocal enabledelayedexpansion +SET CRLF=^ + + +{tmp}""" + SupportFile.write_file(batfilepath, text) + command = batfilepath + self.process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, encoding='utf8') self.status = SupportFfmpeg.Status.READY @@ -320,7 +346,7 @@ class SupportFfmpeg(object): def send_to_listener(self, **arg): if self.total_callback_function != None: self.total_callback_function(**arg) - if self.callback_function is not None: + if self.callback_function is not None and self.callback_function != self.total_callback_function: arg['callback_id'] = self.callback_id self.callback_function(**arg)