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 = require('../config');
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
function humanFileSize(bytes, si) {
|
|
|
|
var thresh = si ? 1000 : 1024;
|
|
|
|
if(Math.abs(bytes) < thresh) {
|
|
|
|
return bytes + ' B';
|
|
|
|
}
|
|
|
|
var units = si
|
|
|
|
? ['kB','MB','GB','TB','PB','EB','ZB','YB']
|
|
|
|
: ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
|
|
|
|
var u = -1;
|
|
|
|
do {
|
|
|
|
bytes /= thresh;
|
|
|
|
++u;
|
|
|
|
} while(Math.abs(bytes) >= thresh && u < units.length - 1);
|
|
|
|
return bytes.toFixed(1)+' '+units[u];
|
2015-09-22 10:03:57 -04:00
|
|
|
}
|
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-22 10:03:57 -04:00
|
|
|
console.log("test2")
|
|
|
|
db.each("SELECT i.id as id, i.title as title, t.hints as hints, p.file as file, i.duration as second, t.size as size, i.year as year"
|
2015-09-15 11:21:39 -04:00
|
|
|
+ " FROM media_items t, metadata_items i, media_parts p "
|
|
|
|
+ " WHERE p.media_item_id=i.id AND t.metadata_item_id = i.id AND i.title != '' AND t.library_section_id = ? "
|
2015-09-15 04:41:00 -04:00
|
|
|
+ " ORDER BY i.title ASC",req.params.id, function(err, row) {
|
2015-09-15 11:21:39 -04:00
|
|
|
|
|
|
|
//découpage des hints
|
|
|
|
var params = {};
|
|
|
|
var tab = row.hints.split('&');
|
|
|
|
tab.forEach(function(val,index,table){
|
|
|
|
var tab2 = val.split('=');
|
|
|
|
params[tab2[0]] = decodeURIComponent(tab2[1]);
|
|
|
|
});
|
|
|
|
row.info_meta = params;
|
|
|
|
|
2015-09-22 09:20:02 -04:00
|
|
|
//formattage des données
|
2015-09-22 10:03:57 -04:00
|
|
|
var tab = row.file.split('/');
|
|
|
|
var tab2 = tab[tab.length -1].split('\\');
|
|
|
|
var filename = tab2[tab2.length -1];
|
|
|
|
row.filename = filename;
|
|
|
|
|
2015-09-22 09:20:02 -04:00
|
|
|
if(typeof row.info_meta !== 'undefined' && typeof row.info_meta.season !== 'undefined' && typeof row.info_meta.episode !== 'undefined'){
|
2015-09-22 09:50:53 -04:00
|
|
|
row.season_episode = "S"+addZero(row.info_meta.season)+"E"+addZero(row.info_meta.episode);
|
2015-09-22 09:20:02 -04:00
|
|
|
}
|
|
|
|
|
2015-09-22 09:50:53 -04:00
|
|
|
row.duree = formatDuree(row.second);
|
|
|
|
row.size = humanFileSize(row.size,true);
|
|
|
|
|
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;
|