mirror of https://github.com/calzoneman/sync.git
Add playlist item count and playtime
This commit is contained in:
parent
04e81338ee
commit
d2271a020b
13
database.js
13
database.js
|
@ -131,6 +131,8 @@ function init() {
|
|||
"`user` VARCHAR(20) NOT NULL,",
|
||||
"`name` VARCHAR(255) NOT NULL,",
|
||||
"`contents` MEDIUMTEXT NOT NULL,",
|
||||
"`count` INT NOT NULL,",
|
||||
"`time` INT NOT NULL,",
|
||||
"PRIMARY KEY (`name`))",
|
||||
"ENGINE = MyISAM;"].join("");
|
||||
results = db.querySync(query);
|
||||
|
@ -753,7 +755,7 @@ function getUserPlaylists(user) {
|
|||
}
|
||||
|
||||
var query = createQuery(
|
||||
"SELECT name FROM user_playlists WHERE user=?",
|
||||
"SELECT name,count,time FROM user_playlists WHERE user=?",
|
||||
[user]
|
||||
);
|
||||
|
||||
|
@ -804,19 +806,22 @@ function saveUserPlaylist(pl, user, name) {
|
|||
|
||||
// Strip out unnecessary data
|
||||
var pl2 = [];
|
||||
var time = 0;
|
||||
for(var i = 0; i < pl.length; i++) {
|
||||
var e = {
|
||||
id: pl[i].id,
|
||||
type: pl[i].type
|
||||
};
|
||||
time += pl[i].seconds;
|
||||
pl2.push(e);
|
||||
}
|
||||
var count = pl2.length;
|
||||
var plstr = JSON.stringify(pl2);
|
||||
|
||||
var query = createQuery(
|
||||
"INSERT INTO user_playlists VALUES (?, ?, ?)" +
|
||||
"ON DUPLICATE KEY UPDATE contents=?",
|
||||
[user, name, plstr, plstr]
|
||||
"INSERT INTO user_playlists VALUES (?, ?, ?, ?, ?)" +
|
||||
"ON DUPLICATE KEY UPDATE contents=?,count=?,time=?",
|
||||
[user, name, plstr, count, time, plstr, count, time]
|
||||
);
|
||||
|
||||
var results = db.querySync(query);
|
||||
|
|
10
user.js
10
user.js
|
@ -12,6 +12,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||
var Rank = require("./rank.js");
|
||||
var Auth = require("./auth.js");
|
||||
var Channel = require("./channel.js").Channel;
|
||||
var formatTime = require("./media.js").formatTime;
|
||||
var Server = require("./server.js");
|
||||
var Database = require("./database.js");
|
||||
var Logger = require("./logger.js");
|
||||
|
@ -425,6 +426,9 @@ User.prototype.initCallbacks = function() {
|
|||
}
|
||||
|
||||
var list = Database.getUserPlaylists(this.name);
|
||||
for(var i = 0; i < list.length; i++) {
|
||||
list[i].time = formatTime(list[i].time);
|
||||
}
|
||||
this.socket.emit("listPlaylists", {
|
||||
pllist: list,
|
||||
});
|
||||
|
@ -458,6 +462,9 @@ User.prototype.initCallbacks = function() {
|
|||
error: result ? false : "Unknown"
|
||||
});
|
||||
var list = Database.getUserPlaylists(this.name);
|
||||
for(var i = 0; i < list.length; i++) {
|
||||
list[i].time = formatTime(list[i].time);
|
||||
}
|
||||
this.socket.emit("listPlaylists", {
|
||||
pllist: list,
|
||||
});
|
||||
|
@ -476,6 +483,9 @@ User.prototype.initCallbacks = function() {
|
|||
|
||||
Database.deleteUserPlaylist(this.name, data.name);
|
||||
var list = Database.getUserPlaylists(this.name);
|
||||
for(var i = 0; i < list.length; i++) {
|
||||
list[i].time = formatTime(list[i].time);
|
||||
}
|
||||
this.socket.emit("listPlaylists", {
|
||||
pllist: list,
|
||||
});
|
||||
|
|
|
@ -775,6 +775,14 @@ Callbacks = {
|
|||
$("<div/>").text(pls[i].name).appendTo(li)
|
||||
.css("float", "left")
|
||||
.css("margin-left", "1em");
|
||||
var metastr = pls[i].count + " item";
|
||||
if(pls[i].count != 1) {
|
||||
metastr += "s";
|
||||
}
|
||||
metastr +=", playtime " + pls[i].time;
|
||||
$("<div/>").text(metastr)
|
||||
.css("float", "right")
|
||||
.appendTo(li);
|
||||
var bg = $("<div/>").addClass("btn-group")
|
||||
.css("float", "left")
|
||||
.prependTo(li);
|
||||
|
|
Loading…
Reference in New Issue