v1.4.0 socketio 적용
This commit is contained in:
@@ -131,6 +131,10 @@ API에선 직접 비트레이트를 설정할 수 있습니다.
|
|||||||
물론 해당 정보가 없으면 null입니다.
|
물론 해당 정보가 없으면 null입니다.
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
v1.4.0
|
||||||
|
* socketio 적용
|
||||||
|
목록 페이지에서 목록이 실시간으로 업데이트됩니다.
|
||||||
|
|
||||||
v1.3.5
|
v1.3.5
|
||||||
|
|
||||||
v1.3.4
|
v1.3.4
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"description": "\uc720\ud29c\ube0c, \ub124\uc774\ubc84TV \ub4f1 \ub3d9\uc601\uc0c1 \uc0ac\uc774\ud2b8\uc5d0\uc11c \ub3d9\uc601\uc0c1 \ub2e4\uc6b4\ub85c\ub4dc", "name": "youtube-dl", "more": "", "version": "1.3.5", "home": "https://github.com/joyfuI/youtube-dl", "category_name": "vod", "developer": "joyfuI"}
|
{"description": "\uc720\ud29c\ube0c, \ub124\uc774\ubc84TV \ub4f1 \ub3d9\uc601\uc0c1 \uc0ac\uc774\ud2b8\uc5d0\uc11c \ub3d9\uc601\uc0c1 \ub2e4\uc6b4\ub85c\ub4dc", "name": "youtube-dl", "more": "", "version": "1.4.0", "home": "https://github.com/joyfuI/youtube-dl", "category_name": "vod", "developer": "joyfuI"}
|
||||||
@@ -109,7 +109,7 @@ class LogicNormal(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def human_readable_size(size, suffix=''):
|
def human_readable_size(size, suffix=''):
|
||||||
for unit in ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB']:
|
for unit in ('Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB'):
|
||||||
if size < 1024.0:
|
if size < 1024.0:
|
||||||
return '%3.1f %s%s' % (size, unit, suffix)
|
return '%3.1f %s%s' % (size, unit, suffix)
|
||||||
size /= 1024.0
|
size /= 1024.0
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class Youtube_dl(object):
|
|||||||
self.postprocessor = postprocessor
|
self.postprocessor = postprocessor
|
||||||
self.index = Youtube_dl._index
|
self.index = Youtube_dl._index
|
||||||
Youtube_dl._index += 1
|
Youtube_dl._index += 1
|
||||||
self.status = Status.READY
|
self._status = Status.READY
|
||||||
self._thread = None
|
self._thread = None
|
||||||
self.key = None
|
self.key = None
|
||||||
self.start_time = None # 시작 시간
|
self.start_time = None # 시작 시간
|
||||||
@@ -87,6 +87,7 @@ class Youtube_dl(object):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
import glob2
|
||||||
try:
|
try:
|
||||||
self.start_time = datetime.now()
|
self.start_time = datetime.now()
|
||||||
self.status = Status.START
|
self.status = Status.START
|
||||||
@@ -112,7 +113,6 @@ class Youtube_dl(object):
|
|||||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
ydl.download([self.url])
|
ydl.download([self.url])
|
||||||
if self.status == Status.FINISHED: # 다운로드 성공
|
if self.status == Status.FINISHED: # 다운로드 성공
|
||||||
import glob2
|
|
||||||
for i in glob2.glob(self.temp_path + '/**/*'):
|
for i in glob2.glob(self.temp_path + '/**/*'):
|
||||||
path = i.replace(self.temp_path, self.save_path, 1)
|
path = i.replace(self.temp_path, self.save_path, 1)
|
||||||
if os.path.isdir(i):
|
if os.path.isdir(i):
|
||||||
@@ -178,6 +178,16 @@ class Youtube_dl(object):
|
|||||||
self.thumbnail = info_dict['thumbnail']
|
self.thumbnail = info_dict['thumbnail']
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def status(self):
|
||||||
|
return self._status
|
||||||
|
|
||||||
|
@status.setter
|
||||||
|
def status(self, value):
|
||||||
|
from .plugin import socketio_emit
|
||||||
|
self._status = value
|
||||||
|
socketio_emit('status', self)
|
||||||
|
|
||||||
|
|
||||||
class MyLogger(object):
|
class MyLogger(object):
|
||||||
def debug(self, msg):
|
def debug(self, msg):
|
||||||
|
|||||||
23
plugin.py
23
plugin.py
@@ -34,7 +34,7 @@ menu = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugin_info = {
|
plugin_info = {
|
||||||
'version': '1.3.5',
|
'version': '1.4.0',
|
||||||
'name': 'youtube-dl',
|
'name': 'youtube-dl',
|
||||||
'category_name': 'vod',
|
'category_name': 'vod',
|
||||||
'developer': 'joyfuI',
|
'developer': 'joyfuI',
|
||||||
@@ -117,6 +117,7 @@ def ajax(sub):
|
|||||||
youtube_dl = Youtube_dl(package_name, url, filename, temp_path, save_path, format_code, postprocessor)
|
youtube_dl = Youtube_dl(package_name, url, filename, temp_path, save_path, format_code, postprocessor)
|
||||||
LogicNormal.youtube_dl_list.append(youtube_dl) # 리스트 추가
|
LogicNormal.youtube_dl_list.append(youtube_dl) # 리스트 추가
|
||||||
youtube_dl.start()
|
youtube_dl.start()
|
||||||
|
socketio_emit('add', youtube_dl)
|
||||||
return jsonify([])
|
return jsonify([])
|
||||||
|
|
||||||
elif sub == 'list':
|
elif sub == 'list':
|
||||||
@@ -154,7 +155,7 @@ def api(sub):
|
|||||||
'errorCode': 0,
|
'errorCode': 0,
|
||||||
'info_dict': None
|
'info_dict': None
|
||||||
}
|
}
|
||||||
if None == url:
|
if None in (url,):
|
||||||
return LogicNormal.abort(ret, 1) # 필수 요청 변수가 없음
|
return LogicNormal.abort(ret, 1) # 필수 요청 변수가 없음
|
||||||
if not url.startswith('http'):
|
if not url.startswith('http'):
|
||||||
return LogicNormal.abort(ret, 2) # 잘못된 동영상 주소
|
return LogicNormal.abort(ret, 2) # 잘못된 동영상 주소
|
||||||
@@ -204,6 +205,7 @@ def api(sub):
|
|||||||
ret['index'] = youtube_dl.index
|
ret['index'] = youtube_dl.index
|
||||||
if start:
|
if start:
|
||||||
youtube_dl.start()
|
youtube_dl.start()
|
||||||
|
socketio_emit('add', youtube_dl)
|
||||||
return jsonify(ret)
|
return jsonify(ret)
|
||||||
|
|
||||||
# 다운로드 시작을 요청하는 API
|
# 다운로드 시작을 요청하는 API
|
||||||
@@ -283,18 +285,5 @@ def api(sub):
|
|||||||
#########################################################
|
#########################################################
|
||||||
# socketio
|
# socketio
|
||||||
#########################################################
|
#########################################################
|
||||||
@socketio.on('connect', namespace='/%s' % package_name)
|
def socketio_emit(cmd, data):
|
||||||
def connect():
|
socketio.emit(cmd, LogicNormal.get_data(data), namespace='/%s' % package_name, broadcast=True)
|
||||||
try:
|
|
||||||
logger.debug('socket_connect')
|
|
||||||
except Exception as e:
|
|
||||||
logger.error('Exception:%s', e)
|
|
||||||
logger.error(traceback.format_exc())
|
|
||||||
|
|
||||||
@socketio.on('disconnect', namespace='/%s' % package_name)
|
|
||||||
def disconnect():
|
|
||||||
try:
|
|
||||||
logger.debug('socket_disconnect')
|
|
||||||
except Exception as e:
|
|
||||||
logger.error('Exception:%s', e)
|
|
||||||
logger.error(traceback.format_exc())
|
|
||||||
|
|||||||
@@ -40,7 +40,15 @@
|
|||||||
var package_name = '{{ arg["package_name"] }}';
|
var package_name = '{{ arg["package_name"] }}';
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
// var socket = io.connect(location.origin + "/" + package_name);
|
var socket = io.connect(location.origin + "/" + package_name);
|
||||||
|
|
||||||
|
socket.on('add', function (data) {
|
||||||
|
$('#list').append(make_item(data));
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('status', function (data) {
|
||||||
|
status_html(data);
|
||||||
|
});
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/' + package_name + '/ajax/list',
|
url: '/' + package_name + '/ajax/list',
|
||||||
@@ -76,24 +84,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
function make_item(data) {
|
function make_item(data) {
|
||||||
var str = '<tr style="cursor: pointer;" data-toggle="collapse" data-target="#collapse_' + data.index + '" aria-expanded="true">';
|
var str = '<tr id="item_' + data.index + '" style="cursor: pointer;" data-toggle="collapse" data-target="#collapse_' + data.index + '" aria-expanded="true">';
|
||||||
str += '<td scope="col">' + (data.index + 1) + '</td>';
|
str += get_item(data);
|
||||||
str += '<td scope="col">' + data.plugin + '</td>';
|
|
||||||
str += '<td scope="col">' + data.start_time + '</td>';
|
|
||||||
str += '<td scope="col">' + data.extractor + '</td>';
|
|
||||||
str += '<td scope="col">' + data.title + '</td>';
|
|
||||||
str += '<td id="status_' + data.index + '" scope="col">' + data.status_ko + '</td>';
|
|
||||||
var visi = 'hidden';
|
|
||||||
if (parseInt(data.percent) > 0 && data.status_str !== 'STOP') {
|
|
||||||
visi = 'visible';
|
|
||||||
}
|
|
||||||
str += '<td scope="col"><div class="progress"><div id="progress_' + data.index + '" class="progress-bar" style="visibility: ' + visi + '; width:' + data.percent + '%">' + data.percent + '%</div></div></td>';
|
|
||||||
str += '<td id="download_time_' + data.index + '" scope="col">' + data.download_time + '</td>';
|
|
||||||
str += '<td id="button_' + data.index + '" scope="col" class="tableRowHoverOff">';
|
|
||||||
if (data.status_str === 'START' || data.status_str === 'DOWNLOADING' || data.status_str === 'FINISHED') {
|
|
||||||
str += '<button class="align-middle btn btn-outline-danger btn-sm youtube-dl_stop" data-index="' + data.index + '">중지</button>';
|
|
||||||
}
|
|
||||||
str += '</td>';
|
|
||||||
str += '</tr>';
|
str += '</tr>';
|
||||||
str += '<tr class="collapse tableRowHoverOff" style="cursor: pointer;" id="collapse_' + data.index + '">';
|
str += '<tr class="collapse tableRowHoverOff" style="cursor: pointer;" id="collapse_' + data.index + '">';
|
||||||
str += '<td colspan="9">';
|
str += '<td colspan="9">';
|
||||||
@@ -105,6 +97,27 @@
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_item(data) {
|
||||||
|
var str = '<td scope="col">' + (data.index + 1) + '</td>';
|
||||||
|
str += '<td scope="col">' + data.plugin + '</td>';
|
||||||
|
str += '<td scope="col">' + data.start_time + '</td>';
|
||||||
|
str += '<td scope="col">' + data.extractor + '</td>';
|
||||||
|
str += '<td scope="col">' + data.title + '</td>';
|
||||||
|
str += '<td scope="col">' + data.status_ko + '</td>';
|
||||||
|
var visi = 'hidden';
|
||||||
|
if (parseInt(data.percent) > 0 && data.status_str !== 'STOP') {
|
||||||
|
visi = 'visible';
|
||||||
|
}
|
||||||
|
str += '<td scope="col"><div class="progress"><div class="progress-bar" style="visibility: ' + visi + '; width:' + data.percent + '%">' + data.percent + '%</div></div></td>';
|
||||||
|
str += '<td scope="col">' + data.download_time + '</td>';
|
||||||
|
str += '<td scope="col" class="tableRowHoverOff">';
|
||||||
|
if (data.status_str === 'START' || data.status_str === 'DOWNLOADING' || data.status_str === 'FINISHED') {
|
||||||
|
str += '<button class="align-middle btn btn-outline-danger btn-sm youtube-dl_stop" data-index="' + data.index + '">중지</button>';
|
||||||
|
}
|
||||||
|
str += '</td>';
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
function get_detail(data) {
|
function get_detail(data) {
|
||||||
var str = info_html('URL', data.url, data.url);
|
var str = info_html('URL', data.url, data.url);
|
||||||
str += info_html('업로더', data.uploader, data.uploader_url);
|
str += info_html('업로더', data.uploader, data.uploader_url);
|
||||||
@@ -140,6 +153,11 @@
|
|||||||
str += '</span></div></div></div>';
|
str += '</span></div></div></div>';
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function status_html(data) {
|
||||||
|
$('#item_' + data.index).html(get_item(data));
|
||||||
|
$('#detail_' + data.index).html(get_detail(data));
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user