2020-02-05 20:54:30 +09:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
#########################################################
|
|
|
|
|
# python
|
|
|
|
|
import os
|
2020-03-16 14:14:37 +09:00
|
|
|
import sys
|
2020-07-25 03:06:03 +09:00
|
|
|
import platform
|
2020-02-15 16:27:18 +09:00
|
|
|
import subprocess
|
2020-02-05 20:54:30 +09:00
|
|
|
import traceback
|
|
|
|
|
|
|
|
|
|
# third-party
|
|
|
|
|
|
|
|
|
|
# sjva 공용
|
2020-07-25 03:06:03 +09:00
|
|
|
from framework import db, path_app_root, path_data
|
2020-02-05 20:54:30 +09:00
|
|
|
from framework.util import Util
|
|
|
|
|
|
|
|
|
|
# 패키지
|
|
|
|
|
from .plugin import logger, package_name
|
|
|
|
|
from .model import ModelSetting
|
|
|
|
|
#########################################################
|
|
|
|
|
|
|
|
|
|
class Logic(object):
|
2020-07-23 23:00:02 +09:00
|
|
|
db_default = {
|
|
|
|
|
'db_version': '1',
|
2020-08-08 15:01:46 +09:00
|
|
|
'ffmpeg_path': '' if platform.system() != 'Windows' else os.path.join(path_app_root, 'bin', 'Windows', 'ffmpeg.exe'),
|
2020-07-23 23:00:02 +09:00
|
|
|
'temp_path': os.path.join(path_data, 'download_tmp'),
|
|
|
|
|
'save_path': os.path.join(path_data, 'download'),
|
2020-08-08 15:01:46 +09:00
|
|
|
'default_filename': '',
|
2020-07-23 23:00:02 +09:00
|
|
|
'proxy': '',
|
|
|
|
|
'activate_cors': False
|
|
|
|
|
}
|
2020-02-05 20:54:30 +09:00
|
|
|
|
2020-07-23 23:00:02 +09:00
|
|
|
@staticmethod
|
|
|
|
|
def db_init():
|
|
|
|
|
try:
|
|
|
|
|
for key, value in Logic.db_default.items():
|
|
|
|
|
if db.session.query(ModelSetting).filter_by(key=key).count() == 0:
|
|
|
|
|
db.session.add(ModelSetting(key, value))
|
|
|
|
|
db.session.commit()
|
|
|
|
|
# Logic.migration()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error('Exception:%s', e)
|
|
|
|
|
logger.error(traceback.format_exc())
|
2020-02-05 20:54:30 +09:00
|
|
|
|
2020-07-23 23:00:02 +09:00
|
|
|
@staticmethod
|
|
|
|
|
def plugin_load():
|
|
|
|
|
try:
|
|
|
|
|
logger.debug('%s plugin_load', package_name)
|
|
|
|
|
Logic.db_init()
|
2020-02-09 18:51:58 +09:00
|
|
|
|
2020-07-25 03:06:03 +09:00
|
|
|
# 모듈 설치
|
2020-07-23 23:00:02 +09:00
|
|
|
try:
|
|
|
|
|
import glob2
|
|
|
|
|
except ImportError:
|
|
|
|
|
logger.debug('glob2 install')
|
|
|
|
|
logger.debug(subprocess.check_output([sys.executable, '-m', 'pip', 'install', 'glob2'], universal_newlines=True))
|
2020-03-15 15:29:32 +09:00
|
|
|
|
2020-07-23 23:00:02 +09:00
|
|
|
# youtube-dl 업데이트
|
|
|
|
|
logger.debug('youtube-dl upgrade')
|
|
|
|
|
logger.debug(subprocess.check_output([sys.executable, '-m', 'pip', 'install', '--upgrade', 'youtube-dl'], universal_newlines=True))
|
2020-02-05 20:54:30 +09:00
|
|
|
|
2020-07-23 23:00:02 +09:00
|
|
|
# 편의를 위해 json 파일 생성
|
2020-11-08 16:06:34 +09:00
|
|
|
from .plugin import plugin_info
|
2020-07-23 23:00:02 +09:00
|
|
|
Util.save_from_dict_to_json(plugin_info, os.path.join(os.path.dirname(__file__), 'info.json'))
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error('Exception:%s', e)
|
|
|
|
|
logger.error(traceback.format_exc())
|
2020-02-05 20:54:30 +09:00
|
|
|
|
2020-07-23 23:00:02 +09:00
|
|
|
@staticmethod
|
|
|
|
|
def plugin_unload():
|
|
|
|
|
try:
|
|
|
|
|
logger.debug('%s plugin_unload', package_name)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error('Exception:%s', e)
|
|
|
|
|
logger.error(traceback.format_exc())
|