썸네일 다운로드 기능(+API) 추가
This commit is contained in:
65
plugin.py
65
plugin.py
@@ -41,7 +41,7 @@ if ModelSetting.get_bool('activate_cors'):
|
||||
menu = {
|
||||
'main': [package_name, 'youtube-dl'],
|
||||
'sub': [
|
||||
['setting', '설정'], ['download', '다운로드'], ['list', '목록'], ['log', '로그']
|
||||
['setting', '설정'], ['download', '다운로드'], ['thumbnail', '썸네일 다운로드'], ['list', '목록'], ['log', '로그']
|
||||
],
|
||||
'category': 'vod'
|
||||
}
|
||||
@@ -98,6 +98,11 @@ def first_menu(sub):
|
||||
arg['postprocessor_list'] = LogicNormal.get_postprocessor_list()
|
||||
return render_template('%s_%s.html' % (package_name, sub), arg=arg)
|
||||
|
||||
elif sub == 'thumbnail':
|
||||
default_filename = ModelSetting.get('default_filename')
|
||||
arg['filename'] = default_filename if default_filename else LogicNormal.get_default_filename()
|
||||
return render_template('%s_%s.html' % (package_name, sub), arg=arg)
|
||||
|
||||
elif sub == 'list':
|
||||
return render_template('%s_%s.html' % (package_name, sub), arg=arg)
|
||||
|
||||
@@ -157,6 +162,19 @@ def ajax(sub):
|
||||
socketio_emit('add', youtube_dl)
|
||||
return jsonify([])
|
||||
|
||||
elif sub == 'thumbnail':
|
||||
youtube_dl = LogicNormal.thumbnail(plugin=package_name,
|
||||
url=request.form['url'],
|
||||
filename=request.form['filename'],
|
||||
temp_path=ModelSetting.get('temp_path'),
|
||||
save_path=ModelSetting.get('save_path'),
|
||||
all_thumbnails=request.form['all_thumbnails'],
|
||||
proxy=ModelSetting.get('proxy'),
|
||||
ffmpeg_path=ModelSetting.get('ffmpeg_path'))
|
||||
youtube_dl.start()
|
||||
socketio_emit('add', youtube_dl)
|
||||
return jsonify([])
|
||||
|
||||
elif sub == 'list':
|
||||
ret = []
|
||||
for i in LogicNormal.youtube_dl_list:
|
||||
@@ -208,7 +226,7 @@ def api(sub):
|
||||
ret['info_dict'] = info_dict
|
||||
return jsonify(ret)
|
||||
|
||||
# 다운로드 준비를 요청하는 API
|
||||
# 비디오 다운로드 준비를 요청하는 API
|
||||
elif sub == 'download':
|
||||
key = request.values.get('key')
|
||||
url = request.values.get('url')
|
||||
@@ -257,6 +275,47 @@ def api(sub):
|
||||
socketio_emit('add', youtube_dl)
|
||||
return jsonify(ret)
|
||||
|
||||
# 썸네일 다운로드 준비를 요청하는 API
|
||||
elif sub == 'thumbnail':
|
||||
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'))
|
||||
all_thumbnails = request.values.get('all_thumbnails', False)
|
||||
dateafter = request.values.get('dateafter', None)
|
||||
archive = request.values.get('archive', None)
|
||||
start = request.values.get('start', False)
|
||||
cookiefile = request.values.get('cookiefile', None)
|
||||
ret = {
|
||||
'errorCode': 0,
|
||||
'index': None
|
||||
}
|
||||
if None in (key, url):
|
||||
return LogicNormal.abort(ret, 1) # 필수 요청 변수가 없음
|
||||
if not url.startswith('http'):
|
||||
return LogicNormal.abort(ret, 2) # 잘못된 동영상 주소
|
||||
if not filename:
|
||||
filename = LogicNormal.get_default_filename()
|
||||
youtube_dl = LogicNormal.thumbnail(plugin=plugin,
|
||||
url=url,
|
||||
filename=filename,
|
||||
temp_path=ModelSetting.get('temp_path'),
|
||||
save_path=save_path,
|
||||
all_thumbnails=all_thumbnails,
|
||||
dateafter=dateafter,
|
||||
archive=archive,
|
||||
proxy=ModelSetting.get('proxy'),
|
||||
ffmpeg_path=ModelSetting.get('ffmpeg_path'),
|
||||
key=key,
|
||||
cookiefile=cookiefile)
|
||||
if youtube_dl is None:
|
||||
return LogicNormal.abort(ret, 10) # 실패
|
||||
ret['index'] = youtube_dl.index
|
||||
if start:
|
||||
youtube_dl.start()
|
||||
socketio_emit('add', youtube_dl)
|
||||
return jsonify(ret)
|
||||
|
||||
# 다운로드 시작을 요청하는 API
|
||||
elif sub == 'start':
|
||||
index = request.values.get('index')
|
||||
@@ -306,6 +365,7 @@ def api(sub):
|
||||
ret = {
|
||||
'errorCode': 0,
|
||||
'status': None,
|
||||
'type': None,
|
||||
'start_time': None,
|
||||
'end_time': None,
|
||||
'temp_path': None,
|
||||
@@ -320,6 +380,7 @@ def api(sub):
|
||||
if youtube_dl.key != key:
|
||||
return LogicNormal.abort(ret, 4) # 키가 일치하지 않음
|
||||
ret['status'] = youtube_dl.status.name
|
||||
ret['type'] = youtube_dl.type
|
||||
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 \
|
||||
|
||||
Reference in New Issue
Block a user