Fix video lengths not showing in library

This commit is contained in:
Calvin Montgomery 2013-08-23 21:06:29 -05:00
parent 0e87fc6907
commit dd0410eac7
6 changed files with 39 additions and 39 deletions

View File

@ -13,7 +13,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
var fs = require("fs");
var Poll = require("./poll.js").Poll;
var Media = require("./media.js").Media;
var formatTime = require("./media.js").formatTime;
var Logger = require("./logger.js");
var Rank = require("./rank.js");
var ChatCommand = require("./chatcommand.js");
@ -718,6 +717,10 @@ Channel.prototype.search = function(query, callback) {
return (x == y) ? 0 : (x < y ? -1 : 1);
});
res.forEach(function (r) {
r.duration = $util.formatTime(r.seconds);
});
callback(res);
});
}
@ -974,7 +977,7 @@ Channel.prototype.broadcastPlaylistMeta = function() {
total += iter.media.seconds;
iter = iter.next;
}
var timestr = formatTime(total);
var timestr = $util.formatTime(total);
var packet = {
count: this.playlist.items.length,
time: timestr

View File

@ -9,37 +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.
*/
// Helper function for formatting a time value in seconds
// to the format hh:mm:ss
function formatTime(sec) {
if(sec == "--:--")
return sec;
sec = Math.floor(sec);
var hours="", minutes="", seconds="";
if(sec > 3600) {
hours = ""+Math.floor(sec / 3600);
if(hours.length < 2)
hours = "0"+hours;
sec = sec % 3600;
}
minutes = ""+Math.floor(sec / 60);
while(minutes.length < 2) {
minutes = "0"+minutes;
}
seconds = ""+(sec % 60);
while(seconds.length < 2) {
seconds = "0"+seconds;
}
var time = "";
if(hours != "")
time = hours + ":";
time += minutes + ":" + seconds;
return time;
}
exports.formatTime = formatTime;
var formatTime = require("./utilities").formatTime;
// Represents a media entry
var Media = function(id, title, seconds, type) {

View File

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

View File

@ -6,7 +6,7 @@ var Logger = require("./logger");
var Channel = require("./channel");
var User = require("./user");
const VERSION = "2.4.1";
const VERSION = "2.4.2";
function getIP(req) {
var raw = req.connection.remoteAddress;

View File

@ -11,7 +11,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
var Rank = require("./rank.js");
var Channel = require("./channel.js").Channel;
var formatTime = require("./media.js").formatTime;
var Logger = require("./logger.js");
var $util = require("./utilities");
@ -443,7 +442,7 @@ User.prototype.initCallbacks = function() {
if(err)
list = [];
for(var i = 0; i < list.length; i++) {
list[i].time = formatTime(list[i].time);
list[i].time = $util.formatTime(list[i].time);
}
self.socket.emit("listPlaylists", {
pllist: list,
@ -492,7 +491,7 @@ User.prototype.initCallbacks = function() {
if(err)
list = [];
for(var i = 0; i < list.length; i++) {
list[i].time = formatTime(list[i].time);
list[i].time = $util.formatTime(list[i].time);
}
self.socket.emit("listPlaylists", {
pllist: list,
@ -519,7 +518,7 @@ User.prototype.initCallbacks = function() {
if(err)
list = [];
for(var i = 0; i < list.length; i++) {
list[i].time = formatTime(list[i].time);
list[i].time = $util.formatTime(list[i].time);
}
self.socket.emit("listPlaylists", {
pllist: list,

View File

@ -25,5 +25,33 @@ module.exports = {
// /24 range
return ip.replace(/\d+\.\d+\.(\d+)/, "x.x.$1.*");
}
},
formatTime: function (sec) {
if(sec === "--:--")
return sec;
sec = Math.floor(+sec);
var h = "", m = "", s = "";
if(sec >= 3600) {
h = "" + Math.floor(sec / 3600);
if(h.length < 2)
h = "0" + h;
sec %= 3600;
}
m = "" + Math.floor(sec / 60);
if(m.length < 2)
m = "0" + m;
s = "" + (sec % 60);
if(s.length < 2)
s = "0" + s;
if(h === "")
return [m, s].join(":");
return [h, m, s].join(":");
}
};