', methods=['GET', 'POST'])
@check_api
def api(sub):
- plugin = request.form.get('plugin')
+ plugin = request.values.get('plugin')
logger.debug('API %s %s: %s', package_name, sub, plugin)
if not plugin: # 요청한 플러그인명이 빈문자열이거나 None면
abort(403) # 403 에러(거부)
try:
# 동영상 정보를 반환하는 API
if sub == 'info_dict':
- url = request.form.get('url')
+ url = request.values.get('url')
ret = {
'errorCode': 0,
'info_dict': None
}
if None in (url,):
- return LogicNormal.abort(ret, 1) # 필수 요청 변수가 없음
+ return LogicNormal.abort(ret, 1) # 필수 요청 변수가 없음
if not url.startswith('http'):
- return LogicNormal.abort(ret, 2) # 잘못된 동영상 주소
- info_dict = Youtube_dl.get_info_dict(url, ModelSetting.get('proxy'))
+ return LogicNormal.abort(ret, 2) # 잘못된 동영상 주소
+ info_dict = LogicNormal.get_info_dict(url, ModelSetting.get('proxy'))
if info_dict is None:
- return LogicNormal.abort(ret, 10) # 실패
+ return LogicNormal.abort(ret, 10) # 실패
ret['info_dict'] = info_dict
return jsonify(ret)
# 다운로드 준비를 요청하는 API
elif sub == 'download':
- key = request.form.get('key')
- url = request.form.get('url')
- filename = request.form.get('filename', ModelSetting.get('default_filename'))
- save_path = request.form.get('save_path', ModelSetting.get('save_path'))
- format_code = request.form.get('format', None)
- preferedformat = request.form.get('preferedformat', None)
- preferredcodec = request.form.get('preferredcodec', None)
- preferredquality = request.form.get('preferredquality', 192)
- archive = request.form.get('archive', None)
- start = request.form.get('start', False)
+ key = request.values.get('key')
+ url = request.values.get('url')
+ filename = request.values.get('filename', ModelSetting.get('default_filename'))
+ save_path = request.values.get('save_path', ModelSetting.get('save_path'))
+ format_code = request.values.get('format', None)
+ preferedformat = request.values.get('preferedformat', None)
+ preferredcodec = request.values.get('preferredcodec', None)
+ preferredquality = request.values.get('preferredquality', 192)
+ archive = request.values.get('archive', None)
+ start = request.values.get('start', False)
ret = {
'errorCode': 0,
'index': None
}
if None in (key, url):
- return LogicNormal.abort(ret, 1) # 필수 요청 변수가 없음
+ return LogicNormal.abort(ret, 1) # 필수 요청 변수가 없음
if not url.startswith('http'):
- return LogicNormal.abort(ret, 2) # 잘못된 동영상 주소
- opts = {}
- if format_code is not None:
- opts['format'] = format_code
- postprocessor = []
- if preferedformat is not None:
- postprocessor.append({
- 'key': 'FFmpegVideoConvertor',
- 'preferedformat': preferedformat
- })
- if preferredcodec is not None:
- if preferredcodec not in ('best', 'mp3', 'aac', 'flac', 'm4a', 'opus', 'vorbis', 'wav'):
- return LogicNormal.abort(ret, 5) # 허용되지 않은 값이 있음
- postprocessor.append({
- 'key': 'FFmpegExtractAudio',
- 'preferredcodec': preferredcodec,
- 'preferredquality': str(preferredquality)
- })
- if postprocessor:
- opts['postprocessors'] = postprocessor
- proxy = ModelSetting.get('proxy')
- if proxy:
- opts['proxy'] = proxy
- if archive is not None:
- opts['download_archive'] = archive
- youtube_dl = Youtube_dl(plugin, url, filename, ModelSetting.get('temp_path'), save_path, opts)
- youtube_dl.key = key
- LogicNormal.youtube_dl_list.append(youtube_dl) # 리스트 추가
+ return LogicNormal.abort(ret, 2) # 잘못된 동영상 주소
+ if preferredcodec not in (None, 'best', 'mp3', 'aac', 'flac', 'm4a', 'opus', 'vorbis', 'wav'):
+ return LogicNormal.abort(ret, 5) # 허용되지 않은 값이 있음
+ youtube_dl = LogicNormal.download(plugin=plugin,
+ url=url,
+ filename=filename,
+ temp_path=ModelSetting.get('temp_path'),
+ save_path=save_path,
+ format=format_code,
+ preferedformat=preferedformat,
+ preferredcodec=preferredcodec,
+ preferredquality=preferredquality,
+ archive=archive,
+ proxy=ModelSetting.get('proxy'),
+ ffmpeg_path=ModelSetting.get('ffmpeg_path'),
+ key=key)
ret['index'] = youtube_dl.index
if start:
youtube_dl.start()
@@ -231,50 +219,50 @@ def api(sub):
# 다운로드 시작을 요청하는 API
elif sub == 'start':
- index = request.form.get('index')
- key = request.form.get('key')
+ index = request.values.get('index')
+ key = request.values.get('key')
ret = {
'errorCode': 0,
'status': None
}
if None in (index, key):
- return LogicNormal.abort(ret, 1) # 필수 요청 변수가 없음
+ return LogicNormal.abort(ret, 1) # 필수 요청 변수가 없음
index = int(index)
if not (0 <= index < len(LogicNormal.youtube_dl_list)):
- return LogicNormal.abort(ret, 3) # 인덱스 범위를 벗어남
+ return LogicNormal.abort(ret, 3) # 인덱스 범위를 벗어남
youtube_dl = LogicNormal.youtube_dl_list[index]
if youtube_dl.key != key:
- return LogicNormal.abort(ret, 4) # 키가 일치하지 않음
+ return LogicNormal.abort(ret, 4) # 키가 일치하지 않음
ret['status'] = youtube_dl.status.name
if not youtube_dl.start():
- return LogicNormal.abort(ret, 10) # 실패
+ return LogicNormal.abort(ret, 10) # 실패
return jsonify(ret)
# 다운로드 중지를 요청하는 API
elif sub == 'stop':
- index = request.form.get('index')
- key = request.form.get('key')
+ index = request.values.get('index')
+ key = request.values.get('key')
ret = {
'errorCode': 0,
'status': None
}
if None in (index, key):
- return LogicNormal.abort(ret, 1) # 필수 요청 변수가 없음
+ return LogicNormal.abort(ret, 1) # 필수 요청 변수가 없음
index = int(index)
if not (0 <= index < len(LogicNormal.youtube_dl_list)):
- return LogicNormal.abort(ret, 3) # 인덱스 범위를 벗어남
+ return LogicNormal.abort(ret, 3) # 인덱스 범위를 벗어남
youtube_dl = LogicNormal.youtube_dl_list[index]
if youtube_dl.key != key:
- return LogicNormal.abort(ret, 4) # 키가 일치하지 않음
+ return LogicNormal.abort(ret, 4) # 키가 일치하지 않음
ret['status'] = youtube_dl.status.name
if not youtube_dl.stop():
- return LogicNormal.abort(ret, 10) # 실패
+ return LogicNormal.abort(ret, 10) # 실패
return jsonify(ret)
# 현재 상태를 반환하는 API
elif sub == 'status':
- index = request.form.get('index')
- key = request.form.get('key')
+ index = request.values.get('index')
+ key = request.values.get('key')
ret = {
'errorCode': 0,
'status': None,
@@ -284,13 +272,13 @@ def api(sub):
'save_path': None
}
if None in (index, key):
- return LogicNormal.abort(ret, 1) # 필수 요청 변수가 없음
+ return LogicNormal.abort(ret, 1) # 필수 요청 변수가 없음
index = int(index)
if not (0 <= index < len(LogicNormal.youtube_dl_list)):
- return LogicNormal.abort(ret, 3) # 인덱스 범위를 벗어남
+ return LogicNormal.abort(ret, 3) # 인덱스 범위를 벗어남
youtube_dl = LogicNormal.youtube_dl_list[index]
if youtube_dl.key != key:
- return LogicNormal.abort(ret, 4) # 키가 일치하지 않음
+ return LogicNormal.abort(ret, 4) # 키가 일치하지 않음
ret['status'] = youtube_dl.status.name
ret['start_time'] = youtube_dl.start_time.strftime('%Y-%m-%dT%H:%M:%S') if youtube_dl.start_time is not None else None
ret['end_time'] = youtube_dl.end_time.strftime('%Y-%m-%dT%H:%M:%S') if youtube_dl.end_time is not None else None
@@ -301,7 +289,7 @@ def api(sub):
logger.error('Exception:%s', e)
logger.error(traceback.format_exc())
abort(500) # 500 에러(서버 오류)
- abort(404) # 404 에러(페이지 없음)
+ abort(404) # 404 에러(페이지 없음)
#########################################################
# socketio
diff --git a/templates/youtube-dl_download.html b/templates/youtube-dl_download.html
index d0b366b..5bc4d51 100644
--- a/templates/youtube-dl_download.html
+++ b/templates/youtube-dl_download.html
@@ -57,7 +57,7 @@
// 후처리 변경
$('#postprocessor').change(function () {
- if ($(this).find($('option[value="' + $(this).val() + '"]')).parent().attr('label') === '오디오 추출') {
+ if ($(this).find($(`option[value="${$(this).val()}"]`)).parent().attr('label') === '오디오 추출') {
$('#preset').val('bestaudio/best').change();
}
});
@@ -72,7 +72,7 @@
return;
}
$.ajax({
- url: '/' + package_name + '/ajax/download',
+ url: `/${package_name}/ajax/download`,
type: 'POST',
cache: false,
data: {
@@ -81,12 +81,15 @@
format: $('#format').val(),
postprocessor: $('#postprocessor').val()
},
- dataType: 'json',
- success: function () {
- $.notify('분석중..', {
- type: 'info'
- });
- }
+ dataType: 'json'
+ }).done(function () {
+ $.notify('분석중..', {
+ type: 'info'
+ });
+ }).fail(function () {
+ $.notify('다운로드 요청 실패', {
+ type: 'danger'
+ });
});
return false;
});
diff --git a/templates/youtube-dl_list.html b/templates/youtube-dl_list.html
index bf5a7d3..4d96f28 100644
--- a/templates/youtube-dl_list.html
+++ b/templates/youtube-dl_list.html
@@ -43,7 +43,7 @@
const package_name = '{{ arg["package_name"] }}';
$(function () {
- let socket = io.connect(location.origin + '/' + package_name);
+ let socket = io.connect(`${location.origin}/${package_name}`);
socket.on('add', function (data) {
$('#list').append(make_item(data));
@@ -54,33 +54,31 @@
});
$.ajax({
- url: '/' + package_name + '/ajax/list',
+ url: `/${package_name}/ajax/list`,
type: 'POST',
cache: false,
data: {},
- dataType: 'json',
- success: function (data) {
- let str = '';
- for (let i of data) {
- str += make_item(i);
- }
- $('#list').html(str);
+ dataType: 'json'
+ }).done(function (data) {
+ let str = '';
+ for (let item of data) {
+ str += make_item(item);
}
+ $('#list').html(str);
});
$('#list').on('click', '.youtube-dl_stop', function () {
let index = $(this).data('index');
$.ajax({
- url: '/' + package_name + '/ajax/stop',
+ url: `/${package_name}/ajax/stop`,
type: 'POST',
cache: false,
data: {
index: index
},
- dataType: 'json',
- success: function () {
- location.reload(); // 새로고침
- }
+ dataType: 'json'
+ }).done(function () {
+ location.reload();
});
return false;
});
@@ -158,8 +156,8 @@
}
function status_html(data) {
- $('#item_' + data.index).html(get_item(data));
- $('#detail_' + data.index).html(get_detail(data));
+ $(`#item_${data.index}`).html(get_item(data));
+ $(`#detail_${data.index}`).html(get_detail(data));
}
diff --git a/templates/youtube-dl_setting.html b/templates/youtube-dl_setting.html
index b1b744e..ad7974f 100644
--- a/templates/youtube-dl_setting.html
+++ b/templates/youtube-dl_setting.html
@@ -4,10 +4,11 @@
{{ macros.setting_input_text('youtube_dl_version', 'youtube-dl 버전', value=arg['youtube_dl_version']) }}
@@ -16,6 +17,33 @@
{% endblock %}