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,",
|
"`user` VARCHAR(20) NOT NULL,",
|
||||||
"`name` VARCHAR(255) NOT NULL,",
|
"`name` VARCHAR(255) NOT NULL,",
|
||||||
"`contents` MEDIUMTEXT NOT NULL,",
|
"`contents` MEDIUMTEXT NOT NULL,",
|
||||||
|
"`count` INT NOT NULL,",
|
||||||
|
"`time` INT NOT NULL,",
|
||||||
"PRIMARY KEY (`name`))",
|
"PRIMARY KEY (`name`))",
|
||||||
"ENGINE = MyISAM;"].join("");
|
"ENGINE = MyISAM;"].join("");
|
||||||
results = db.querySync(query);
|
results = db.querySync(query);
|
||||||
|
@ -753,7 +755,7 @@ function getUserPlaylists(user) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var query = createQuery(
|
var query = createQuery(
|
||||||
"SELECT name FROM user_playlists WHERE user=?",
|
"SELECT name,count,time FROM user_playlists WHERE user=?",
|
||||||
[user]
|
[user]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -804,19 +806,22 @@ function saveUserPlaylist(pl, user, name) {
|
||||||
|
|
||||||
// Strip out unnecessary data
|
// Strip out unnecessary data
|
||||||
var pl2 = [];
|
var pl2 = [];
|
||||||
|
var time = 0;
|
||||||
for(var i = 0; i < pl.length; i++) {
|
for(var i = 0; i < pl.length; i++) {
|
||||||
var e = {
|
var e = {
|
||||||
id: pl[i].id,
|
id: pl[i].id,
|
||||||
type: pl[i].type
|
type: pl[i].type
|
||||||
};
|
};
|
||||||
|
time += pl[i].seconds;
|
||||||
pl2.push(e);
|
pl2.push(e);
|
||||||
}
|
}
|
||||||
|
var count = pl2.length;
|
||||||
var plstr = JSON.stringify(pl2);
|
var plstr = JSON.stringify(pl2);
|
||||||
|
|
||||||
var query = createQuery(
|
var query = createQuery(
|
||||||
"INSERT INTO user_playlists VALUES (?, ?, ?)" +
|
"INSERT INTO user_playlists VALUES (?, ?, ?, ?, ?)" +
|
||||||
"ON DUPLICATE KEY UPDATE contents=?",
|
"ON DUPLICATE KEY UPDATE contents=?,count=?,time=?",
|
||||||
[user, name, plstr, plstr]
|
[user, name, plstr, count, time, plstr, count, time]
|
||||||
);
|
);
|
||||||
|
|
||||||
var results = db.querySync(query);
|
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 Rank = require("./rank.js");
|
||||||
var Auth = require("./auth.js");
|
var Auth = require("./auth.js");
|
||||||
var Channel = require("./channel.js").Channel;
|
var Channel = require("./channel.js").Channel;
|
||||||
|
var formatTime = require("./media.js").formatTime;
|
||||||
var Server = require("./server.js");
|
var Server = require("./server.js");
|
||||||
var Database = require("./database.js");
|
var Database = require("./database.js");
|
||||||
var Logger = require("./logger.js");
|
var Logger = require("./logger.js");
|
||||||
|
@ -425,6 +426,9 @@ User.prototype.initCallbacks = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var list = Database.getUserPlaylists(this.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", {
|
this.socket.emit("listPlaylists", {
|
||||||
pllist: list,
|
pllist: list,
|
||||||
});
|
});
|
||||||
|
@ -458,6 +462,9 @@ User.prototype.initCallbacks = function() {
|
||||||
error: result ? false : "Unknown"
|
error: result ? false : "Unknown"
|
||||||
});
|
});
|
||||||
var list = Database.getUserPlaylists(this.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", {
|
this.socket.emit("listPlaylists", {
|
||||||
pllist: list,
|
pllist: list,
|
||||||
});
|
});
|
||||||
|
@ -476,6 +483,9 @@ User.prototype.initCallbacks = function() {
|
||||||
|
|
||||||
Database.deleteUserPlaylist(this.name, data.name);
|
Database.deleteUserPlaylist(this.name, data.name);
|
||||||
var list = Database.getUserPlaylists(this.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", {
|
this.socket.emit("listPlaylists", {
|
||||||
pllist: list,
|
pllist: list,
|
||||||
});
|
});
|
||||||
|
|
|
@ -775,6 +775,14 @@ Callbacks = {
|
||||||
$("<div/>").text(pls[i].name).appendTo(li)
|
$("<div/>").text(pls[i].name).appendTo(li)
|
||||||
.css("float", "left")
|
.css("float", "left")
|
||||||
.css("margin-left", "1em");
|
.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")
|
var bg = $("<div/>").addClass("btn-group")
|
||||||
.css("float", "left")
|
.css("float", "left")
|
||||||
.prependTo(li);
|
.prependTo(li);
|
||||||
|
|
Loading…
Reference in New Issue