119 lines
4.2 KiB
Python
119 lines
4.2 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
# @Time : 2023/02/25 7:29 PM
|
||
|
|
# @Author : yommi
|
||
|
|
# @Site :
|
||
|
|
# @File : mod_basic
|
||
|
|
# @Software: PyCharm
|
||
|
|
# @Path : youtube-dl/mod_basic.py
|
||
|
|
from support import SupportYaml
|
||
|
|
from tool import ToolUtil
|
||
|
|
|
||
|
|
from .setup import *
|
||
|
|
|
||
|
|
# from .main import LogicMain
|
||
|
|
from .my_youtube_dl import MyYoutubeDL, Status
|
||
|
|
import platform
|
||
|
|
import os
|
||
|
|
from .model import ModelYoutubeDlItem
|
||
|
|
from loguru import logger
|
||
|
|
|
||
|
|
|
||
|
|
class ModuleBasic(PluginModuleBase):
|
||
|
|
def __init__(self, P):
|
||
|
|
super(ModuleBasic, self).__init__(
|
||
|
|
P, name="basic", first_menu="setting", scheduler_desc="유튜브 다운로더"
|
||
|
|
)
|
||
|
|
self.db_default = {
|
||
|
|
"db_version": "2",
|
||
|
|
"youtube_dl_package": "1",
|
||
|
|
"ffmpeg_path": ""
|
||
|
|
if platform.system() != "Windows"
|
||
|
|
else os.path.join("PATH_APP_ROOT", "bin", "Windows", "ffmpeg.exe"),
|
||
|
|
"temp_path": os.path.join("{PATH_DATA}", "download_tmp"),
|
||
|
|
"save_path": os.path.join("{PATH_DATA}", "download"),
|
||
|
|
"default_filename": "",
|
||
|
|
"proxy": "",
|
||
|
|
}
|
||
|
|
self.web_list_model = ModelYoutubeDlItem
|
||
|
|
|
||
|
|
def process_menu(self, sub, req):
|
||
|
|
logger.debug(f"sub: {sub}")
|
||
|
|
arg = P.ModelSetting.to_dict()
|
||
|
|
logger.debug(f"arg:: {arg}")
|
||
|
|
if sub == "setting":
|
||
|
|
arg["is_include"] = F.scheduler.is_include(self.get_scheduler_name())
|
||
|
|
arg["is_running"] = F.scheduler.is_running(self.get_scheduler_name())
|
||
|
|
|
||
|
|
elif sub == "download":
|
||
|
|
default_filename = P.ModelSetting.get("default_filename")
|
||
|
|
arg["filename"] = (
|
||
|
|
default_filename
|
||
|
|
if default_filename
|
||
|
|
else ModuleBasic.get_default_filename()
|
||
|
|
)
|
||
|
|
arg["preset_list"] = ModuleBasic.get_preset_list()
|
||
|
|
arg["postprocessor_list"] = ModuleBasic.get_postprocessor_list()
|
||
|
|
|
||
|
|
return render_template(f"{P.package_name}_{self.name}_{sub}.html", arg=arg)
|
||
|
|
|
||
|
|
def process_command(self, command, arg1, arg2, arg3, req):
|
||
|
|
ret = {"ret": "success"}
|
||
|
|
return jsonify(ret)
|
||
|
|
|
||
|
|
# def plugin_load(self):
|
||
|
|
# if (
|
||
|
|
# os.path.exists(
|
||
|
|
# ToolUtil.make_path(P.ModelSetting.get(f"{self.name}_path_config"))
|
||
|
|
# )
|
||
|
|
# is False
|
||
|
|
# ):
|
||
|
|
# shutil.copyfile(
|
||
|
|
# os.path.join(
|
||
|
|
# os.path.dirname(__file__), "files", f"config_{self.name}.yaml"
|
||
|
|
# ),
|
||
|
|
# ToolUtil.make_path(P.ModelSetting.get(f"{self.name}_path_config")),
|
||
|
|
# )
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def get_default_filename():
|
||
|
|
return MyYoutubeDL.DEFAULT_FILENAME
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def get_preset_list():
|
||
|
|
return [
|
||
|
|
["bestvideo+bestaudio/best", "최고 화질"],
|
||
|
|
["bestvideo[height<=1080]+bestaudio/best[height<=1080]", "1080p"],
|
||
|
|
["worstvideo+worstaudio/worst", "최저 화질"],
|
||
|
|
["bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]", "최고 화질(mp4)"],
|
||
|
|
[
|
||
|
|
"bestvideo[ext=mp4][height<=1080]+bestaudio[ext=m4a]/best[ext=mp4][height<=1080]",
|
||
|
|
"1080p(mp4)",
|
||
|
|
],
|
||
|
|
["bestvideo[filesize<50M]+bestaudio/best[filesize<50M]", "50MB 미만"],
|
||
|
|
["bestaudio/best", "오디오만"],
|
||
|
|
["_custom", "사용자 정의"],
|
||
|
|
]
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def get_postprocessor_list():
|
||
|
|
return [
|
||
|
|
["", "후처리 안함", None],
|
||
|
|
["mp4", "MP4", "비디오 변환"],
|
||
|
|
["flv", "FLV", "비디오 변환"],
|
||
|
|
["webm", "WebM", "비디오 변환"],
|
||
|
|
["ogg", "Ogg", "비디오 변환"],
|
||
|
|
["mkv", "MKV", "비디오 변환"],
|
||
|
|
["ts", "TS", "비디오 변환"],
|
||
|
|
["avi", "AVI", "비디오 변환"],
|
||
|
|
["wmv", "WMV", "비디오 변환"],
|
||
|
|
["mov", "MOV", "비디오 변환"],
|
||
|
|
["gif", "GIF", "비디오 변환"],
|
||
|
|
["mp3", "MP3", "오디오 추출"],
|
||
|
|
["aac", "AAC", "오디오 추출"],
|
||
|
|
["flac", "FLAC", "오디오 추출"],
|
||
|
|
["m4a", "M4A", "오디오 추출"],
|
||
|
|
["opus", "Opus", "오디오 추출"],
|
||
|
|
["vorbis", "Vorbis", "오디오 추출"],
|
||
|
|
["wav", "WAV", "오디오 추출"],
|
||
|
|
]
|