From dd0410eac77887e20776addc98fe3333107cb16b Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Fri, 23 Aug 2013 21:06:29 -0500 Subject: [PATCH] Fix video lengths not showing in library --- channel.js | 7 +++++-- media.js | 32 +------------------------------- package.json | 2 +- server.js | 2 +- user.js | 7 +++---- utilities.js | 28 ++++++++++++++++++++++++++++ 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/channel.js b/channel.js index ae29c50b..a261d16b 100644 --- a/channel.js +++ b/channel.js @@ -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 diff --git a/media.js b/media.js index 6944b094..7dae37c7 100644 --- a/media.js +++ b/media.js @@ -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) { diff --git a/package.json b/package.json index 03681734..89e4d2db 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/server.js b/server.js index 9d16a427..65118009 100644 --- a/server.js +++ b/server.js @@ -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; diff --git a/user.js b/user.js index 65b81427..7978fbf1 100644 --- a/user.js +++ b/user.js @@ -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, diff --git a/utilities.js b/utilities.js index 0e401cb4..b4d5efe8 100644 --- a/utilities.js +++ b/utilities.js @@ -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(":"); } };