plex-web-downloader/routes/channel.js

61 lines
1.7 KiB
JavaScript
Raw Normal View History

2015-09-15 04:41:00 -04:00
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/:id', function(req, res, next) {
var config = res.locals.config;
2015-09-15 04:41:00 -04:00
var db = config.init_db();
var data = [];
2015-09-15 11:21:39 -04:00
var channel_info = [];
2015-09-22 09:50:53 -04:00
function addZero(v) {
return v.toString().replace(/^(\d)$/,'0$1');
};
function formatDuree(time) {
2015-09-22 10:05:43 -04:00
if(typeof time !== 'undefined' && time != "" && time > 0){
var d = new Date(time); // js fonctionne en milisecondes
return addZero(d.getHours()-1) + "h "+ addZero(d.getMinutes()) + "m "+ addZero(d.getSeconds()) + "s ";
}
else {
return "";
}
2015-09-22 09:50:53 -04:00
}
2015-09-15 04:41:00 -04:00
//on fais toute les opération de base a la suite
db.serialize(function() {
//db.run("CREATE TABLE if not exists user_info (info TEXT)");
//var stmt = db.prepare("INSERT INTO user_info VALUES (?)");
//for (var i = 0; i < 10; i++) {
// stmt.run("Ipsum " + i);
//}
//stmt.finalize();
2015-09-22 10:05:43 -04:00
2015-09-15 11:21:39 -04:00
db.get("SELECT id, name, section_type as type"
2015-09-22 08:56:32 -04:00
+ " FROM library_sections WHERE id = ? ORDER BY name ASC",req.params.id, function(err, row) {
2015-09-15 11:21:39 -04:00
channel_info = row;
});
2015-09-23 18:02:59 -04:00
2015-09-23 18:17:03 -04:00
db.each("SELECT i.id as id, i.title as title, i.duration as second, i.year as year"
+ " FROM metadata_items i, media_items t "
+ " WHERE i.id = t.metadata_item_id AND i.title != '' AND t.library_section_id = ? "
2015-09-23 18:24:51 -04:00
+ " GROUP BY i.id",req.params.id, function(err, row) {
2015-09-15 11:21:39 -04:00
2015-09-22 09:50:53 -04:00
row.duree = formatDuree(row.second);
2015-09-15 11:21:39 -04:00
data.push(row);
2015-09-15 04:41:00 -04:00
},
//aprés toute les opération de la base
function() {
2015-09-15 11:21:39 -04:00
res.render('channel', { title: 'Liste des vidéos',videos: data, channel: channel_info });
2015-09-15 04:41:00 -04:00
});
});
db.close();
});
module.exports = router;