Add comma-separated queueing for multiple items

This commit is contained in:
calzoneman 2015-07-16 19:14:55 -07:00
parent 45c4e650ee
commit d76af73286
3 changed files with 60 additions and 46 deletions

View File

@ -115,6 +115,7 @@ html(lang="en")
label label
input.add-temp(type="checkbox") input.add-temp(type="checkbox")
| Add as temporary | Add as temporary
div#addfromurl-queue
#customembed.collapse.plcontrol-collapse.col-lg-12.col-md-12 #customembed.collapse.plcontrol-collapse.col-lg-12.col-md-12
.vertical-spacer .vertical-spacer
.input-group .input-group

View File

@ -344,37 +344,67 @@ function queue(pos, src) {
temp: $(".add-temp").prop("checked") temp: $(".add-temp").prop("checked")
}); });
} else { } else {
var link = $("#mediaurl").val(); var links = $("#mediaurl").val().split(",");
if (pos === "next") links = links.reverse();
if (pos === "next" && $("#queue li").length === 0) links.unshift(links.pop());
var emitQueue = [];
var addTemp = $(".add-temp").prop("checked");
var notification = document.getElementById("addfromurl-queue");
if (!notification) {
notification = document.createElement("div");
notification.id = "addfromurl-queue";
document.getElementById("addfromurl").appendChild(notification);
}
links.forEach(function (link) {
var data = parseMediaLink(link); var data = parseMediaLink(link);
var duration = undefined; var duration = undefined;
var title = undefined; var title = undefined;
if (link.indexOf("jw:") === 0) {
duration = parseInt($("#addfromurl-duration-val").val());
if (duration <= 0 || isNaN(duration)) {
duration = undefined;
}
}
if (data.type === "fi") { if (data.type === "fi") {
title = $("#addfromurl-title-val").val(); title = $("#addfromurl-title-val").val();
} }
if (data.id == null || data.type == null) { if (data.id == null || data.type == null) {
makeAlert("Error", "Failed to parse link. Please check that it is correct", makeAlert("Error", "Failed to parse link " + link +
". Please check that it is correct",
"alert-danger") "alert-danger")
.insertAfter($("#addfromurl")); .insertAfter($("#addfromurl"));
} else { } else {
$("#mediaurl").val(""); emitQueue.push({
$("#addfromurl-duration").remove();
$("#addfromurl-title").remove();
socket.emit("queue", {
id: data.id, id: data.id,
type: data.type, type: data.type,
pos: pos, pos: pos,
duration: duration, duration: duration,
title: title, title: title,
temp: $(".add-temp").prop("checked") temp: addTemp,
link: link
}); });
} }
});
var nextQueueDelay = 1020;
function next() {
var data = emitQueue.shift();
if (!data) {
$("#mediaurl").val("");
$("#addfromurl-title").remove();
return;
}
var link = data.link;
delete data.link;
socket.emit("queue", data);
if (emitQueue.length > 0) {
notification.textContent = "Waiting to queue " + emitQueue[0].link;
} else {
notification.textContent = "";
}
setTimeout(next, nextQueueDelay);
}
next();
} }
} }
@ -387,23 +417,6 @@ $("#mediaurl").keyup(function(ev) {
if (ev.keyCode === 13) { if (ev.keyCode === 13) {
queue("end", "url"); queue("end", "url");
} else { } else {
if ($("#mediaurl").val().indexOf("jw:") === 0) {
var duration = $("#addfromurl-duration");
if (duration.length === 0) {
duration = $("<div/>")
.attr("id", "addfromurl-duration")
.appendTo($("#addfromurl"));
$("<span/>").text("JWPlayer Duration (seconds) (optional)")
.appendTo(duration);
$("<input/>").addClass("form-control")
.attr("type", "text")
.attr("id", "addfromurl-duration-val")
.appendTo($("#addfromurl-duration"));
}
} else {
$("#addfromurl-duration").remove();
}
var url = $("#mediaurl").val().split("?")[0]; var url = $("#mediaurl").val().split("?")[0];
if (url.match(/^https?:\/\/(.*)?\.(flv|mp4|og[gv]|webm|mp3|mov)$/)) { if (url.match(/^https?:\/\/(.*)?\.(flv|mp4|og[gv]|webm|mp3|mov)$/)) {
var title = $("#addfromurl-title"); var title = $("#addfromurl-title");

View File

@ -1219,7 +1219,7 @@ function parseMediaLink(url) {
if(url.indexOf("jw:") == 0) { if(url.indexOf("jw:") == 0) {
return { return {
id: url.substring(3), id: url.substring(3),
type: "jw" type: "fi"
}; };
} }