2023.01.26 (01. ohli24.org bug fixed)

This commit is contained in:
2023-01-26 15:33:59 +09:00
parent 1ef263b440
commit e3060bba3f
6 changed files with 738 additions and 461 deletions

View File

@@ -7,18 +7,22 @@ import traceback
from datetime import datetime from datetime import datetime
import requests import requests
# from flaskfarm.lib.plugin import get_model_setting # from flaskfarm.lib.plugin import get_model_setting
from flaskfarm.lib.support.expand.ffmpeg import SupportFfmpeg from flaskfarm.lib.support.expand.ffmpeg import SupportFfmpeg
# from flaskfarm.lib.system.setup import SystemModelSetting # from flaskfarm.lib.system.setup import SystemModelSetting
from flaskfarm.lib.tool import ToolUtil from flaskfarm.lib.tool import ToolUtil
# from flaskfarm.lib.system.setup import P as SM # from flaskfarm.lib.system.setup import P as SM
# from flaskfarm.lib.system.mod_setting import ModuleSetting as SM # from flaskfarm.lib.system.mod_setting import ModuleSetting as SM
from ..setup import * from ..setup import *
logger = P.logger
class FfmpegQueueEntity(abc.ABCMeta('ABC', (object,), {'__slots__': ()})):
class FfmpegQueueEntity(abc.ABCMeta("ABC", (object,), {"__slots__": ()})):
def __init__(self, P, module_logic, info): def __init__(self, P, module_logic, info):
self.P = P self.P = P
# SupportFfmpeg.initialize() # SupportFfmpeg.initialize()
@@ -29,11 +33,11 @@ class FfmpegQueueEntity(abc.ABCMeta('ABC', (object,), {'__slots__': ()})):
self.info = info self.info = info
self.url = None self.url = None
self.ffmpeg_status = -1 self.ffmpeg_status = -1
self.ffmpeg_status_kor = u'대기중' self.ffmpeg_status_kor = "대기중"
self.ffmpeg_percent = 0 self.ffmpeg_percent = 0
self.ffmpeg_arg = None self.ffmpeg_arg = None
self.cancel = False self.cancel = False
self.created_time = datetime.now().strftime('%m-%d %H:%M:%S') self.created_time = datetime.now().strftime("%m-%d %H:%M:%S")
self.savepath = None self.savepath = None
self.filename = None self.filename = None
self.filepath = None self.filepath = None
@@ -61,26 +65,25 @@ class FfmpegQueueEntity(abc.ABCMeta('ABC', (object,), {'__slots__': ()})):
def as_dict(self): def as_dict(self):
tmp = {} tmp = {}
tmp['entity_id'] = self.entity_id tmp["entity_id"] = self.entity_id
tmp['url'] = self.url tmp["url"] = self.url
tmp['ffmpeg_status'] = self.ffmpeg_status tmp["ffmpeg_status"] = self.ffmpeg_status
tmp['ffmpeg_status_kor'] = self.ffmpeg_status_kor tmp["ffmpeg_status_kor"] = self.ffmpeg_status_kor
tmp['ffmpeg_percent'] = self.ffmpeg_percent tmp["ffmpeg_percent"] = self.ffmpeg_percent
tmp['ffmpeg_arg'] = self.ffmpeg_arg tmp["ffmpeg_arg"] = self.ffmpeg_arg
tmp['cancel'] = self.cancel tmp["cancel"] = self.cancel
tmp['created_time'] = self.created_time # .strftime('%m-%d %H:%M:%S') tmp["created_time"] = self.created_time # .strftime('%m-%d %H:%M:%S')
tmp['savepath'] = self.savepath tmp["savepath"] = self.savepath
tmp['filename'] = self.filename tmp["filename"] = self.filename
tmp['filepath'] = self.filepath tmp["filepath"] = self.filepath
tmp['quality'] = self.quality tmp["quality"] = self.quality
# tmp['current_speed'] = self.ffmpeg_arg['current_speed'] if self.ffmpeg_arg is not None else '' # tmp['current_speed'] = self.ffmpeg_arg['current_speed'] if self.ffmpeg_arg is not None else ''
tmp = self.info_dict(tmp) tmp = self.info_dict(tmp)
return tmp return tmp
class FfmpegQueue(object): class FfmpegQueue(object):
def __init__(self, P, max_ffmpeg_count, sub_package_name, caller=None):
def __init__(self, P, max_ffmpeg_count):
self.P = P self.P = P
self.static_index = 1 self.static_index = 1
@@ -89,20 +92,34 @@ class FfmpegQueue(object):
self.download_queue = None self.download_queue = None
self.download_thread = None self.download_thread = None
self.max_ffmpeg_count = max_ffmpeg_count self.max_ffmpeg_count = max_ffmpeg_count
if self.max_ffmpeg_count is None or self.max_ffmpeg_count == '': self.name = sub_package_name
if self.max_ffmpeg_count is None or self.max_ffmpeg_count == "":
self.max_ffmpeg_count = 1 self.max_ffmpeg_count = 1
self.caller = caller
# self.support_init()
def support_init(self):
SupportFfmpeg.initialize(
"ffmpeg",
os.path.join(F.config["path_data"], "tmp"),
self.callback_function,
P.ModelSetting.get(f"{self.name}_max_ffmpeg_process_count"),
)
def queue_start(self): def queue_start(self):
try: try:
if self.download_queue is None: if self.download_queue is None:
self.download_queue = queue.Queue() self.download_queue = queue.Queue()
if self.download_thread is None: if self.download_thread is None:
self.download_thread = threading.Thread(target=self.download_thread_function, args=()) self.download_thread = threading.Thread(
target=self.download_thread_function, args=()
)
self.download_thread.daemon = True self.download_thread.daemon = True
# todo: 동작 방식 고찰 # todo: 동작 방식 고찰
self.download_thread.start() self.download_thread.start()
except Exception as exception: except Exception as exception:
self.P.logger.error(f'Exception: {exception}') self.P.logger.error(f"Exception: {exception}")
self.P.logger.error(traceback.format_exc()) self.P.logger.error(traceback.format_exc())
def download_thread_function(self): def download_thread_function(self):
@@ -114,12 +131,17 @@ class FfmpegQueue(object):
break break
time.sleep(5) time.sleep(5)
except Exception as exception: except Exception as exception:
self.P.logger.error(f'Exception: {exception}') self.P.logger.error(f"Exception: {exception}")
self.P.logger.error(traceback.format_exc()) self.P.logger.error(traceback.format_exc())
self.P.logger.error('current_ffmpeg_count : %s', self.current_ffmpeg_count) self.P.logger.error(
self.P.logger.error('max_ffmpeg_count : %s', self.max_ffmpeg_count) "current_ffmpeg_count : %s", self.current_ffmpeg_count
)
self.P.logger.error(
"max_ffmpeg_count : %s", self.max_ffmpeg_count
)
break break
entity = self.download_queue.get() entity = self.download_queue.get()
logger.debug(f"entity: {entity}")
if entity.cancel: if entity.cancel:
continue continue
@@ -127,7 +149,7 @@ class FfmpegQueue(object):
# entity.url = LogicAni24.get_video_url(entity.info['code']) # entity.url = LogicAni24.get_video_url(entity.info['code'])
video_url = entity.get_video_url() video_url = entity.get_video_url()
if video_url is None: if video_url is None:
entity.ffmpeg_status_kor = 'URL실패' entity.ffmpeg_status_kor = "URL실패"
entity.refresh_status() entity.refresh_status()
# plugin.socketio_list_refresh() # plugin.socketio_list_refresh()
continue continue
@@ -145,17 +167,18 @@ class FfmpegQueue(object):
# except: # except:
# logger.debug('program path make fail!!') # logger.debug('program path make fail!!')
# 파일 존재여부 체크 # 파일 존재여부 체크
print("here...................")
P.logger.info(entity.info) P.logger.info(entity.info)
filepath = entity.get_video_filepath() filepath = entity.get_video_filepath()
P.logger.debug(f'filepath:: {filepath}') P.logger.debug(f"filepath:: {filepath}")
if os.path.exists(filepath): if os.path.exists(filepath):
entity.ffmpeg_status_kor = '파일 있음' entity.ffmpeg_status_kor = "파일 있음"
entity.ffmpeg_percent = 100 entity.ffmpeg_percent = 100
entity.refresh_status() entity.refresh_status()
# plugin.socketio_list_refresh() # plugin.socketio_list_refresh()
continue continue
dirname = os.path.dirname(filepath) dirname = os.path.dirname(filepath)
# filename = os.path.f filename = os.path.basename(filepath)
if not os.path.exists(dirname): if not os.path.exists(dirname):
os.makedirs(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) # 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)
@@ -165,10 +188,20 @@ class FfmpegQueue(object):
# aa_sm = get_model_setting("system", P.logger) # aa_sm = get_model_setting("system", P.logger)
P.logger.debug(P) P.logger.debug(P)
# P.logger.debug(P.system_setting.get("port")) # P.logger.debug(P.system_setting.get("port"))
P.logger.debug(filename)
# P.logger.debug(filepath)
ffmpeg = SupportFfmpeg(video_url, str(os.path.basename(filepath)), # SupportFfmpeg 초기화
self.support_init()
ffmpeg = SupportFfmpeg(
url=video_url,
filename=filename,
callback_function=self.callback_function, callback_function=self.callback_function,
max_pf_count=0, save_path=ToolUtil.make_path(dirname), timeout_minute=60, headers=self.caller.headers,
max_pf_count=0,
save_path=ToolUtil.make_path(dirname),
timeout_minute=60,
) )
# #
# todo: 임시로 start() 중지 # todo: 임시로 start() 중지
@@ -177,108 +210,152 @@ class FfmpegQueue(object):
self.download_queue.task_done() self.download_queue.task_done()
except Exception as exception: except Exception as exception:
self.P.logger.error('Exception:%s', exception) self.P.logger.error("Exception:%s", exception)
self.P.logger.error(traceback.format_exc()) self.P.logger.error(traceback.format_exc())
# def callback_function(self, **args): def callback_function(self, **args):
# refresh_type = None refresh_type = None
# if args['type'] == 'status_change': # entity = self.get_entity_by_entity_id(arg['plugin_id'])
# if args['status'] == SupportFfmpeg.Status.DOWNLOADING: entity = self.get_entity_by_entity_id(args["data"]["callback_id"])
# 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'] + '<br>' + 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': '잘못된 디렉토리입니다.<br>' + 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': '다운로드 시작 실패.<br>' + 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': '다운로드가 중지 되었습니다.<br>' + 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': '다운로드가 완료 되었습니다.<br>' + 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': '시간초과로 중단 되었습니다.<br>' + 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초과로 중단 되었습니다.<br>' + 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': '강제 중단 되었습니다.<br>' + 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에러로 중단 되었습니다.<br>' + 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': '임시파일폴더에 파일이 있습니다.<br>' + 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): if args["type"] == "status_change":
import ffmpeg if args["status"] == SupportFfmpeg.Status.DOWNLOADING:
entity = self.get_entity_by_entity_id(arg['plugin_id']) refresh_type = "status_change"
if entity is None: elif args["status"] == SupportFfmpeg.Status.COMPLETED:
return logger.debug("ffmpeg_queue_v1.py:: download completed........")
if arg['type'] == 'status_change': refresh_type = "status_change"
if arg['status'] == ffmpeg.Status.DOWNLOADING: elif args["status"] == SupportFfmpeg.Status.READY:
pass data = {
elif arg['status'] == ffmpeg.Status.COMPLETED: "type": "info",
entity.donwload_completed() "msg": "다운로드중 Duration(%s)" % args["data"]["duration_str"]
elif arg['status'] == ffmpeg.Status.READY: + "<br>"
pass + args["data"]["save_fullpath"],
elif arg['type'] == 'last': "url": "/ffmpeg/download/list",
self.current_ffmpeg_count += -1 }
elif arg['type'] == 'log': socketio.emit("notify", data, namespace="/framework", broadcast=True)
pass refresh_type = "add"
elif arg['type'] == 'normal': elif args["type"] == "last":
pass 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": "잘못된 디렉토리입니다.<br>" + 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": "다운로드 시작 실패.<br>" + 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": "다운로드가 중지 되었습니다.<br>" + 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:
print("print():: ffmpeg download completed..")
logger.debug("ffmpeg download completed......")
entity.download_completed()
data = {
"type": "success",
"msg": "다운로드가 완료 되었습니다.<br>" + args["data"]["save_fullpath"],
"url": "/ffmpeg/download/list",
}
entity.ffmpeg_arg = arg socketio.emit("notify", data, namespace="/framework", broadcast=True)
entity.ffmpeg_status = int(arg['status']) refresh_type = "last"
entity.ffmpeg_status_kor = str(arg['status']) elif args["status"] == SupportFfmpeg.Status.TIME_OVER:
entity.ffmpeg_percent = arg['data']['percent'] data = {
entity.ffmpeg_arg['status'] = str(arg['status']) "type": "warning",
# self.P.logger.debug(arg) "msg": "시간초과로 중단 되었습니다.<br>" + args["data"]["save_fullpath"],
# import plugin "url": "/ffmpeg/download/list",
# arg['status'] = str(arg['status']) }
# plugin.socketio_callback('status', arg) socketio.emit("notify", data, namespace="/framework", broadcast=True)
entity.refresh_status() refresh_type = "last"
elif args["status"] == SupportFfmpeg.Status.PF_STOP:
data = {
"type": "warning",
"msg": "PF초과로 중단 되었습니다.<br>" + 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": "강제 중단 되었습니다.<br>" + 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에러로 중단 되었습니다.<br>" + 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": "임시파일폴더에 파일이 있습니다.<br>" + 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)
# Todo:
self.caller.socketio_callback(refresh_type, args["data"])
# FfmpegQueueEntity.static_index += 1 # def ffmpeg_listener(self, **arg):
# FfmpegQueueEntity.entity_list.append(self) # 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.download_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): def add_queue(self, entity):
try: try:
@@ -292,7 +369,7 @@ class FfmpegQueue(object):
self.download_queue.put(entity) self.download_queue.put(entity)
return True return True
except Exception as exception: except Exception as exception:
self.P.logger.error('Exception:%s', exception) self.P.logger.error("Exception:%s", exception)
self.P.logger.error(traceback.format_exc()) self.P.logger.error(traceback.format_exc())
return False return False
@@ -303,63 +380,65 @@ class FfmpegQueue(object):
return self.max_ffmpeg_count return self.max_ffmpeg_count
def command(self, cmd, entity_id): def command(self, cmd, entity_id):
self.P.logger.debug('command :%s %s', cmd, entity_id) self.P.logger.debug("command :%s %s", cmd, entity_id)
ret = {} ret = {}
try: try:
if cmd == 'cancel': if cmd == "cancel":
self.P.logger.debug('command :%s %s', cmd, entity_id) self.P.logger.debug("command :%s %s", cmd, entity_id)
entity = self.get_entity_by_entity_id(entity_id) entity = self.get_entity_by_entity_id(entity_id)
if entity is not None: if entity is not None:
if entity.ffmpeg_status == -1: if entity.ffmpeg_status == -1:
entity.cancel = True entity.cancel = True
entity.ffmpeg_status_kor = "취소" entity.ffmpeg_status_kor = "취소"
# entity.refresh_status() # entity.refresh_status()
ret['ret'] = 'refresh' ret["ret"] = "refresh"
elif entity.ffmpeg_status != 5: elif entity.ffmpeg_status != 5:
ret['ret'] = 'notify' ret["ret"] = "notify"
ret['log'] = '다운로드중 상태가 아닙니다.' ret["log"] = "다운로드중 상태가 아닙니다."
else: else:
idx = entity.ffmpeg_arg['data']['idx'] idx = entity.ffmpeg_arg["data"]["idx"]
import ffmpeg import ffmpeg
ffmpeg.Ffmpeg.stop_by_idx(idx) ffmpeg.Ffmpeg.stop_by_idx(idx)
entity.refresh_status() entity.refresh_status()
ret['ret'] = 'refresh' ret["ret"] = "refresh"
elif cmd == 'reset': elif cmd == "reset":
if self.download_queue is not None: if self.download_queue is not None:
with self.download_queue.mutex: with self.download_queue.mutex:
self.download_queue.queue.clear() self.download_queue.queue.clear()
for _ in self.entity_list: for _ in self.entity_list:
if _.ffmpeg_status == 5: if _.ffmpeg_status == 5:
import ffmpeg import ffmpeg
idx = _.ffmpeg_arg['data']['idx']
idx = _.ffmpeg_arg["data"]["idx"]
ffmpeg.Ffmpeg.stop_by_idx(idx) ffmpeg.Ffmpeg.stop_by_idx(idx)
self.entity_list = [] self.entity_list = []
ret['ret'] = 'refresh' ret["ret"] = "refresh"
elif cmd == 'delete_completed': elif cmd == "delete_completed":
new_list = [] new_list = []
for _ in self.entity_list: for _ in self.entity_list:
if _.ffmpeg_status_kor in [u'파일 있음', u'취소', u'사용자중지']: if _.ffmpeg_status_kor in ["파일 있음", "취소", "사용자중지"]:
continue continue
if _.ffmpeg_status != 7: if _.ffmpeg_status != 7:
new_list.append(_) new_list.append(_)
self.entity_list = new_list self.entity_list = new_list
ret['ret'] = 'refresh' ret["ret"] = "refresh"
elif cmd == 'remove': elif cmd == "remove":
new_list = [] new_list = []
for _ in self.entity_list: for _ in self.entity_list:
if _.entity_id == entity_id: if _.entity_id == entity_id:
continue continue
new_list.append(_) new_list.append(_)
self.entity_list = new_list self.entity_list = new_list
ret['ret'] = 'refresh' ret["ret"] = "refresh"
return ret return ret
except Exception as exception: except Exception as exception:
self.P.logger.error('Exception:%s', exception) self.P.logger.error("Exception:%s", exception)
self.P.logger.error(traceback.format_exc()) self.P.logger.error(traceback.format_exc())
def get_entity_by_entity_id(self, entity_id): def get_entity_by_entity_id(self, entity_id):
for _ in self.entity_list: for _ in self.entity_list:
if _.entity_id == entity_id: if _.entity_id == int(entity_id):
return _ return _
return None return None

View File

@@ -66,6 +66,7 @@ T = TypeVar("T")
from .setup import * from .setup import *
logger = P.logger logger = P.logger
name = 'anilife'
class LogicAniLife(PluginModuleBase): class LogicAniLife(PluginModuleBase):
db_default = { db_default = {
@@ -653,7 +654,7 @@ class LogicAniLife(PluginModuleBase):
def plugin_load(self): def plugin_load(self):
self.queue = FfmpegQueue( self.queue = FfmpegQueue(
P, P.ModelSetting.get_int("anilife_max_ffmpeg_process_count") P, P.ModelSetting.get_int("anilife_max_ffmpeg_process_count"), name
) )
self.current_data = None self.current_data = None
self.queue.queue_start() self.queue.queue_start()

View File

@@ -22,6 +22,7 @@ from urllib import parse
# third-party # third-party
import requests import requests
# third-party # third-party
from flask import request, render_template, jsonify from flask import request, render_template, jsonify
from lxml import html from lxml import html
@@ -33,9 +34,11 @@ for pkg in pkgs:
importlib.import_module(pkg) importlib.import_module(pkg)
# except ImportError: # except ImportError:
except ImportError: except ImportError:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', 'pip']) subprocess.check_call(
[sys.executable, "-m", "pip", "install", "--upgrade", "pip"]
)
# main(["install", pkg]) # main(["install", pkg])
subprocess.check_call([sys.executable, '-m', 'pip', 'install', pkg]) subprocess.check_call([sys.executable, "-m", "pip", "install", pkg])
importlib.import_module(pkg) importlib.import_module(pkg)
# third party package # third party package
@@ -47,11 +50,10 @@ import jsbeautifier
# sjva 공용 # sjva 공용
from framework import db, scheduler, path_data, socketio from framework import db, scheduler, path_data, socketio
from framework.util import Util from framework.util import Util
# from framework.common.util import headers # from framework.common.util import headers
from framework import F from framework import F
from plugin import ( from plugin import PluginModuleBase
PluginModuleBase
)
from .lib.ffmpeg_queue_v1 import FfmpegQueueEntity, FfmpegQueue from .lib.ffmpeg_queue_v1 import FfmpegQueueEntity, FfmpegQueue
from support.expand.ffmpeg import SupportFfmpeg from support.expand.ffmpeg import SupportFfmpeg
@@ -63,8 +65,8 @@ from .setup import *
logger = P.logger logger = P.logger
print('*=' * 50) print("*=" * 50)
name = 'ohli24' name = "ohli24"
class LogicOhli24(PluginModuleBase): class LogicOhli24(PluginModuleBase):
@@ -74,14 +76,13 @@ class LogicOhli24(PluginModuleBase):
session = requests.Session() session = requests.Session()
headers = { headers = {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.5249.114 Whale/3.17.145.12 Safari/537.36', "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.5249.114 Whale/3.17.145.12 Safari/537.36",
'authority': 'ndoodle.xyz', "authority": "ndoodle.xyz",
'accept': '*/*', "accept": "*/*",
'accept-language': 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7', "accept-language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7",
'cache-control': 'no-cache', "cache-control": "no-cache",
'pragma': 'no-cache', "pragma": "no-cache",
'referer': 'https://ndoodle.xyz/video/e6e31529675d0ef99d777d729c423382' "referer": "https://ndoodle.xyz/video/e6e31529675d0ef99d777d729c423382",
} }
useragent = { useragent = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, " "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, "
@@ -109,7 +110,7 @@ class LogicOhli24(PluginModuleBase):
"ohli24_auto_start": "False", "ohli24_auto_start": "False",
"ohli24_interval": "* 5 * * *", "ohli24_interval": "* 5 * * *",
"ohli24_auto_mode_all": "False", "ohli24_auto_mode_all": "False",
"ohli24_auto_code_list": "all", "ohli24_auto_code_list": "",
"ohli24_current_code": "", "ohli24_current_code": "",
"ohli24_uncompleted_auto_enqueue": "False", "ohli24_uncompleted_auto_enqueue": "False",
"ohli24_image_url_prefix_series": "https://www.jetcloud.cc/series/", "ohli24_image_url_prefix_series": "https://www.jetcloud.cc/series/",
@@ -118,7 +119,7 @@ class LogicOhli24(PluginModuleBase):
} }
self.queue = None self.queue = None
# default_route_socketio(P, self) # default_route_socketio(P, self)
default_route_socketio_module(self, attach='/queue') default_route_socketio_module(self, attach="/queue")
@staticmethod @staticmethod
def db_init(): def db_init():
@@ -251,9 +252,21 @@ class LogicOhli24(PluginModuleBase):
thread.daemon = True thread.daemon = True
thread.start() thread.start()
return jsonify("") return jsonify("")
elif sub == "web_list3":
print("web_list3")
print(request)
P.logger.debug(req)
P.logger.debug("web_list3")
ret = ModelOhli24Item.web_list(req)
print(ret)
# return jsonify("test")
# return jsonify(ModelOhli24Item.web_list(req))
elif sub == "web_list2": elif sub == "web_list2":
logger.debug("web_list2") logger.debug("web_list2")
return jsonify(ModelOhli24Item.web_list(request)) return jsonify(ModelOhli24Item.web_list(request))
elif sub == "db_remove": elif sub == "db_remove":
return jsonify(ModelOhli24Item.delete_by_id(req.form["id"])) return jsonify(ModelOhli24Item.delete_by_id(req.form["id"]))
elif sub == "add_whitelist": elif sub == "add_whitelist":
@@ -279,45 +292,51 @@ class LogicOhli24(PluginModuleBase):
def get_episode(self, clip_id): def get_episode(self, clip_id):
for _ in self.current_data["episode"]: for _ in self.current_data["episode"]:
if _['title'] == clip_id: if _["title"] == clip_id:
return _ return _
def process_command(self, command, arg1, arg2, arg3, req): def process_command(self, command, arg1, arg2, arg3, req):
ret = {'ret': 'success'} ret = {"ret": "success"}
if command == 'queue_list': if command == "queue_list":
logger.debug('queue_list') logger.debug("queue_list")
logger.debug(f"self.queue.get_entity_list():: {self.queue.get_entity_list()}") logger.debug(
f"self.queue.get_entity_list():: {self.queue.get_entity_list()}"
)
ret = [x for x in self.queue.get_entity_list()] ret = [x for x in self.queue.get_entity_list()]
return ret return ret
elif command == 'download_program': elif command == "download_program":
_pass = arg2 _pass = arg2
db_item = ModelOhli24Program.get(arg1) db_item = ModelOhli24Program.get(arg1)
if _pass == 'false' and db_item != None: if _pass == "false" and db_item != None:
ret['ret'] = 'warning' ret["ret"] = "warning"
ret['msg'] = '이미 DB에 있는 항목 입니다.' ret["msg"] = "이미 DB에 있는 항목 입니다."
elif _pass == 'true' and db_item != None and ModelOhli24Program.get_by_id_in_queue(db_item.id) != None: elif (
ret['ret'] = 'warning' _pass == "true"
ret['msg'] = '이미 큐에 있는 항목 입니다.' and db_item != None
and ModelOhli24Program.get_by_id_in_queue(db_item.id) != None
):
ret["ret"] = "warning"
ret["msg"] = "이미 큐에 있는 항목 입니다."
else: else:
if db_item == None: if db_item == None:
db_item = ModelOhli24Program(arg1, self.get_episode(arg1)) db_item = ModelOhli24Program(arg1, self.get_episode(arg1))
db_item.save() db_item.save()
db_item.init_for_queue() db_item.init_for_queue()
self.download_queue.put(db_item) self.download_queue.put(db_item)
ret['msg'] = '다운로드를 추가 하였습니다.' ret["msg"] = "다운로드를 추가 하였습니다."
elif command == 'list': elif command == "list":
ret = [] ret = []
for ins in SupportFfmpeg.get_list(): for ins in SupportFfmpeg.get_list():
ret.append(ins.get_data()) ret.append(ins.get_data())
elif command == 'queue_command': elif command == "queue_command":
if arg1 == 'cancel': if arg1 == "cancel":
pass pass
elif arg1 == 'reset': elif arg1 == "reset":
logger.debug('reset') logger.debug("reset")
# if self.queue is not None: # if self.queue is not None:
# with self.queue.mutex: # with self.queue.mutex:
# self.queue.queue.clear() # self.queue.queue.clear()
@@ -432,10 +451,12 @@ class LogicOhli24(PluginModuleBase):
elif len(content_code_list) > 0: elif len(content_code_list) > 0:
for item in content_code_list: for item in content_code_list:
url = P.ModelSetting.get("ohli24_url") + "/c/" + item url = P.ModelSetting.get("ohli24_url") + "/c/" + item
print("scheduling url: %s", url) logger.debug(f"scheduling url: {url}")
# ret_data = LogicOhli24.get_auto_anime_info(self, url=url) # ret_data = LogicOhli24.get_auto_anime_info(self, url=url)
content_info = self.get_series_info(item, "", "") content_info = self.get_series_info(item, "", "")
logger.debug(content_info)
for episode_info in content_info["episode"]: for episode_info in content_info["episode"]:
add_ret = self.add(episode_info) add_ret = self.add(episode_info)
if add_ret.startswith("enqueue"): if add_ret.startswith("enqueue"):
@@ -506,7 +527,7 @@ class LogicOhli24(PluginModuleBase):
else: else:
pass pass
logger.debug('url:::> %s', url) logger.debug("url:::> %s", url)
response_data = LogicOhli24.get_html(url, timeout=10) response_data = LogicOhli24.get_html(url, timeout=10)
tree = html.fromstring(response_data) tree = html.fromstring(response_data)
@@ -748,16 +769,13 @@ class LogicOhli24(PluginModuleBase):
return data return data
except Exception as e: except Exception as e:
P.logger.error("Exception:%s", e) P.logger.error(f"Exception: {str(e)}")
P.logger.error(traceback.format_exc()) P.logger.error(traceback.format_exc())
return {"ret": "exception", "log": str(e)} return {"ret": "exception", "log": str(e)}
# @staticmethod # @staticmethod
def plugin_load(self): def plugin_load(self):
try: try:
P.logger.debug(F.config['path_data'])
# SupportFfmpeg.initialize(ffmpeg_modelsetting.get('ffmpeg_path'), os.path.join(F.config['path_data'], 'tmp'), # SupportFfmpeg.initialize(ffmpeg_modelsetting.get('ffmpeg_path'), os.path.join(F.config['path_data'], 'tmp'),
# self.callback_function, ffmpeg_modelsetting.get_int('max_pf_count')) # self.callback_function, ffmpeg_modelsetting.get_int('max_pf_count'))
@@ -765,12 +783,19 @@ class LogicOhli24(PluginModuleBase):
# if self.download_queue is None: # if self.download_queue is None:
# self.download_queue = queue.Queue() # self.download_queue = queue.Queue()
SupportFfmpeg.initialize("ffmpeg", os.path.join(F.config['path_data'], 'tmp'), SupportFfmpeg.initialize(
self.callback_function, 1) "ffmpeg",
os.path.join(F.config["path_data"], "tmp"),
self.callback_function,
P.ModelSetting.get(f"{name}_max_ffmpeg_process_count"),
)
logger.debug("%s plugin_load", P.package_name) logger.debug("%s plugin_load", P.package_name)
self.queue = FfmpegQueue( self.queue = FfmpegQueue(
P, P.ModelSetting.get_int("ohli24_max_ffmpeg_process_count") P,
P.ModelSetting.get_int(f"{name}_max_ffmpeg_process_count"),
name,
self,
) )
self.current_data = None self.current_data = None
self.queue.queue_start() self.queue.queue_start()
@@ -827,6 +852,7 @@ class LogicOhli24(PluginModuleBase):
if self.is_exist(episode_info): if self.is_exist(episode_info):
return "queue_exist" return "queue_exist"
else: else:
logger.debug(f"episode_info:: {episode_info}")
db_entity = ModelOhli24Item.get_by_ohli24_id(episode_info["_id"]) db_entity = ModelOhli24Item.get_by_ohli24_id(episode_info["_id"])
logger.debug("db_entity:::> %s", db_entity) logger.debug("db_entity:::> %s", db_entity)
@@ -857,14 +883,14 @@ class LogicOhli24(PluginModuleBase):
# P.logger.debug(F.config['path_data']) # P.logger.debug(F.config['path_data'])
# P.logger.debug(self.headers) # P.logger.debug(self.headers)
filename = os.path.basename(entity.filepath) # filename = os.path.basename(entity.filepath)
ffmpeg = SupportFfmpeg(entity.url, entity.filename, callback_function=self.callback_function, # ffmpeg = SupportFfmpeg(entity.url, entity.filename, callback_function=self.callback_function,
max_pf_count=0, save_path=entity.savepath, timeout_minute=60, # max_pf_count=0, save_path=entity.savepath, timeout_minute=60,
headers=self.headers) # headers=self.headers)
ret = {'ret': 'success'} # ret = {'ret': 'success'}
ret['json'] = ffmpeg.start() # ret['json'] = ffmpeg.start()
# self.queue.add_queue(entity) self.queue.add_queue(entity)
return "enqueue_db_exist" return "enqueue_db_exist"
else: else:
return "db_completed" return "db_completed"
@@ -878,75 +904,111 @@ class LogicOhli24(PluginModuleBase):
# return False # return False
def callback_function(self, **args): def callback_function(self, **args):
logger.debug('callback_function============') logger.debug("callback_function============")
logger.debug(args) logger.debug(args)
refresh_type = None refresh_type = None
if args['type'] == 'status_change': if args["type"] == "status_change":
if args['status'] == SupportFfmpeg.Status.DOWNLOADING: if args["status"] == SupportFfmpeg.Status.DOWNLOADING:
refresh_type = 'status_change' refresh_type = "status_change"
elif args['status'] == SupportFfmpeg.Status.COMPLETED: elif args["status"] == SupportFfmpeg.Status.COMPLETED:
refresh_type = 'status_change' refresh_type = "status_change"
elif args['status'] == SupportFfmpeg.Status.READY: logger.debug("mod_ohli24.py:: download completed........")
data = {'type': 'info', elif args["status"] == SupportFfmpeg.Status.READY:
'msg': '다운로드중 Duration(%s)' % args['data']['duration_str'] + '<br>' + args['data'][ data = {
'save_fullpath'], 'url': '/ffmpeg/download/list'} "type": "info",
"msg": "다운로드중 Duration(%s)" % args["data"]["duration_str"]
+ "<br>"
+ 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' refresh_type = "add"
elif args['type'] == 'last': elif args["type"] == "last":
if args['status'] == SupportFfmpeg.Status.WRONG_URL: if args["status"] == SupportFfmpeg.Status.WRONG_URL:
data = {'type': 'warning', 'msg': '잘못된 URL입니다'} data = {"type": "warning", "msg": "잘못된 URL입니다"}
socketio.emit("notify", data, namespace='/framework', broadcast=True) socketio.emit("notify", data, namespace="/framework", broadcast=True)
refresh_type = 'add' refresh_type = "add"
elif args['status'] == SupportFfmpeg.Status.WRONG_DIRECTORY: elif args["status"] == SupportFfmpeg.Status.WRONG_DIRECTORY:
data = {'type': 'warning', 'msg': '잘못된 디렉토리입니다.<br>' + args['data']['save_fullpath']} data = {
socketio.emit("notify", data, namespace='/framework', broadcast=True) "type": "warning",
refresh_type = 'add' "msg": "잘못된 디렉토리입니다.<br>" + args["data"]["save_fullpath"],
elif args['status'] == SupportFfmpeg.Status.ERROR or args['status'] == SupportFfmpeg.Status.EXCEPTION: }
data = {'type': 'warning', 'msg': '다운로드 시작 실패.<br>' + args['data']['save_fullpath']} socketio.emit("notify", data, namespace="/framework", broadcast=True)
socketio.emit("notify", data, namespace='/framework', broadcast=True) refresh_type = "add"
refresh_type = 'add' elif (
elif args['status'] == SupportFfmpeg.Status.USER_STOP: args["status"] == SupportFfmpeg.Status.ERROR
data = {'type': 'warning', 'msg': '다운로드가 중지 되었습니다.<br>' + args['data']['save_fullpath'], or args["status"] == SupportFfmpeg.Status.EXCEPTION
'url': '/ffmpeg/download/list'} ):
socketio.emit("notify", data, namespace='/framework', broadcast=True) data = {
refresh_type = 'last' "type": "warning",
elif args['status'] == SupportFfmpeg.Status.COMPLETED: "msg": "다운로드 시작 실패.<br>" + args["data"]["save_fullpath"],
data = {'type': 'success', 'msg': '다운로드가 완료 되었습니다.<br>' + args['data']['save_fullpath'], }
'url': '/ffmpeg/download/list'} socketio.emit("notify", data, namespace="/framework", broadcast=True)
refresh_type = "add"
elif args["status"] == SupportFfmpeg.Status.USER_STOP:
data = {
"type": "warning",
"msg": "다운로드가 중지 되었습니다.<br>" + 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:
logger.debug("download completed........")
data = {
"type": "success",
"msg": "다운로드가 완료 되었습니다.<br>" + 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' refresh_type = "last"
elif args['status'] == SupportFfmpeg.Status.TIME_OVER: elif args["status"] == SupportFfmpeg.Status.TIME_OVER:
data = {'type': 'warning', 'msg': '시간초과로 중단 되었습니다.<br>' + args['data']['save_fullpath'], data = {
'url': '/ffmpeg/download/list'} "type": "warning",
socketio.emit("notify", data, namespace='/framework', broadcast=True) "msg": "시간초과로 중단 되었습니다.<br>" + args["data"]["save_fullpath"],
refresh_type = 'last' "url": "/ffmpeg/download/list",
elif args['status'] == SupportFfmpeg.Status.PF_STOP: }
data = {'type': 'warning', 'msg': 'PF초과로 중단 되었습니다.<br>' + args['data']['save_fullpath'], socketio.emit("notify", data, namespace="/framework", broadcast=True)
'url': '/ffmpeg/download/list'} refresh_type = "last"
socketio.emit("notify", data, namespace='/framework', broadcast=True) elif args["status"] == SupportFfmpeg.Status.PF_STOP:
refresh_type = 'last' data = {
elif args['status'] == SupportFfmpeg.Status.FORCE_STOP: "type": "warning",
data = {'type': 'warning', 'msg': '강제 중단 되었습니다.<br>' + args['data']['save_fullpath'], "msg": "PF초과로 중단 되었습니다.<br>" + args["data"]["save_fullpath"],
'url': '/ffmpeg/download/list'} "url": "/ffmpeg/download/list",
socketio.emit("notify", data, namespace='/framework', broadcast=True) }
refresh_type = 'last' socketio.emit("notify", data, namespace="/framework", broadcast=True)
elif args['status'] == SupportFfmpeg.Status.HTTP_FORBIDDEN: refresh_type = "last"
data = {'type': 'warning', 'msg': '403에러로 중단 되었습니다.<br>' + args['data']['save_fullpath'], elif args["status"] == SupportFfmpeg.Status.FORCE_STOP:
'url': '/ffmpeg/download/list'} data = {
socketio.emit("notify", data, namespace='/framework', broadcast=True) "type": "warning",
refresh_type = 'last' "msg": "강제 중단 되었습니다.<br>" + args["data"]["save_fullpath"],
elif args['status'] == SupportFfmpeg.Status.ALREADY_DOWNLOADING: "url": "/ffmpeg/download/list",
data = {'type': 'warning', 'msg': '임시파일폴더에 파일이 있습니다.<br>' + args['data']['temp_fullpath'], }
'url': '/ffmpeg/download/list'} socketio.emit("notify", data, namespace="/framework", broadcast=True)
socketio.emit("notify", data, namespace='/framework', broadcast=True) refresh_type = "last"
refresh_type = 'last' elif args["status"] == SupportFfmpeg.Status.HTTP_FORBIDDEN:
elif args['type'] == 'normal': data = {
if args['status'] == SupportFfmpeg.Status.DOWNLOADING: "type": "warning",
refresh_type = 'status' "msg": "403에러로 중단 되었습니다.<br>" + 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": "임시파일폴더에 파일이 있습니다.<br>" + 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) # P.logger.info(refresh_type)
self.socketio_callback(refresh_type, args['data']) self.socketio_callback(refresh_type, args["data"])
class Ohli24QueueEntity(FfmpegQueueEntity): class Ohli24QueueEntity(FfmpegQueueEntity):
@@ -981,7 +1043,8 @@ class Ohli24QueueEntity(FfmpegQueueEntity):
tmp["epi_queue"] = self.epi_queue tmp["epi_queue"] = self.epi_queue
return tmp return tmp
def donwload_completed(self): def download_completed(self):
logger.debug("download completed.......!!")
db_entity = ModelOhli24Item.get_by_ohli24_id(self.info["_id"]) db_entity = ModelOhli24Item.get_by_ohli24_id(self.info["_id"])
if db_entity is not None: if db_entity is not None:
db_entity.status = "completed" db_entity.status = "completed"
@@ -993,7 +1056,7 @@ class Ohli24QueueEntity(FfmpegQueueEntity):
def make_episode_info(self): def make_episode_info(self):
try: try:
# url = 'https://ohli24.net/e/' + self.info['va'] # url = 'https://ohli24.net/e/' + self.info['va']
base_url = "https://ohli24.net" base_url = "https://ohli24.org"
iframe_url = "" iframe_url = ""
# https://ohli24.net/e/%EB%85%B9%EC%9D%84%20%EB%A8%B9%EB%8A%94%20%EB%B9%84%EC%8A%A4%EC%BD%94%206%ED%99%94 # https://ohli24.net/e/%EB%85%B9%EC%9D%84%20%EB%A8%B9%EB%8A%94%20%EB%B9%84%EC%8A%A4%EC%BD%94%206%ED%99%94
@@ -1002,13 +1065,17 @@ class Ohli24QueueEntity(FfmpegQueueEntity):
ourls = parse.urlparse(url) ourls = parse.urlparse(url)
headers = { headers = {
"referer": f"{ourls.scheme}://{ourls.netloc}", "Referer": f"{ourls.scheme}://{ourls.netloc}",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Whale/3.12.129.46 Safari/537.36", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/96.0.4664.110 Whale/3.12.129.46 Safari/537.36",
} }
logger.debug("make_episode_info()::url==> %s", url) logger.debug("make_episode_info()::url==> %s", url)
logger.info(f"self.info:::> {self.info}") logger.info(f"self.info:::> {self.info}")
text = requests.get(url, headers=headers).text # text = requests.get(url, headers=headers).text
text = LogicOhli24.get_html(
url, headers=headers, referer=f"{ourls.scheme}://{ourls.netloc}"
)
# logger.debug(text) # logger.debug(text)
soup1 = BeautifulSoup(text, "lxml") soup1 = BeautifulSoup(text, "lxml")
pattern = re.compile(r"url : \"\.\.(.*)\"") pattern = re.compile(r"url : \"\.\.(.*)\"")
@@ -1047,7 +1114,7 @@ class Ohli24QueueEntity(FfmpegQueueEntity):
) )
packed_script = soup3.find("script", text=s_pattern) packed_script = soup3.find("script", text=s_pattern)
# packed_script = soup3.find('script') # packed_script = soup3.find('script')
logger.info('packed_script>>> %s', packed_script.text) logger.info("packed_script>>> %s", packed_script.text)
unpack_script = None unpack_script = None
if packed_script is not None: if packed_script is not None:
# logger.debug('zzzzzzzzzzzz') # logger.debug('zzzzzzzzzzzz')
@@ -1184,8 +1251,11 @@ class Ohli24QueueEntity(FfmpegQueueEntity):
self.savepath, self.filename.replace(".mp4", ".ko.srt") self.savepath, self.filename.replace(".mp4", ".ko.srt")
) )
if self.srt_url is not None and not os.path.exists(srt_filepath) and not self.srt_url.split("/")[ if (
-1] == 'thumbnails.vtt': self.srt_url is not None
and not os.path.exists(srt_filepath)
and not self.srt_url.split("/")[-1] == "thumbnails.vtt"
):
if requests.get(self.srt_url, headers=headers).status_code == 200: if requests.get(self.srt_url, headers=headers).status_code == 200:
srt_data = requests.get(self.srt_url, headers=headers).text srt_data = requests.get(self.srt_url, headers=headers).text
Util.write_file(srt_data, srt_filepath) Util.write_file(srt_data, srt_filepath)
@@ -1194,8 +1264,85 @@ class Ohli24QueueEntity(FfmpegQueueEntity):
P.logger.error("Exception:%s", e) P.logger.error("Exception:%s", e)
P.logger.error(traceback.format_exc()) P.logger.error(traceback.format_exc())
# def callback_function(self, **args):
# refresh_type = None
# # entity = self.get_entity_by_entity_id(arg['plugin_id'])
# entity = self.get_entity_by_entity_id(args['data']['callback_id'])
#
# 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'
# logger.debug('ffmpeg_queue_v1.py:: download completed........')
# elif args['status'] == SupportFfmpeg.Status.READY:
# data = {'type': 'info',
# 'msg': '다운로드중 Duration(%s)' % args['data']['duration_str'] + '<br>' + 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': '잘못된 디렉토리입니다.<br>' + 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': '다운로드 시작 실패.<br>' + 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': '다운로드가 중지 되었습니다.<br>' + 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:
# logger.debug('ffmpeg download completed......')
# entity.download_completed()
# data = {'type': 'success', 'msg': '다운로드가 완료 되었습니다.<br>' + 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': '시간초과로 중단 되었습니다.<br>' + 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초과로 중단 되었습니다.<br>' + 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': '강제 중단 되었습니다.<br>' + 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에러로 중단 되었습니다.<br>' + 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': '임시파일폴더에 파일이 있습니다.<br>' + 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)
# # Todo:
# self.socketio_callback(refresh_type, args['data'])
class ModelOhli24Item(db.Model):
class ModelOhli24Item(ModelBase):
P = P
__tablename__ = "{package_name}_ohli24_item".format(package_name=P.package_name) __tablename__ = "{package_name}_ohli24_item".format(package_name=P.package_name)
__table_args__ = {"mysql_collate": "utf8_general_ci"} __table_args__ = {"mysql_collate": "utf8_general_ci"}
__bind_key__ = P.package_name __bind_key__ = P.package_name
@@ -1238,16 +1385,32 @@ class ModelOhli24Item(db.Model):
return ret return ret
def save(self): def save(self):
db.session.add(self) try:
db.session.commit() with F.app.app_context():
F.db.session.add(self)
F.db.session.commit()
return self
except Exception as e:
self.P.logger.error(f"Exception:{str(e)}")
self.P.logger.error(traceback.format_exc())
@classmethod @classmethod
def get_by_id(cls, idx): def get_by_id(cls, id):
return db.session.query(cls).filter_by(id=idx).first() try:
with F.app.app_context():
return F.db.session.query(cls).filter_by(id=int(id)).first()
except Exception as e:
cls.P.logger.error(f"Exception:{str(e)}")
cls.P.logger.error(traceback.format_exc())
@classmethod @classmethod
def get_by_ohli24_id(cls, ohli24_id): def get_by_ohli24_id(cls, ohli24_id):
return db.session.query(cls).filter_by(ohli24_id=ohli24_id).first() try:
with F.app.app_context():
return F.db.session.query(cls).filter_by(ohli24_id=ohli24_id).first()
except Exception as e:
cls.P.logger.error(f"Exception:{str(e)}")
cls.P.logger.error(traceback.format_exc())
@classmethod @classmethod
def delete_by_id(cls, idx): def delete_by_id(cls, idx):
@@ -1269,7 +1432,7 @@ class ModelOhli24Item(db.Model):
query = query.limit(page_size).offset((page - 1) * page_size) query = query.limit(page_size).offset((page - 1) * page_size)
lists = query.all() lists = query.all()
ret["list"] = [item.as_dict() for item in lists] ret["list"] = [item.as_dict() for item in lists]
ret["paging"] = Util.get_paging_info(count, page, page_size) ret["paging"] = cls.get_paging_info(count, page, page_size)
return ret return ret
@classmethod @classmethod
@@ -1327,8 +1490,8 @@ class ModelOhli24Item(db.Model):
class ModelOhli24Program(ModelBase): class ModelOhli24Program(ModelBase):
P = P P = P
__tablename__ = f'{P.package_name}_{name}_program' __tablename__ = f"{P.package_name}_{name}_program"
__table_args__ = {'mysql_collate': 'utf8_general_ci'} __table_args__ = {"mysql_collate": "utf8_general_ci"}
__bind_key__ = P.package_name __bind_key__ = P.package_name
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
@@ -1342,7 +1505,7 @@ class ModelOhli24Program(ModelBase):
call = db.Column(db.String) call = db.Column(db.String)
queue_list = [] queue_list = []
def __init__(self, clip_id, info, call='user'): def __init__(self, clip_id, info, call="user"):
self.clip_id = clip_id self.clip_id = clip_id
self.info = info self.info = info
self.completed = False self.completed = False
@@ -1357,29 +1520,34 @@ class ModelOhli24Program(ModelBase):
@classmethod @classmethod
def get(cls, clip_id): def get(cls, clip_id):
with F.app.app_context(): with F.app.app_context():
return db.session.query(cls).filter_by( return (
db.session.query(cls)
.filter_by(
clip_id=clip_id, clip_id=clip_id,
).order_by(desc(cls.id)).first() )
.order_by(desc(cls.id))
.first()
)
@classmethod @classmethod
def is_duplicate(cls, clip_id): def is_duplicate(cls, clip_id):
return (cls.get(clip_id) != None) return cls.get(clip_id) != None
# 오버라이딩 # 오버라이딩
@classmethod @classmethod
def make_query(cls, req, order='desc', search='', option1='all', option2='all'): def make_query(cls, req, order="desc", search="", option1="all", option2="all"):
with F.app.app_context(): with F.app.app_context():
query = F.db.session.query(cls) query = F.db.session.query(cls)
# query = cls.make_query_search(query, search, cls.program_title) # query = cls.make_query_search(query, search, cls.program_title)
query = query.filter(cls.info['channel_name'].like('%' + search + '%')) query = query.filter(cls.info["channel_name"].like("%" + search + "%"))
if option1 == 'completed': if option1 == "completed":
query = query.filter_by(completed=True) query = query.filter_by(completed=True)
elif option1 == 'incompleted': elif option1 == "incompleted":
query = query.filter_by(completed=False) query = query.filter_by(completed=False)
elif option1 == 'auto': elif option1 == "auto":
query = query.filter_by(call="user") query = query.filter_by(call="user")
if order == 'desc': if order == "desc":
query = query.order_by(desc(cls.id)) query = query.order_by(desc(cls.id))
else: else:
query = query.order_by(cls.id) query = query.order_by(cls.id)
@@ -1395,9 +1563,7 @@ class ModelOhli24Program(ModelBase):
@classmethod @classmethod
def get_failed(cls): def get_failed(cls):
with F.app.app_context(): with F.app.app_context():
return db.session.query(cls).filter_by( return db.session.query(cls).filter_by(completed=False).all()
completed=False
).all()
### only for queue ### only for queue
@classmethod @classmethod
@@ -1405,4 +1571,5 @@ class ModelOhli24Program(ModelBase):
for _ in cls.queue_list: for _ in cls.queue_list:
if _.id == int(id): if _.id == int(id):
return _ return _
### only for queue END ### only for queue END

View File

@@ -16,7 +16,8 @@
</select> </select>
</span> </span>
<span class="col-md-8"> <span class="col-md-8">
<input id="search_word" name="search_word" class="form-control form-control-sm w-75" type="text" placeholder="" aria-label="Search"> <input id="search_word" name="search_word" class="form-control form-control-sm w-75" type="text"
placeholder="" aria-label="Search">
<button id="search" class="btn btn-sm btn-outline-success">검색</button> <button id="search" class="btn btn-sm btn-outline-success">검색</button>
<button id="reset_btn" class="btn btn-sm btn-outline-success">리셋</button> <button id="reset_btn" class="btn btn-sm btn-outline-success">리셋</button>
</span> </span>
@@ -44,13 +45,35 @@ var current_data = null;
$(document).ready(function () { $(document).ready(function () {
{#global_sub_request_search('1');#} {#global_sub_request_search('1');#}
console.log('ready') console.log('ready')
globalRequestSearch2('1'); globalRequestSearchTest('1');
}); });
function globalRequestSearchTest(page, move_top = true) {
console.log('........................')
var formData = getFormdata('#form_search')
formData += '&page=' + page;
$.ajax({
{#url: '/' + PACKAGE_NAME + '/ajax/' + MODULE_NAME + '/web_list2',#}
url: '/' + package_name + '/ajax/' + sub + '/web_list3',
type: "POST",
cache: false,
data: formData,
dataType: "json",
success: function (data) {
console.log(data)
current_data = data;
{#if (move_top)#}
{# window.scrollTo(0,0);#}
{#make_list(data.list)#}
{#make_page_html(data.paging)#}
}
});
}
$("#search").click(function (e) { $("#search").click(function (e) {
e.preventDefault(); e.preventDefault();
{#global_sub_request_search('1');#} {#global_sub_request_search('1');#}
globalRequestSearch2('1'); globalRequestSearch('1');
}); });
$("body").on('click', '#page', function (e) { $("body").on('click', '#page', function (e) {
@@ -115,7 +138,6 @@ $("body").on('click', '#request_btn', function(e){
}); });
function make_list(data) { function make_list(data) {
//console.log(data) //console.log(data)
str = ''; str = '';
@@ -143,7 +165,5 @@ function make_list(data) {
} }
</script> </script>
{% endblock %} {% endblock %}

View File

@@ -17,6 +17,8 @@
<div id="download_list_div"></div> <div id="download_list_div"></div>
</div> <!--전체--> </div> <!--전체-->
<script src="{{ url_for('.static', filename='js/sjva_ui14.js') }}"></script>
<script type="text/javascript"> <script type="text/javascript">
var package_name = "{{arg['package_name'] }}"; var package_name = "{{arg['package_name'] }}";
var sub = "{{arg['sub'] }}"; var sub = "{{arg['sub'] }}";
@@ -41,7 +43,7 @@
}); });
socket.on('status', function (data) { socket.on('status', function (data) {
console.log(data); // console.log(data);
on_status(data) on_status(data)
}); });
@@ -57,6 +59,7 @@
data: {}, data: {},
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
console.log("on_start():: ", data)
make_download_list(data) make_download_list(data)
} }
}); });
@@ -64,11 +67,12 @@
function on_status(data) { function on_status(data) {
//console.log(data) console.log(data)
tmp = document.getElementById("progress_" + data.entity_id) console.log(data.percent)
tmp = document.getElementById("progress_" + data.idx)
if (tmp != null) { if (tmp != null) {
document.getElementById("progress_" + data.entity_id).style.width = data.ffmpeg_percent + '%'; document.getElementById("progress_" + data.idx).style.width = data.percent + '%';
document.getElementById("progress_" + data.entity_id + "_label").innerHTML = data.ffmpeg_status_kor + "(" + data.ffmpeg_percent + "%)" + ' ' + ((data.ffmpeg_arg != null) ? data.ffmpeg_arg.data.current_speed : '') document.getElementById("progress_" + data.idx + "_label").innerHTML = data.status_kor + "(" + data.percent + "%)" + ' ' + ((data.current_speed != null) ? data.current_speed : '')
} }
} }
@@ -138,4 +142,10 @@
}); });
</script> </script>
<style>
#progress_1_label {
color: #966f93;
font-weight: 700;
}
</style>
{% endblock %} {% endblock %}