95 lines
3.9 KiB
HTML
95 lines
3.9 KiB
HTML
{% extends "base.html" %}
|
|
|
|
{% macro my_setting_select(id, title, options, col='9', desc=None, value=None) %}
|
|
{{ macros.setting_top(title) }}
|
|
<div class="input-group col-sm-{{ col }}">
|
|
<select id="{{ id }}" name="{{ id }}" class="form-control form-control-sm">
|
|
{% set ns = namespace(optgroup=none) %}
|
|
{% for item in options %}
|
|
{% if ns.optgroup != item[2] %}
|
|
{% if ns.optgroup is not none %}
|
|
</optgroup>
|
|
{% endif %}
|
|
{% if item[2] is not none %}
|
|
<optgroup label="{{ item[2] }}">
|
|
{% endif %}
|
|
{% set ns.optgroup = item[2] %}
|
|
{% endif %}
|
|
{% if value is not none and value == item[0] %}
|
|
<option value="{{ item[0] }}" selected>{{ item[1] }}</option>
|
|
{% else %}
|
|
<option value="{{ item[0] }}">{{ item[1] }}</option>
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% if ns.optgroup is not none %}
|
|
</optgroup>
|
|
{% endif %}
|
|
</select>
|
|
</div>
|
|
{{ macros.setting_bottom(desc) }}
|
|
{% endmacro %}
|
|
|
|
{% block content %}
|
|
|
|
<form id="download">
|
|
{{ macros.setting_input_text('url', 'URL', placeholder='http:// 주소', desc='유튜브, 네이버TV 등 동영상 주소') }}
|
|
{{ macros.setting_input_text('filename', '파일명', value=arg['filename'], desc='템플릿 규칙은 https://github.com/ytdl-org/youtube-dl/#output-template 참고') }}
|
|
{{ macros.setting_select('preset', '동영상 포맷 프리셋', arg['preset_list'], col='3') }}
|
|
{{ macros.setting_input_text('format', '동영상 포맷', desc=['포맷 지정은 https://github.com/ytdl-org/youtube-dl/#format-selection 참고', '빈칸으로 두면 최고 화질로 다운로드합니다.']) }}
|
|
{{ my_setting_select('postprocessor', '후처리', arg['postprocessor_list'], col='3', desc='다운로드 후 FFmpeg로 후처리합니다.') }}
|
|
{{ macros.setting_button([['download_btn', '다운로드']]) }}
|
|
</form>
|
|
|
|
<script>
|
|
"use strict";
|
|
const package_name = '{{ arg["package_name"] }}';
|
|
|
|
// 프리셋 변경
|
|
const preset = document.getElementById('preset');
|
|
const format = document.getElementById('format');
|
|
preset.addEventListener('change', () => {
|
|
if (preset.value !== '_custom') {
|
|
format.value = preset.value;
|
|
}
|
|
});
|
|
format.addEventListener('input', () => {
|
|
preset.value = '_custom';
|
|
});
|
|
|
|
// 후처리 변경
|
|
const postprocessor = document.getElementById('postprocessor');
|
|
postprocessor.addEventListener('change', () => {
|
|
const select = postprocessor.selectedOptions[0];
|
|
if (select.parentElement.label === '오디오 추출') {
|
|
preset.value = 'bestaudio/best';
|
|
format.value = preset.value;
|
|
}
|
|
});
|
|
|
|
// 다운로드
|
|
const download_btn = document.getElementById('download_btn');
|
|
download_btn.addEventListener('click', (event) => {
|
|
event.preventDefault();
|
|
const url = document.getElementById('url').value;
|
|
if (!url.startsWith('http')) {
|
|
notify('URL을 입력하세요.', 'warning');
|
|
return;
|
|
}
|
|
|
|
fetch(`/${package_name}/ajax/download`, {
|
|
method: 'POST',
|
|
cache: 'no-cache',
|
|
headers: {
|
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
|
|
},
|
|
body: get_formdata('#download')
|
|
}).then(response => response.json()).then(() => {
|
|
notify('분석중..', 'info');
|
|
}).catch(() => {
|
|
notify('다운로드 요청 실패', 'danger');
|
|
});
|
|
});
|
|
</script>
|
|
|
|
{% endblock %}
|