diff --git a/lib/_ffmpeg_queue.py b/lib/_ffmpeg_queue.py deleted file mode 100644 index d19db78..0000000 --- a/lib/_ffmpeg_queue.py +++ /dev/null @@ -1,368 +0,0 @@ -import abc -import os -import queue -import threading -import time -import traceback -from datetime import datetime - -import requests -# from flaskfarm.lib.plugin import get_model_setting -from flaskfarm.lib.support.expand.ffmpeg import SupportFfmpeg -# from flaskfarm.lib.system.setup import SystemModelSetting -from flaskfarm.lib.tool import ToolUtil -# from flaskfarm.lib.system.setup import P as SM -# from flaskfarm.lib.system.mod_setting import ModuleSetting as SM - -from ..setup import * - - -class FfmpegQueueEntity(abc.ABCMeta('ABC', (object,), {'__slots__': ()})): - - def __init__(self, P, module_logic, info): - self.P = P - # SupportFfmpeg.initialize() - self.module_logic = module_logic - self.entity_id = -1 # FfmpegQueueEntity.static_index - self.info = info - self.url = None - self.ffmpeg_status = -1 - self.ffmpeg_status_kor = u'대기중' - self.ffmpeg_percent = 0 - self.ffmpeg_arg = None - self.cancel = False - self.created_time = datetime.now().strftime('%m-%d %H:%M:%S') - self.savepath = None - self.filename = None - self.filepath = None - self.quality = None - self.headers = None - # FfmpegQueueEntity.static_index += 1 - # FfmpegQueueEntity.entity_list.append(self) - - def get_video_url(self): - return self.url - - def get_video_filepath(self): - return self.filepath - - @abc.abstractmethod - def refresh_status(self): - pass - - @abc.abstractmethod - def info_dict(self, tmp): - pass - - def download_completed(self): - pass - - def as_dict(self): - tmp = {} - tmp['entity_id'] = self.entity_id - tmp['url'] = self.url - tmp['ffmpeg_status'] = self.ffmpeg_status - tmp['ffmpeg_status_kor'] = self.ffmpeg_status_kor - tmp['ffmpeg_percent'] = self.ffmpeg_percent - tmp['ffmpeg_arg'] = self.ffmpeg_arg - tmp['cancel'] = self.cancel - tmp['created_time'] = self.created_time # .strftime('%m-%d %H:%M:%S') - tmp['savepath'] = self.savepath - tmp['filename'] = self.filename - tmp['filepath'] = self.filepath - tmp['quality'] = self.quality - # tmp['current_speed'] = self.ffmpeg_arg['current_speed'] if self.ffmpeg_arg is not None else '' - tmp = self.info_dict(tmp) - return tmp - - -class FfmpegQueue(object): - - def __init__(self, P, max_ffmpeg_count): - - self.P = P - self.static_index = 1 - self.entity_list = [] - self.current_ffmpeg_count = 0 - self.download_queue = None - self.download_thread = None - self.max_ffmpeg_count = max_ffmpeg_count - if self.max_ffmpeg_count is None or self.max_ffmpeg_count == '': - self.max_ffmpeg_count = 1 - - def queue_start(self): - try: - if self.download_queue is None: - self.download_queue = queue.Queue() - if self.download_thread is None: - self.download_thread = threading.Thread(target=self.download_thread_function, args=()) - self.download_thread.daemon = True - self.download_thread.start() - except Exception as exception: - self.P.logger.error('Exception:%s', exception) - self.P.logger.error(traceback.format_exc()) - - def download_thread_function(self): - while True: - try: - while True: - try: - if self.current_ffmpeg_count < self.max_ffmpeg_count: - break - time.sleep(5) - except Exception as exception: - self.P.logger.error('Exception:%s', exception) - self.P.logger.error(traceback.format_exc()) - self.P.logger.error('current_ffmpeg_count : %s', self.current_ffmpeg_count) - self.P.logger.error('max_ffmpeg_count : %s', self.max_ffmpeg_count) - break - entity = self.download_queue.get() - if entity.cancel: - continue - - # from .logic_ani24 import LogicAni24 - # entity.url = LogicAni24.get_video_url(entity.info['code']) - video_url = entity.get_video_url() - if video_url is None: - entity.ffmpeg_status_kor = 'URL실패' - entity.refresh_status() - # plugin.socketio_list_refresh() - continue - - # import ffmpeg - - # max_pf_count = 0 - # save_path = ModelSetting.get('download_path') - # if ModelSetting.get('auto_make_folder') == 'True': - # program_path = os.path.join(save_path, entity.info['filename'].split('.')[0]) - # save_path = program_path - # try: - # if not os.path.exists(save_path): - # os.makedirs(save_path) - # except: - # logger.debug('program path make fail!!') - # 파일 존재여부 체크 - print(entity.info) - filepath = entity.get_video_filepath() - P.logger.debug(f'filepath:: {filepath}') - if os.path.exists(filepath): - entity.ffmpeg_status_kor = '파일 있음' - entity.ffmpeg_percent = 100 - entity.refresh_status() - # plugin.socketio_list_refresh() - continue - dirname = os.path.dirname(filepath) - # filename = os.path.f - if not os.path.exists(dirname): - os.makedirs(dirname) - # f = ffmpeg.Ffmpeg(video_url, os.path.basename(filepath), plugin_id=entity.entity_id, listener=self.ffmpeg_listener, call_plugin=self.P.package_name, save_path=dirname, headers=entity.headers) - # print(filepath) - # print(os.path.basename(filepath)) - # print(dirname) - # aa_sm = get_model_setting("system", P.logger) - P.logger.debug(P) - # P.logger.debug(P.system_setting.get("port")) - - ffmpeg = SupportFfmpeg(video_url, os.path.basename(str(filepath)), - callback_function=self.callback_function, - max_pf_count=0, save_path=ToolUtil.make_path(dirname), timeout_minute=60, - ) - # - ffmpeg.start() - self.current_ffmpeg_count += 1 - self.download_queue.task_done() - - except Exception as exception: - self.P.logger.error('Exception:%s', exception) - self.P.logger.error(traceback.format_exc()) - - def callback_function(self, **args): - refresh_type = None - if args['type'] == 'status_change': - if args['status'] == SupportFfmpeg.Status.DOWNLOADING: - refresh_type = 'status_change' - elif args['status'] == SupportFfmpeg.Status.COMPLETED: - refresh_type = 'status_change' - elif args['status'] == SupportFfmpeg.Status.READY: - data = {'type': 'info', - 'msg': '다운로드중 Duration(%s)' % args['data']['duration_str'] + '
' + args['data'][ - 'save_fullpath'], 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'add' - elif args['type'] == 'last': - if args['status'] == SupportFfmpeg.Status.WRONG_URL: - data = {'type': 'warning', 'msg': '잘못된 URL입니다'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'add' - elif args['status'] == SupportFfmpeg.Status.WRONG_DIRECTORY: - data = {'type': 'warning', 'msg': '잘못된 디렉토리입니다.
' + args['data']['save_fullpath']} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'add' - elif args['status'] == SupportFfmpeg.Status.ERROR or args['status'] == SupportFfmpeg.Status.EXCEPTION: - data = {'type': 'warning', 'msg': '다운로드 시작 실패.
' + args['data']['save_fullpath']} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'add' - elif args['status'] == SupportFfmpeg.Status.USER_STOP: - data = {'type': 'warning', 'msg': '다운로드가 중지 되었습니다.
' + args['data']['save_fullpath'], - 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'last' - elif args['status'] == SupportFfmpeg.Status.COMPLETED: - data = {'type': 'success', 'msg': '다운로드가 완료 되었습니다.
' + args['data']['save_fullpath'], - 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'last' - elif args['status'] == SupportFfmpeg.Status.TIME_OVER: - data = {'type': 'warning', 'msg': '시간초과로 중단 되었습니다.
' + args['data']['save_fullpath'], - 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'last' - elif args['status'] == SupportFfmpeg.Status.PF_STOP: - data = {'type': 'warning', 'msg': 'PF초과로 중단 되었습니다.
' + args['data']['save_fullpath'], - 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'last' - elif args['status'] == SupportFfmpeg.Status.FORCE_STOP: - data = {'type': 'warning', 'msg': '강제 중단 되었습니다.
' + args['data']['save_fullpath'], - 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'last' - elif args['status'] == SupportFfmpeg.Status.HTTP_FORBIDDEN: - data = {'type': 'warning', 'msg': '403에러로 중단 되었습니다.
' + args['data']['save_fullpath'], - 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'last' - elif args['status'] == SupportFfmpeg.Status.ALREADY_DOWNLOADING: - data = {'type': 'warning', 'msg': '임시파일폴더에 파일이 있습니다.
' + args['data']['temp_fullpath'], - 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'last' - elif args['type'] == 'normal': - if args['status'] == SupportFfmpeg.Status.DOWNLOADING: - refresh_type = 'status' - # P.logger.info(refresh_type) - self.socketio_callback(refresh_type, args['data']) - - def ffmpeg_listener(self, **arg): - import ffmpeg - entity = self.get_entity_by_entity_id(arg['plugin_id']) - if entity is None: - return - if arg['type'] == 'status_change': - if arg['status'] == ffmpeg.Status.DOWNLOADING: - pass - elif arg['status'] == ffmpeg.Status.COMPLETED: - entity.donwload_completed() - elif arg['status'] == ffmpeg.Status.READY: - pass - elif arg['type'] == 'last': - self.current_ffmpeg_count += -1 - elif arg['type'] == 'log': - pass - elif arg['type'] == 'normal': - pass - - entity.ffmpeg_arg = arg - entity.ffmpeg_status = int(arg['status']) - entity.ffmpeg_status_kor = str(arg['status']) - entity.ffmpeg_percent = arg['data']['percent'] - entity.ffmpeg_arg['status'] = str(arg['status']) - # self.P.logger.debug(arg) - # import plugin - # arg['status'] = str(arg['status']) - # plugin.socketio_callback('status', arg) - entity.refresh_status() - - # FfmpegQueueEntity.static_index += 1 - # FfmpegQueueEntity.entity_list.append(self) - - def add_queue(self, entity): - try: - # entity = QueueEntity.create(info) - # if entity is not None: - # LogicQueue.download_queue.put(entity) - # return True - entity.entity_id = self.static_index - self.static_index += 1 - self.entity_list.append(entity) - self.download_queue.put(entity) - return True - except Exception as exception: - self.P.logger.error('Exception:%s', exception) - self.P.logger.error(traceback.format_exc()) - return False - - def set_max_ffmpeg_count(self, max_ffmpeg_count): - self.max_ffmpeg_count = max_ffmpeg_count - - def get_max_ffmpeg_count(self): - return self.max_ffmpeg_count - - def command(self, cmd, entity_id): - self.P.logger.debug('command :%s %s', cmd, entity_id) - ret = {} - try: - if cmd == 'cancel': - self.P.logger.debug('command :%s %s', cmd, entity_id) - entity = self.get_entity_by_entity_id(entity_id) - if entity is not None: - if entity.ffmpeg_status == -1: - entity.cancel = True - entity.ffmpeg_status_kor = "취소" - # entity.refresh_status() - ret['ret'] = 'refresh' - elif entity.ffmpeg_status != 5: - ret['ret'] = 'notify' - ret['log'] = '다운로드중 상태가 아닙니다.' - else: - idx = entity.ffmpeg_arg['data']['idx'] - import ffmpeg - ffmpeg.Ffmpeg.stop_by_idx(idx) - entity.refresh_status() - ret['ret'] = 'refresh' - elif cmd == 'reset': - if self.download_queue is not None: - with self.download_queue.mutex: - self.download_queue.queue.clear() - for _ in self.entity_list: - if _.ffmpeg_status == 5: - import ffmpeg - idx = _.ffmpeg_arg['data']['idx'] - ffmpeg.Ffmpeg.stop_by_idx(idx) - self.entity_list = [] - ret['ret'] = 'refresh' - elif cmd == 'delete_completed': - new_list = [] - for _ in self.entity_list: - if _.ffmpeg_status_kor in [u'파일 있음', u'취소', u'사용자중지']: - continue - if _.ffmpeg_status != 7: - new_list.append(_) - self.entity_list = new_list - ret['ret'] = 'refresh' - elif cmd == 'remove': - new_list = [] - for _ in self.entity_list: - if _.entity_id == entity_id: - continue - new_list.append(_) - self.entity_list = new_list - ret['ret'] = 'refresh' - return ret - except Exception as exception: - self.P.logger.error('Exception:%s', exception) - self.P.logger.error(traceback.format_exc()) - - def get_entity_by_entity_id(self, entity_id): - for _ in self.entity_list: - if _.entity_id == entity_id: - return _ - return None - - def get_entity_list(self): - ret = [] - P.logger.debug(self) - for x in self.entity_list: - tmp = x.as_dict() - ret.append(tmp) - return ret diff --git a/lib/ffmpeg_queue_v1.py b/lib/ffmpeg_queue_v1.py index 6a571aa..a384a11 100644 --- a/lib/ffmpeg_queue_v1.py +++ b/lib/ffmpeg_queue_v1.py @@ -23,7 +23,9 @@ class FfmpegQueueEntity(abc.ABCMeta('ABC', (object,), {'__slots__': ()})): self.P = P # SupportFfmpeg.initialize() self.module_logic = module_logic - self.entity_id = -1 # FfmpegQueueEntity.static_index + self.entity_id = -1 + self.entity_list = [] + # FfmpegQueueEntity.static_index self.info = info self.url = None self.ffmpeg_status = -1 @@ -97,8 +99,8 @@ class FfmpegQueue(object): if self.download_thread is None: self.download_thread = threading.Thread(target=self.download_thread_function, args=()) self.download_thread.daemon = True - # todo: - # self.download_thread.start() + # todo: 동작 방식 고찰 + self.download_thread.start() except Exception as exception: self.P.logger.error(f'Exception: {exception}') self.P.logger.error(traceback.format_exc()) @@ -170,7 +172,7 @@ class FfmpegQueue(object): ) # # todo: 임시로 start() 중지 - # ffmpeg.start() + ffmpeg.start() self.current_ffmpeg_count += 1 self.download_queue.task_done() @@ -178,72 +180,72 @@ class FfmpegQueue(object): self.P.logger.error('Exception:%s', exception) self.P.logger.error(traceback.format_exc()) - def callback_function(self, **args): - refresh_type = None - if args['type'] == 'status_change': - if args['status'] == SupportFfmpeg.Status.DOWNLOADING: - refresh_type = 'status_change' - elif args['status'] == SupportFfmpeg.Status.COMPLETED: - refresh_type = 'status_change' - elif args['status'] == SupportFfmpeg.Status.READY: - data = {'type': 'info', - 'msg': '다운로드중 Duration(%s)' % args['data']['duration_str'] + '
' + args['data'][ - 'save_fullpath'], 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'add' - elif args['type'] == 'last': - if args['status'] == SupportFfmpeg.Status.WRONG_URL: - data = {'type': 'warning', 'msg': '잘못된 URL입니다'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'add' - elif args['status'] == SupportFfmpeg.Status.WRONG_DIRECTORY: - data = {'type': 'warning', 'msg': '잘못된 디렉토리입니다.
' + args['data']['save_fullpath']} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'add' - elif args['status'] == SupportFfmpeg.Status.ERROR or args['status'] == SupportFfmpeg.Status.EXCEPTION: - data = {'type': 'warning', 'msg': '다운로드 시작 실패.
' + args['data']['save_fullpath']} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'add' - elif args['status'] == SupportFfmpeg.Status.USER_STOP: - data = {'type': 'warning', 'msg': '다운로드가 중지 되었습니다.
' + args['data']['save_fullpath'], - 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'last' - elif args['status'] == SupportFfmpeg.Status.COMPLETED: - data = {'type': 'success', 'msg': '다운로드가 완료 되었습니다.
' + args['data']['save_fullpath'], - 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'last' - elif args['status'] == SupportFfmpeg.Status.TIME_OVER: - data = {'type': 'warning', 'msg': '시간초과로 중단 되었습니다.
' + args['data']['save_fullpath'], - 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'last' - elif args['status'] == SupportFfmpeg.Status.PF_STOP: - data = {'type': 'warning', 'msg': 'PF초과로 중단 되었습니다.
' + args['data']['save_fullpath'], - 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'last' - elif args['status'] == SupportFfmpeg.Status.FORCE_STOP: - data = {'type': 'warning', 'msg': '강제 중단 되었습니다.
' + args['data']['save_fullpath'], - 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'last' - elif args['status'] == SupportFfmpeg.Status.HTTP_FORBIDDEN: - data = {'type': 'warning', 'msg': '403에러로 중단 되었습니다.
' + args['data']['save_fullpath'], - 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'last' - elif args['status'] == SupportFfmpeg.Status.ALREADY_DOWNLOADING: - data = {'type': 'warning', 'msg': '임시파일폴더에 파일이 있습니다.
' + args['data']['temp_fullpath'], - 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) - refresh_type = 'last' - elif args['type'] == 'normal': - if args['status'] == SupportFfmpeg.Status.DOWNLOADING: - refresh_type = 'status' - # P.logger.info(refresh_type) - self.socketio_callback(refresh_type, args['data']) + # def callback_function(self, **args): + # refresh_type = None + # if args['type'] == 'status_change': + # if args['status'] == SupportFfmpeg.Status.DOWNLOADING: + # refresh_type = 'status_change' + # elif args['status'] == SupportFfmpeg.Status.COMPLETED: + # refresh_type = 'status_change' + # elif args['status'] == SupportFfmpeg.Status.READY: + # data = {'type': 'info', + # 'msg': '다운로드중 Duration(%s)' % args['data']['duration_str'] + '
' + args['data'][ + # 'save_fullpath'], 'url': '/ffmpeg/download/list'} + # socketio.emit("notify", data, namespace='/framework', broadcast=True) + # refresh_type = 'add' + # elif args['type'] == 'last': + # if args['status'] == SupportFfmpeg.Status.WRONG_URL: + # data = {'type': 'warning', 'msg': '잘못된 URL입니다'} + # socketio.emit("notify", data, namespace='/framework', broadcast=True) + # refresh_type = 'add' + # elif args['status'] == SupportFfmpeg.Status.WRONG_DIRECTORY: + # data = {'type': 'warning', 'msg': '잘못된 디렉토리입니다.
' + args['data']['save_fullpath']} + # socketio.emit("notify", data, namespace='/framework', broadcast=True) + # refresh_type = 'add' + # elif args['status'] == SupportFfmpeg.Status.ERROR or args['status'] == SupportFfmpeg.Status.EXCEPTION: + # data = {'type': 'warning', 'msg': '다운로드 시작 실패.
' + args['data']['save_fullpath']} + # socketio.emit("notify", data, namespace='/framework', broadcast=True) + # refresh_type = 'add' + # elif args['status'] == SupportFfmpeg.Status.USER_STOP: + # data = {'type': 'warning', 'msg': '다운로드가 중지 되었습니다.
' + args['data']['save_fullpath'], + # 'url': '/ffmpeg/download/list'} + # socketio.emit("notify", data, namespace='/framework', broadcast=True) + # refresh_type = 'last' + # elif args['status'] == SupportFfmpeg.Status.COMPLETED: + # data = {'type': 'success', 'msg': '다운로드가 완료 되었습니다.
' + args['data']['save_fullpath'], + # 'url': '/ffmpeg/download/list'} + # socketio.emit("notify", data, namespace='/framework', broadcast=True) + # refresh_type = 'last' + # elif args['status'] == SupportFfmpeg.Status.TIME_OVER: + # data = {'type': 'warning', 'msg': '시간초과로 중단 되었습니다.
' + args['data']['save_fullpath'], + # 'url': '/ffmpeg/download/list'} + # socketio.emit("notify", data, namespace='/framework', broadcast=True) + # refresh_type = 'last' + # elif args['status'] == SupportFfmpeg.Status.PF_STOP: + # data = {'type': 'warning', 'msg': 'PF초과로 중단 되었습니다.
' + args['data']['save_fullpath'], + # 'url': '/ffmpeg/download/list'} + # socketio.emit("notify", data, namespace='/framework', broadcast=True) + # refresh_type = 'last' + # elif args['status'] == SupportFfmpeg.Status.FORCE_STOP: + # data = {'type': 'warning', 'msg': '강제 중단 되었습니다.
' + args['data']['save_fullpath'], + # 'url': '/ffmpeg/download/list'} + # socketio.emit("notify", data, namespace='/framework', broadcast=True) + # refresh_type = 'last' + # elif args['status'] == SupportFfmpeg.Status.HTTP_FORBIDDEN: + # data = {'type': 'warning', 'msg': '403에러로 중단 되었습니다.
' + args['data']['save_fullpath'], + # 'url': '/ffmpeg/download/list'} + # socketio.emit("notify", data, namespace='/framework', broadcast=True) + # refresh_type = 'last' + # elif args['status'] == SupportFfmpeg.Status.ALREADY_DOWNLOADING: + # data = {'type': 'warning', 'msg': '임시파일폴더에 파일이 있습니다.
' + args['data']['temp_fullpath'], + # 'url': '/ffmpeg/download/list'} + # socketio.emit("notify", data, namespace='/framework', broadcast=True) + # refresh_type = 'last' + # elif args['type'] == 'normal': + # if args['status'] == SupportFfmpeg.Status.DOWNLOADING: + # refresh_type = 'status' + # # P.logger.info(refresh_type) + # self.socketio_callback(refresh_type, args['data']) def ffmpeg_listener(self, **arg): import ffmpeg diff --git a/mod_anilife.py b/mod_anilife.py index 3c5ca66..aebc096 100644 --- a/mod_anilife.py +++ b/mod_anilife.py @@ -49,7 +49,8 @@ from framework import F from plugin import ( PluginModuleBase ) -from .lib.ffmpeg_queue import FfmpegQueueEntity, FfmpegQueue +from .lib.ffmpeg_queue_v1 import FfmpegQueueEntity, FfmpegQueue +from support.expand.ffmpeg import SupportFfmpeg from .lib.crawler import Crawler # from tool_base import d @@ -547,6 +548,40 @@ class LogicAniLife(PluginModuleBase): P.logger.error("Exception:%s", e) P.logger.error(traceback.format_exc()) + + def process_command(self, command, arg1, arg2, arg3, req): + ret = {'ret': 'success'} + logger.debug('queue_list') + if command == 'queue_list': + logger.debug(f"self.queue.get_entity_list():: {self.queue.get_entity_list()}") + ret = [x for x in self.queue.get_entity_list()] + + return ret + elif command == 'download_program': + _pass = arg2 + db_item = ModelOhli24Program.get(arg1) + if _pass == 'false' and db_item != None: + ret['ret'] = 'warning' + ret['msg'] = '이미 DB에 있는 항목 입니다.' + elif _pass == 'true' and db_item != None and ModelOhli24Program.get_by_id_in_queue(db_item.id) != None: + ret['ret'] = 'warning' + ret['msg'] = '이미 큐에 있는 항목 입니다.' + else: + if db_item == None: + db_item = ModelOhli24Program(arg1, self.get_episode(arg1)) + db_item.save() + db_item.init_for_queue() + self.download_queue.put(db_item) + ret['msg'] = '다운로드를 추가 하였습니다.' + + elif command == 'list': + ret = [] + for ins in SupportFfmpeg.get_list(): + ret.append(ins.get_data()) + + return jsonify(ret) + + @staticmethod def add_whitelist(*args): ret = {} @@ -650,7 +685,7 @@ class LogicAniLife(PluginModuleBase): import json post_data = { "url": url, - "headless": True, + "headless": False, "engine": "webkit" } payload = json.dumps(post_data) @@ -830,8 +865,9 @@ class LogicAniLife(PluginModuleBase): import json post_data = { "url": url, - "headless": True, - "engine": "chromium" + "headless": False, + "engine": "chrome", + "reload": True, } payload = json.dumps(post_data) logger.debug(payload) @@ -877,6 +913,7 @@ class LogicAniLife(PluginModuleBase): # real_url = LogicAniLife.get_real_link(url=entity["link"]) entity["code"] = entity["link"].split("/")[-1] + entity["epx"] = item.xpath(".//span[@class='epx']/text()")[0].strip() entity["title"] = item.xpath(".//div[@class='tt']/text()")[0].strip() entity["image_link"] = item.xpath(".//div[@class='limit']/img/@src")[ 0 @@ -986,14 +1023,15 @@ class AniLifeQueueEntity(FfmpegQueueEntity): logger.info(f"self.info:::> {self.info}") referer = "https://anilife.live/g/l?id=13fd4d28-ff18-4764-9968-7e7ea7347c51" - referer = LogicAniLife.episode_url + # text = requests.get(url, headers=headers).text # text = LogicAniLife.get_html_seleniumwire(url, referer=referer, wired=True) # https://anilife.live/ani/provider/10f60832-20d1-4918-be62-0f508bf5460c referer_url = ( - "https://anilife.live/g/l?id=d4be1e0e-301b-403b-be1b-cf19f3ccfd23" + "https://anilife.live/g/l?id=b012a355-a997-449a-ae2b-408a81a9b464" ) + referer_url = LogicAniLife.episode_url logger.debug(f"LogicAniLife.episode_url:: {LogicAniLife.episode_url}") @@ -1017,14 +1055,16 @@ class AniLifeQueueEntity(FfmpegQueueEntity): # )) # loop = asyncio.new_event_loop() - + logger.debug(url, referer_url) import json post_data = { "url": url, - "headless": True, - "engine": "chromium", + "headless": False, + # "engine": "chromium", + "engine": "webkit", "referer": referer_url, - "stealth": "False" + "stealth": "False", + "reload": True, } payload = json.dumps(post_data) logger.debug(payload) @@ -1114,14 +1154,14 @@ class AniLifeQueueEntity(FfmpegQueueEntity): # vod_1080p_url = asyncio.run( # LogicAniLife.get_vod_url(jawcloud_url, headless=True) # ) - vod_1080p_url = LogicAniLife.get_vod_url_v2(jawcloud_url, headless=True) + vod_1080p_url = LogicAniLife.get_vod_url_v2(jawcloud_url, headless=False) print(f"vod_1080p_url:: {vod_1080p_url}") self.url = vod_1080p_url logger.info(self.url) except Exception as e: - P.logger.error("Exception:%s", e) + P.logger.error(f"Exception: str(e)") P.logger.error(traceback.format_exc()) diff --git a/mod_ohli24.py b/mod_ohli24.py index eb69559..8d5fe36 100644 --- a/mod_ohli24.py +++ b/mod_ohli24.py @@ -52,7 +52,7 @@ from framework import F from plugin import ( PluginModuleBase ) -from .lib.ffmpeg_queue import FfmpegQueueEntity, FfmpegQueue +from .lib.ffmpeg_queue_v1 import FfmpegQueueEntity, FfmpegQueue from support.expand.ffmpeg import SupportFfmpeg from .lib.util import Util @@ -118,7 +118,7 @@ class LogicOhli24(PluginModuleBase): } self.queue = None # default_route_socketio(P, self) - default_route_socketio_module(self, attach='/search') + default_route_socketio_module(self, attach='/queue') @staticmethod def db_init(): @@ -219,10 +219,6 @@ class LogicOhli24(PluginModuleBase): # if db_item == None: # db_item = ModelOhli24Program(info['_id'], self.get_episode(info['_id'])) # db_item.save() - - - - elif sub == "entity_list": return jsonify(self.queue.get_entity_list()) elif sub == "queue_list": @@ -255,7 +251,8 @@ class LogicOhli24(PluginModuleBase): thread.daemon = True thread.start() return jsonify("") - elif sub == "web_list": + elif sub == "web_list2": + logger.debug("web_list2") return jsonify(ModelOhli24Item.web_list(request)) elif sub == "db_remove": return jsonify(ModelOhli24Item.delete_by_id(req.form["id"])) @@ -287,8 +284,9 @@ class LogicOhli24(PluginModuleBase): def process_command(self, command, arg1, arg2, arg3, req): ret = {'ret': 'success'} - logger.debug('queue_list') + if command == 'queue_list': + logger.debug('queue_list') logger.debug(f"self.queue.get_entity_list():: {self.queue.get_entity_list()}") ret = [x for x in self.queue.get_entity_list()] @@ -315,6 +313,19 @@ class LogicOhli24(PluginModuleBase): for ins in SupportFfmpeg.get_list(): ret.append(ins.get_data()) + elif command == 'queue_command': + if arg1 == 'cancel': + pass + elif arg1 == 'reset': + logger.debug('reset') + # if self.queue is not None: + # with self.queue.mutex: + # self.queue.queue.clear() + + if self.download_queue is not None: + with self.download_queue.mutex: + self.download_queue.queue.clear() + return jsonify(ret) @staticmethod @@ -751,8 +762,8 @@ class LogicOhli24(PluginModuleBase): # self.callback_function, ffmpeg_modelsetting.get_int('max_pf_count')) # plugin loading download_queue 가 없으면 생성 - if self.download_queue is None: - self.download_queue = queue.Queue() + # if self.download_queue is None: + # self.download_queue = queue.Queue() SupportFfmpeg.initialize("ffmpeg", os.path.join(F.config['path_data'], 'tmp'), self.callback_function, 1) @@ -762,7 +773,7 @@ class LogicOhli24(PluginModuleBase): P, P.ModelSetting.get_int("ohli24_max_ffmpeg_process_count") ) self.current_data = None - # self.queue.queue_start() + self.queue.queue_start() except Exception as e: logger.error("Exception:%s", e) @@ -859,13 +870,16 @@ class LogicOhli24(PluginModuleBase): return "db_completed" def is_exist(self, info): - print(self.queue.entity_list) + # print(self.queue) + # print(self.queue.entity_list) for en in self.queue.entity_list: if en.info["_id"] == info["_id"]: return True # return False def callback_function(self, **args): + logger.debug('callback_function============') + logger.debug(args) refresh_type = None if args['type'] == 'status_change': if args['status'] == SupportFfmpeg.Status.DOWNLOADING: @@ -876,7 +890,7 @@ class LogicOhli24(PluginModuleBase): data = {'type': 'info', 'msg': '다운로드중 Duration(%s)' % args['data']['duration_str'] + '
' + args['data'][ 'save_fullpath'], 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) + # socketio.emit("notify", data, namespace='/framework', broadcast=True) refresh_type = 'add' elif args['type'] == 'last': if args['status'] == SupportFfmpeg.Status.WRONG_URL: @@ -899,7 +913,9 @@ class LogicOhli24(PluginModuleBase): elif args['status'] == SupportFfmpeg.Status.COMPLETED: data = {'type': 'success', 'msg': '다운로드가 완료 되었습니다.
' + args['data']['save_fullpath'], 'url': '/ffmpeg/download/list'} - socketio.emit("notify", data, namespace='/framework', broadcast=True) + + # socketio.emit("notify", data, namespace='/framework', broadcast=True) + refresh_type = 'last' elif args['status'] == SupportFfmpeg.Status.TIME_OVER: data = {'type': 'warning', 'msg': '시간초과로 중단 되었습니다.
' + args['data']['save_fullpath'], diff --git a/templates/anime_downloader_anilife_queue.html b/templates/anime_downloader_anilife_queue.html index 29b84d0..564d94a 100644 --- a/templates/anime_downloader_anilife_queue.html +++ b/templates/anime_downloader_anilife_queue.html @@ -1,175 +1,231 @@ {% extends "base.html" %} {% block content %} +
+ {{ macros.m_button_group([['reset_btn', '초기화'], ['delete_completed_btn', '완료 목록 삭제'], ['go_ffmpeg_btn', 'Go FFMPEG']]) }} +
+ + + + + + + + + + + + + + + + + +
IDXPlugin시작시간파일명상태진행률길이PF배속진행시간Action
- - - - - - - - - - - - - - - - - -
IDXPlugin시작시간파일명상태진행률길이PF배속진행시간Action
+ + function make_item2(data) { + str = ''; + str += ''; + str += '
'; + str += get_detail(data); + str += '
'; + str += ''; + return str + } + + + function get_detail(data) { + var str = j_row_info('URL', data.url); + str += j_row_info('임시경로', data.temp_fullpath); + str += j_row_info('저장경로', data.save_fullpath); + str += j_row_info('진행률(current/total)', data.percent + '% (' + data.current_duration + ' / ' + data.duration + ')'); + str += j_row_info('현재 비트레이트', data.current_bitrate); + str += j_row_info('종료시간', data.end_time); + str += j_row_info('허용 Packet Fail 수', data.max_pf_count); + str += j_row_info('파일 Exist', data.exist); + if (data.status_str == 'COMPLETED') { + str += j_row_info('파일 크기', data.filesize_str); + str += j_row_info('다운 속도', data.download_speed); + } + return str; + } + + function button_html(data) { + //console.log(data) + str = ''; + if (data.status_str == 'DOWNLOADING') { + str = j_button('stop_btn', '중지', {'idx': data.idx}, 'danger', false, false); + } + $("#button_" + data.idx).html(str); + } + + function status_html(data) { + var progress = document.getElementById("progress_" + data.idx); + progress.style.width = data.percent + '%'; + progress.innerHTML = data.percent + '%'; + progress.style.visibility = 'visible'; + document.getElementById("status_" + data.idx).innerHTML = data.status_kor; + document.getElementById("current_pf_count_" + data.idx).innerHTML = data.current_pf_count; + document.getElementById("current_speed_" + data.idx).innerHTML = data.current_speed; + document.getElementById("download_time_" + data.idx).innerHTML = data.download_time; + document.getElementById("detail_" + data.idx).innerHTML = get_detail(data); + } + + $("body").on('click', '#reset_btn', function (e) { + e.preventDefault(); + entity_id = $(this).data('id') + send_data = {'command': 'reset', 'entity_id': -1} + queue_command(send_data) + }); + + function queue_command(data) { + $.ajax({ + url: '/' + package_name + '/ajax/' + sub + '/queue_command', + type: "POST", + cache: false, + data: data, + dataType: "json", + success: function (ret) { + if (ret.ret == 'notify') { + $.notify('' + ret.log + '', {type: 'warning'}); + } + on_start(); + } + }); + } + + {% endblock %} diff --git a/templates/anime_downloader_anilife_request.html b/templates/anime_downloader_anilife_request.html index 8ed0fc5..d64fb54 100644 --- a/templates/anime_downloader_anilife_request.html +++ b/templates/anime_downloader_anilife_request.html @@ -222,6 +222,7 @@ $(document).ready(function () { $("#loader").css("display", 'none') + console.log({{ arg['code'] }}) // console.log('wr_id::', params.wr_id) diff --git a/templates/anime_downloader_anilife_search.html b/templates/anime_downloader_anilife_search.html index 9f32e92..405cd67 100644 --- a/templates/anime_downloader_anilife_search.html +++ b/templates/anime_downloader_anilife_search.html @@ -187,6 +187,7 @@ // {# '' + data.episode[i].code + '';#} tmp += '
' + data.anime_list[i].title + '
'; tmp += '

' + data.anime_list[i].code + '

'; + tmp += '

' + data.anime_list[i].epx + '

'; tmp += '' + data.anime_list[i].title + ''; tmp += ''; tmp += ''; @@ -247,6 +248,7 @@ // {# '' + data.episode[i].code + '';#} tmp += '
' + data.anime_list[i].title + '
'; tmp += '

' + data.anime_list[i].code + '

'; + tmp += '

' + data.anime_list[i].epx + '

'; tmp += '' + data.anime_list[i].title + ''; tmp += ''; tmp += ''; @@ -602,254 +604,261 @@ max-width: 80%; margin: 0 auto; } + } - [data-tooltip-text]:hover { - position: relative; - } + [data-tooltip-text]:hover { + position: relative; + } - [data-tooltip-text]:after { - -webkit-transition: bottom 0.3s ease-in-out, opacity 0.3s ease-in-out; - -moz-transition: bottom 0.3s ease-in-out, opacity 0.3s ease-in-out; - transition: bottom 0.3s ease-in-out, opacity 0.3s ease-in-out; + [data-tooltip-text]:after { + -webkit-transition: bottom 0.3s ease-in-out, opacity 0.3s ease-in-out; + -moz-transition: bottom 0.3s ease-in-out, opacity 0.3s ease-in-out; + transition: bottom 0.3s ease-in-out, opacity 0.3s ease-in-out; - background-color: rgba(0, 0, 0, 0.8); + background-color: rgba(0, 0, 0, 0.8); - -webkit-box-shadow: 0px 0px 3px 1px rgba(50, 50, 50, 0.4); - -moz-box-shadow: 0px 0px 3px 1px rgba(50, 50, 50, 0.4); - box-shadow: 0px 0px 3px 1px rgba(50, 50, 50, 0.4); + -webkit-box-shadow: 0px 0px 3px 1px rgba(50, 50, 50, 0.4); + -moz-box-shadow: 0px 0px 3px 1px rgba(50, 50, 50, 0.4); + box-shadow: 0px 0px 3px 1px rgba(50, 50, 50, 0.4); - -webkit-border-radius: 5px; - -moz-border-radius: 5px; - border-radius: 5px; + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + border-radius: 5px; - color: #ffffff; - font-size: 12px; - margin-bottom: 10px; - padding: 7px 12px; - position: absolute; - width: auto; - min-width: 50px; - max-width: 300px; - word-wrap: break-word; + color: #ffffff; + font-size: 12px; + margin-bottom: 10px; + padding: 7px 12px; + position: absolute; + width: auto; + min-width: 50px; + max-width: 300px; + word-wrap: break-word; - z-index: 9999; + z-index: 9999; - opacity: 0; - left: -9999px; - top: 90%; + opacity: 0; + left: -9999px; + top: 90%; - content: attr(data-tooltip-text); - } + content: attr(data-tooltip-text); + } - [data-tooltip-text]:hover:after { - top: 230%; - left: 0; - opacity: 1; - } + [data-tooltip-text]:hover:after { + top: 230%; + left: 0; + opacity: 1; + } - [data-tooltip-text]:hover { - position: relative; - } + [data-tooltip-text]:hover { + position: relative; + } - [data-tooltip-text]:after { - -webkit-transition: bottom 0.3s ease-in-out, opacity 0.3s ease-in-out; - -moz-transition: bottom 0.3s ease-in-out, opacity 0.3s ease-in-out; - transition: bottom 0.3s ease-in-out, opacity 0.3s ease-in-out; + [data-tooltip-text]:after { + -webkit-transition: bottom 0.3s ease-in-out, opacity 0.3s ease-in-out; + -moz-transition: bottom 0.3s ease-in-out, opacity 0.3s ease-in-out; + transition: bottom 0.3s ease-in-out, opacity 0.3s ease-in-out; - background-color: rgba(0, 0, 0, 0.8); + background-color: rgba(0, 0, 0, 0.8); - -webkit-box-shadow: 0px 0px 3px 1px rgba(50, 50, 50, 0.4); - -moz-box-shadow: 0px 0px 3px 1px rgba(50, 50, 50, 0.4); - box-shadow: 0px 0px 3px 1px rgba(50, 50, 50, 0.4); + -webkit-box-shadow: 0px 0px 3px 1px rgba(50, 50, 50, 0.4); + -moz-box-shadow: 0px 0px 3px 1px rgba(50, 50, 50, 0.4); + box-shadow: 0px 0px 3px 1px rgba(50, 50, 50, 0.4); - -webkit-border-radius: 5px; - -moz-border-radius: 5px; - border-radius: 5px; + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + border-radius: 5px; - color: #ffffff; - font-size: 12px; - margin-bottom: 10px; - padding: 7px 12px; - position: absolute; - width: auto; - min-width: 50px; - max-width: 300px; - word-wrap: break-word; + color: #ffffff; + font-size: 12px; + margin-bottom: 10px; + padding: 7px 12px; + position: absolute; + width: auto; + min-width: 50px; + max-width: 300px; + word-wrap: break-word; - z-index: 9999; + z-index: 9999; - opacity: 0; - left: -9999px; - top: -210% !important; + opacity: 0; + left: -9999px; + top: -210% !important; - content: attr(data-tooltip-text); - } + content: attr(data-tooltip-text); + } - [data-tooltip-text]:hover:after { - top: 130%; - left: 0; - opacity: 1; - } + [data-tooltip-text]:hover:after { + top: 130%; + left: 0; + opacity: 1; + } - #airing_list { - display: none; - } + #airing_list { + display: none; + } - .cut-text { - text-overflow: ellipsis; - overflow: hidden; - white-space: nowrap; - width: 100%; - } + .cut-text { + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; + width: 100%; + } - #screen_movie_list { - margin-top: 10px; - } + .btn { + white-space: normal !important; + word-wrap: break-word; + } - .card-body { - padding: 0 !important; - } + #screen_movie_list { + margin-top: 10px; + } - .card-title { - padding: 1rem !important; - } + .card-body { + padding: 0 !important; + } - button#add_whitelist { - float: right; - } + .card-title { + padding: 1rem !important; + } - button.btn-favorite { - background-color: #e0ff42; - } + button#add_whitelist { + float: right; + } - body { - font-family: NanumSquareNeo, system-ui, -apple-system, Segoe UI, Roboto, Helvetica Neue, Noto Sans, Liberation Sans, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji; - } + button.btn-favorite { + background-color: #e0ff42; + } - body { - background-image: linear-gradient(90deg, #233f48, #6c6fa2, #768dae); - } + body { + font-family: NanumSquareNeo, system-ui, -apple-system, Segoe UI, Roboto, Helvetica Neue, Noto Sans, Liberation Sans, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji; + } - .demo { - width: 100px; - height: 102px; - border-radius: 100%; - position: absolute; - top: 45%; - left: calc(50% - 50px); - } + body { + background-image: linear-gradient(90deg, #233f48, #6c6fa2, #768dae); + } - .circle { - width: 100%; - height: 100%; - position: absolute; - } + .demo { + width: 100px; + height: 102px; + border-radius: 100%; + position: absolute; + top: 45%; + left: calc(50% - 50px); + } - .circle .inner { - width: 100%; - height: 100%; - border-radius: 100%; - border: 5px solid rgba(0, 255, 170, 0.7); - border-right: none; - border-top: none; - backgroudn-clip: padding; - box-shadow: inset 0px 0px 10px rgba(0, 255, 170, 0.15); - } + .circle { + width: 100%; + height: 100%; + position: absolute; + } - @-webkit-keyframes spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } - } + .circle .inner { + width: 100%; + height: 100%; + border-radius: 100%; + border: 5px solid rgba(0, 255, 170, 0.7); + border-right: none; + border-top: none; + backgroudn-clip: padding; + box-shadow: inset 0px 0px 10px rgba(0, 255, 170, 0.15); + } - @keyframes spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } - } - - .circle:nth-of-type(0) { + @-webkit-keyframes spin { + from { transform: rotate(0deg); } - - .circle:nth-of-type(0) .inner { - -webkit-animation: spin 2s infinite linear; - animation: spin 2s infinite linear; + to { + transform: rotate(360deg); } + } - .circle:nth-of-type(1) { - transform: rotate(70deg); + @keyframes spin { + from { + transform: rotate(0deg); } - - .circle:nth-of-type(1) .inner { - -webkit-animation: spin 2s infinite linear; - animation: spin 2s infinite linear; + to { + transform: rotate(360deg); } + } - .circle:nth-of-type(2) { - transform: rotate(140deg); - } + .circle:nth-of-type(0) { + transform: rotate(0deg); + } - .circle:nth-of-type(2) .inner { - -webkit-animation: spin 2s infinite linear; - animation: spin 2s infinite linear; - } + .circle:nth-of-type(0) .inner { + -webkit-animation: spin 2s infinite linear; + animation: spin 2s infinite linear; + } - .demo { - -webkit-animation: spin 5s infinite linear; - animation: spin 5s infinite linear; - background: rgba(0, 0, 0, 0.2); - background: radial-gradient(#222, #000); - bottom: 0; - left: 0; - overflow: hidden; - /*position: fixed;*/ - right: 0; - /*top: 0;*/ - z-index: 99999; - opacity: 0.5; - margin: 0 auto; - transform: translate(-50%, -50%); - position: absolute; - top: 50%; + .circle:nth-of-type(1) { + transform: rotate(70deg); + } - } + .circle:nth-of-type(1) .inner { + -webkit-animation: spin 2s infinite linear; + animation: spin 2s infinite linear; + } - .loader-inner { - bottom: 0; - height: 60px; - left: 0; - margin: auto; - position: absolute; - right: 0; - top: 0; - width: 100px; - } + .circle:nth-of-type(2) { + transform: rotate(140deg); + } + + .circle:nth-of-type(2) .inner { + -webkit-animation: spin 2s infinite linear; + animation: spin 2s infinite linear; + } + + .demo { + -webkit-animation: spin 5s infinite linear; + animation: spin 5s infinite linear; + background: rgba(0, 0, 0, 0.2); + background: radial-gradient(#222, #000); + bottom: 0; + left: 0; + overflow: hidden; + /*position: fixed;*/ + right: 0; + /*top: 0;*/ + z-index: 99999; + opacity: 0.5; + margin: 0 auto; + transform: translate(-50%, -50%); + position: absolute; + top: 50%; + + } + + .loader-inner { + bottom: 0; + height: 60px; + left: 0; + margin: auto; + position: absolute; + right: 0; + top: 0; + width: 100px; + } + + #preloader { + /*background-color: green;*/ + /*color: white;*/ + /*height: 100vh;*/ + /*width: 100%;*/ + /*position: fixed;*/ + /*z-index: 100;*/ + background: rgba(0, 0, 0, 0.2); + background: radial-gradient(#222, #000); + bottom: 0; + left: 0; + overflow: hidden; + position: fixed; + right: 0; + top: 0; + z-index: 99999; + opacity: 0.5; + } - #preloader { - /*background-color: green;*/ - /*color: white;*/ - /*height: 100vh;*/ - /*width: 100%;*/ - /*position: fixed;*/ - /*z-index: 100;*/ - background: rgba(0, 0, 0, 0.2); - background: radial-gradient(#222, #000); - bottom: 0; - left: 0; - overflow: hidden; - position: fixed; - right: 0; - top: 0; - z-index: 99999; - opacity: 0.5; - } {% endblock %} diff --git a/templates/anime_downloader_ohli24_list.html b/templates/anime_downloader_ohli24_list.html index 797a6c1..cbc5ac1 100644 --- a/templates/anime_downloader_ohli24_list.html +++ b/templates/anime_downloader_ohli24_list.html @@ -8,7 +8,7 @@