Add temporary videos

This commit is contained in:
calzoneman 2013-05-04 17:54:28 -05:00
parent 62e80cec63
commit 703ac3ce4f
12 changed files with 163 additions and 50 deletions

View file

@ -46,6 +46,7 @@ var Channel = function(name) {
qopen_allow_move: false, qopen_allow_move: false,
qopen_allow_playnext: false, qopen_allow_playnext: false,
qopen_allow_delete: false, qopen_allow_delete: false,
qopen_temp: true,
allow_voteskip: true, allow_voteskip: true,
voteskip_ratio: 0.5, voteskip_ratio: 0.5,
pagetitle: this.name, pagetitle: this.name,
@ -93,6 +94,9 @@ Channel.prototype.loadDump = function() {
var m = new Media(e.id, e.title, e.seconds, e.type); var m = new Media(e.id, e.title, e.seconds, e.type);
m.queueby = data.queue[i].queueby ? data.queue[i].queueby m.queueby = data.queue[i].queueby ? data.queue[i].queueby
: ""; : "";
if(e.temp !== undefined) {
m.temp = e.temp;
}
this.queue.push(m); this.queue.push(m);
} }
this.sendAll("playlist", { this.sendAll("playlist", {
@ -236,6 +240,9 @@ Channel.prototype.saveRank = function(user) {
} }
Channel.prototype.cacheMedia = function(media) { Channel.prototype.cacheMedia = function(media) {
if(media.temp) {
return;
}
this.library[media.id] = media; this.library[media.id] = media;
if(this.registered) { if(this.registered) {
return Database.cacheMedia(this.name, media); return Database.cacheMedia(this.name, media);
@ -479,7 +486,7 @@ Channel.prototype.sendPlaylist = function(user) {
Channel.prototype.sendMediaUpdate = function(user) { Channel.prototype.sendMediaUpdate = function(user) {
if(this.media != null) { if(this.media != null) {
user.socket.emit("mediaUpdate", this.media.packupdate()); user.socket.emit("mediaUpdate", this.media.fullupdate());
} }
} }
@ -649,12 +656,12 @@ function mediaUpdate(chan, id) {
chan.time = new Date().getTime(); chan.time = new Date().getTime();
// Show's over, move on to the next thing // Show's over, move on to the next thing
if(chan.media.currentTime > chan.media.seconds) { if(chan.media.currentTime > chan.media.seconds + 1) {
chan.playNext(); chan.playNext();
} }
// Send updates about every 5 seconds // Send updates about every 5 seconds
else if(chan.i % 5 == 0) { else if(chan.i % 5 == 0) {
chan.sendAll("mediaUpdate", chan.media.packupdate()); chan.sendAll("mediaUpdate", chan.media.timeupdate());
} }
chan.i++; chan.i++;
@ -680,13 +687,23 @@ Channel.prototype.queueAdd = function(media, idx) {
} }
} }
Channel.prototype.autoTemp = function(media, user) {
if(isLive(media.type)) {
media.temp = true;
}
if(user.rank < Rank.Moderator && this.opts.qopen_temp) {
media.temp = true;
}
}
Channel.prototype.enqueue = function(data, user) { Channel.prototype.enqueue = function(data, user) {
var idx = data.pos == "next" ? this.position + 1 : this.queue.length; var idx = data.pos == "next" ? this.position + 1 : this.queue.length;
// Prefer cache over looking up new data // Prefer cache over looking up new data
if(data.id in this.library) { if(data.id in this.library) {
var media = this.library[data.id]; var media = this.library[data.id].dup();
media.queueby = user ? user.name : ""; media.queueby = user ? user.name : "";
this.autoTemp(media, user);
this.queueAdd(media, idx); this.queueAdd(media, idx);
this.logger.log("*** Queued from cache: id=" + data.id); this.logger.log("*** Queued from cache: id=" + data.id);
} }
@ -699,6 +716,7 @@ Channel.prototype.enqueue = function(data, user) {
case "sc": case "sc":
InfoGetter.getMedia(data.id, data.type, function(media) { InfoGetter.getMedia(data.id, data.type, function(media) {
media.queueby = user ? user.name : ""; media.queueby = user ? user.name : "";
this.autoTemp(media, user);
this.queueAdd(media, idx); this.queueAdd(media, idx);
this.cacheMedia(media); this.cacheMedia(media);
if(data.type == "yp") if(data.type == "yp")
@ -708,21 +726,25 @@ Channel.prototype.enqueue = function(data, user) {
case "li": case "li":
var media = new Media(data.id, "Livestream - " + data.id, "--:--", "li"); var media = new Media(data.id, "Livestream - " + data.id, "--:--", "li");
media.queueby = user ? user.name : ""; media.queueby = user ? user.name : "";
this.autoTemp(media, user);
this.queueAdd(media, idx); this.queueAdd(media, idx);
break; break;
case "tw": case "tw":
var media = new Media(data.id, "Twitch - " + data.id, "--:--", "tw"); var media = new Media(data.id, "Twitch - " + data.id, "--:--", "tw");
media.queueby = user ? user.name : ""; media.queueby = user ? user.name : "";
this.autoTemp(media, user);
this.queueAdd(media, idx); this.queueAdd(media, idx);
break; break;
case "rt": case "rt":
var media = new Media(data.id, "Livestream", "--:--", "rt"); var media = new Media(data.id, "Livestream", "--:--", "rt");
media.queueby = user ? user.name : ""; media.queueby = user ? user.name : "";
this.autoTemp(media, user);
this.queueAdd(media, idx); this.queueAdd(media, idx);
break; break;
case "jw": case "jw":
var media = new Media(data.id, "JWPlayer Stream - " + data.id, "--:--", "jw"); var media = new Media(data.id, "JWPlayer Stream - " + data.id, "--:--", "jw");
media.queueby = user ? user.name : ""; media.queueby = user ? user.name : "";
this.autoTemp(media, user);
this.queueAdd(media, idx); this.queueAdd(media, idx);
break; break;
default: default:
@ -759,6 +781,38 @@ Channel.prototype.tryQueue = function(user, data) {
this.enqueue(data, user); this.enqueue(data, user);
} }
Channel.prototype.setTemp = function(idx, temp) {
var med = this.queue[idx];
med.temp = temp;
this.sendAll("setTemp", {
idx: idx,
temp: temp
});
if(temp) {
if(Database.uncacheMedia(this.name, med.id)) {
delete this.library[med.id];
}
}
else {
this.cacheMedia(med);
}
}
Channel.prototype.trySetTemp = function(user, data) {
if(!Rank.hasPermission(user, "settemp")) {
return;
}
if(typeof data.idx != "number" || typeof data.temp != "boolean") {
return;
}
if(data.idx < 0 || data.idx >= this.queue.length) {
return;
}
this.setTemp(data.idx, data.temp);
}
Channel.prototype.dequeue = function(data) { Channel.prototype.dequeue = function(data) {
if(data.pos < 0 || data.pos >= this.queue.length) { if(data.pos < 0 || data.pos >= this.queue.length) {
return; return;
@ -771,7 +825,7 @@ Channel.prototype.dequeue = function(data) {
this.broadcastPlaylistMeta(); this.broadcastPlaylistMeta();
// If you remove the currently playing video, play the next one // If you remove the currently playing video, play the next one
if(data.pos == this.position) { if(data.pos == this.position && !data.removeonly) {
this.position--; this.position--;
this.playNext(); this.playNext();
return; return;
@ -811,41 +865,8 @@ Channel.prototype.tryUncache = function(user, data) {
} }
Channel.prototype.playNext = function() { Channel.prototype.playNext = function() {
// Nothing to play var pos = this.position + 1 >= this.queue.length ? 0 : this.position + 1;
if(this.queue.length == 0) { this.jumpTo(pos);
return;
}
// Reset voteskip
this.voteskip = false;
this.broadcastVoteskipUpdate();
this.drinks = 0;
this.broadcastDrinks();
var old = this.position;
// Wrap around if the end is hit
if(this.position + 1 >= this.queue.length) {
this.position = -1;
}
this.position++;
var oid = this.media ? this.media.id : "";
this.media = this.queue[this.position];
this.media.currentTime = -1;
this.sendAll("mediaUpdate", this.media.packupdate());
this.sendAll("updatePlaylistIdx", {
old: old,
idx: this.position
});
// If it's not a livestream, enable autolead
if(this.leader == null && !isLive(this.media.type)) {
this.time = new Date().getTime();
if(this.media.id != oid) {
mediaUpdate(this, this.media.id);
}
}
} }
Channel.prototype.tryPlayNext = function(user) { Channel.prototype.tryPlayNext = function(user) {
@ -871,12 +892,24 @@ Channel.prototype.jumpTo = function(pos) {
this.broadcastDrinks(); this.broadcastDrinks();
var old = this.position; var old = this.position;
if(this.media && this.media.temp && old != pos) {
this.dequeue({pos: old, removeonly: true});
if(pos > old) {
pos--;
}
}
if(pos >= this.queue.length || pos < 0) {
return;
}
if(this.media) {
delete this.media["currentTime"];
}
this.position = pos; this.position = pos;
var oid = this.media ? this.media.id : ""; var oid = this.media ? this.media.id : "";
this.media = this.queue[this.position]; this.media = this.queue[this.position];
this.media.currentTime = -1; this.media.currentTime = -1;
this.sendAll("mediaUpdate", this.media.packupdate()); this.sendAll("changeMedia", this.media.fullupdate());
this.sendAll("updatePlaylistIdx", { this.sendAll("updatePlaylistIdx", {
old: old, old: old,
idx: this.position idx: this.position
@ -969,7 +1002,7 @@ Channel.prototype.tryUpdate = function(user, data) {
} }
this.media.currentTime = data.currentTime; this.media.currentTime = data.currentTime;
this.sendAll("mediaUpdate", this.media.packupdate()); this.sendAll("mediaUpdate", this.media.timeupdate());
} }
Channel.prototype.move = function(data) { Channel.prototype.move = function(data) {

View file

@ -52,6 +52,14 @@ var Media = function(id, title, seconds, type) {
} }
this.type = type; this.type = type;
this.queueby = ""; this.queueby = "";
this.temp = false;
}
Media.prototype.dup = function() {
var m = new Media(this.id, this.title, this.seconds, this.type);
m.queueby = this.queueby;
m.temp = this.temp;
return m;
} }
// Returns an object containing the data in this Media but not the // Returns an object containing the data in this Media but not the
@ -63,13 +71,14 @@ Media.prototype.pack = function() {
seconds: this.seconds, seconds: this.seconds,
duration: this.duration, duration: this.duration,
type: this.type, type: this.type,
queueby: this.queueby queueby: this.queueby,
temp: this.temp
}; };
} }
// Same as pack() but includes the currentTime variable set by the channel // Same as pack() but includes the currentTime variable set by the channel
// when the media is being synchronized // when the media is being synchronized
Media.prototype.packupdate = function() { Media.prototype.fullupdate = function() {
return { return {
id: this.id, id: this.id,
title: this.title, title: this.title,
@ -77,7 +86,14 @@ Media.prototype.packupdate = function() {
duration: this.duration, duration: this.duration,
type: this.type, type: this.type,
currentTime: this.currentTime, currentTime: this.currentTime,
queueby: this.queueby queueby: this.queueby,
temp: this.temp
};
}
Media.prototype.timeupdate = function() {
return {
currentTime: this.currentTime
}; };
} }

View file

@ -2,7 +2,7 @@
"author": "Calvin Montgomery", "author": "Calvin Montgomery",
"name": "CyTube", "name": "CyTube",
"description": "Online media synchronizer and chat", "description": "Online media synchronizer and chat",
"version": "1.5.5", "version": "1.6.0",
"repository": { "repository": {
"url": "http://github.com/calzoneman/sync" "url": "http://github.com/calzoneman/sync"
}, },

View file

@ -36,6 +36,7 @@ var permissions = {
seeVoteskip : exports.Moderator, seeVoteskip : exports.Moderator,
uncache : exports.Moderator, uncache : exports.Moderator,
seenlogins : exports.Moderator, seenlogins : exports.Moderator,
settemp : exports.Moderator,
search : exports.Guest, search : exports.Guest,
chat : exports.Guest, chat : exports.Guest,
}; };

View file

@ -9,7 +9,7 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
const VERSION = "1.5.5"; const VERSION = "1.6.0";
var fs = require("fs"); var fs = require("fs");
var Logger = require("./logger.js"); var Logger = require("./logger.js");

View file

@ -166,6 +166,12 @@ User.prototype.initCallbacks = function() {
} }
}.bind(this)); }.bind(this));
this.socket.on("setTemp", function(data) {
if(this.channel != null) {
this.channel.trySetTemp(this, data);
}
}.bind(this));
this.socket.on("unqueue", function(data) { this.socket.on("unqueue", function(data) {
if(this.channel != null) { if(this.channel != null) {
this.channel.tryDequeue(this, data); this.channel.tryDequeue(this, data);

View file

@ -955,6 +955,15 @@ li.alert-info {
color: #ff9900; color: #ff9900;
} }
li.alert-error {
border: 1px solid #cc0000;
color: #cc0000;
}
li.alert-error.alert-info {
color: #ff9900;
}
.btn, .btn:hover { .btn, .btn:hover {
text-shadow: none; text-shadow: none;
color: #aaaaaa; color: #aaaaaa;

View file

@ -71,6 +71,7 @@ function initCallbacks() {
$("#opt_qopen_allow_move").prop("checked", opts.qopen_allow_move); $("#opt_qopen_allow_move").prop("checked", opts.qopen_allow_move);
$("#opt_qopen_allow_delete").prop("checked", opts.qopen_allow_delete); $("#opt_qopen_allow_delete").prop("checked", opts.qopen_allow_delete);
$("#opt_qopen_allow_playnext").prop("checked", opts.qopen_allow_playnext); $("#opt_qopen_allow_playnext").prop("checked", opts.qopen_allow_playnext);
$("#opt_qopen_temp").prop("checked", opts.qopen_temp);
$("#opt_pagetitle").attr("placeholder", opts.pagetitle); $("#opt_pagetitle").attr("placeholder", opts.pagetitle);
document.title = opts.pagetitle; document.title = opts.pagetitle;
PAGETITLE = opts.pagetitle; PAGETITLE = opts.pagetitle;
@ -284,6 +285,20 @@ function initCallbacks() {
$(li).show("blind"); $(li).show("blind");
}); });
socket.on("setTemp", function(data) {
var li = $("#queue").children()[data.idx];
var buttons = $(li).find(".qe_btn");
if(buttons.length == 5) {
$(buttons[4]).text(data.temp ? "Untemp" : "Temp");
}
if(data.temp) {
$(li).addClass("alert alert-error");
}
else {
$(li).removeClass("alert alert-error");
}
});
socket.on("unqueue", function(data) { socket.on("unqueue", function(data) {
var li = $("#queue").children()[data.pos]; var li = $("#queue").children()[data.pos];
$(li).remove(); $(li).remove();
@ -308,7 +323,7 @@ function initCallbacks() {
$("#voteskip").attr("disabled", false); $("#voteskip").attr("disabled", false);
}); });
socket.on("mediaUpdate", function(data) { socket.on("changeMedia", function(data) {
$("#currenttitle").text("Currently Playing: " + data.title); $("#currenttitle").text("Currently Playing: " + data.title);
if(data.type != "sc" && MEDIATYPE == "sc") if(data.type != "sc" && MEDIATYPE == "sc")
// [](/goddamnitmango) // [](/goddamnitmango)
@ -317,7 +332,13 @@ function initCallbacks() {
MEDIATYPE = data.type; MEDIATYPE = data.type;
PLAYER = new Media(data); PLAYER = new Media(data);
} }
else if(PLAYER.update) { if(PLAYER.update) {
PLAYER.update(data);
}
});
socket.on("mediaUpdate", function(data) {
if(PLAYER.update) {
PLAYER.update(data); PLAYER.update(data);
} }
}); });

View file

@ -381,6 +381,7 @@ $("#opt_submit").click(function() {
qopen_allow_move: $("#opt_qopen_allow_move").prop("checked"), qopen_allow_move: $("#opt_qopen_allow_move").prop("checked"),
qopen_allow_delete: $("#opt_qopen_allow_delete").prop("checked"), qopen_allow_delete: $("#opt_qopen_allow_delete").prop("checked"),
qopen_allow_playnext: $("#opt_qopen_allow_playnext").prop("checked"), qopen_allow_playnext: $("#opt_qopen_allow_playnext").prop("checked"),
qopen_temp: $("#opt_qopen_temp").prop("checked"),
allow_voteskip: $("#opt_allow_voteskip").prop("checked"), allow_voteskip: $("#opt_allow_voteskip").prop("checked"),
voteskip_ratio: ratio, voteskip_ratio: ratio,
pagetitle: ptitle, pagetitle: ptitle,

View file

@ -256,6 +256,9 @@ function makeQueueEntry(video) {
var time = $("<span />").addClass("qe_time").appendTo(li); var time = $("<span />").addClass("qe_time").appendTo(li);
time.text(video.duration); time.text(video.duration);
var clear = $("<div />").addClass("qe_clear").appendTo(li); var clear = $("<div />").addClass("qe_clear").appendTo(li);
if(video.temp) {
li.addClass("alert alert-error");
}
return li; return li;
} }
@ -326,6 +329,25 @@ function addQueueButtons(li) {
}); });
} }
if(RANK >= Rank.Moderator) {
var btnTemp = $("<button />").attr("class", "btn qe_btn").appendTo(btnstrip);
var temp = $(li).hasClass("alert-error");
if(temp) {
btnTemp.text("Untemp");
}
else {
btnTemp.text("Temp");
}
$(btnTemp).click(function() {
temp = $(li).hasClass("alert-error");
var idx = $("#queue").children().index(li);
socket.emit("setTemp", {
idx: idx,
temp: !temp
});
});
}
$(document).mouseup(function() { $(document).mouseup(function() {
if(GRABBEDLI != null) { if(GRABBEDLI != null) {
var idx = $("#queue").children().index(GRABBEDLI); var idx = $("#queue").children().index(GRABBEDLI);

View file

@ -307,7 +307,7 @@ Media.prototype.initJWPlayer = function() {
} }
Media.prototype.update = function(data) { Media.prototype.update = function(data) {
if(data.id != this.id) { if(data.id && data.id != this.id) {
if(data.currentTime < 0) { if(data.currentTime < 0) {
data.currentTime = 0; data.currentTime = 0;
} }

View file

@ -165,6 +165,10 @@
<input type="checkbox" id="opt_qopen_allow_playnext"> <input type="checkbox" id="opt_qopen_allow_playnext">
Allow anyone to jump to a video Allow anyone to jump to a video
</label> </label>
<label class="checkbox">
<input type="checkbox" id="opt_qopen_temp">
Videos added by guests are temporary
</label>
</div> </div>
<div class="span5"> <div class="span5">
<label>Page Title <label>Page Title