plex-web-downloader/routes/show.js

68 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-09-23 16:32:17 -04:00
var express = require('express');
var router = express.Router();
2015-09-23 18:29:36 -04:00
function formatDuree(time) {
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 "";
}
}
function addZero(v) {
return v.toString().replace(/^(\d)$/,'0$1');
};
2015-09-23 16:32:17 -04:00
/* GET home page. */
router.get('/:id', function(req, res, next) {
var config = require('../config');
var db = config.init_db();
2015-09-23 17:29:23 -04:00
var data = [];
2015-09-23 16:32:17 -04:00
//on fais toute les opération de base a la suite
db.serialize(function() {
2015-09-23 18:41:47 -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 "
+ " WHERE t.metadata_item_id = i.id AND i.parent_id = ? ",req.params.id, function(err, row) {
2015-09-23 16:32:17 -04:00
console.log(err);
console.log(row);
2015-09-23 18:41:47 -04:00
/*//découpage des hints
2015-09-23 16:32:17 -04:00
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;
if(typeof row.info_meta !== 'undefined' && typeof row.info_meta.season !== 'undefined' && typeof row.info_meta.episode !== 'undefined'){
row.season_episode = "S"+addZero(row.info_meta.season)+"E"+addZero(row.info_meta.episode);
2015-09-23 18:41:47 -04:00
}*/
2015-09-23 16:32:17 -04:00
row.duree = formatDuree(row.second);
data.push(row);
},
//aprés toute les opération de la base
function() {
2015-09-23 18:29:36 -04:00
res.render('show',{
2015-09-23 17:39:18 -04:00
title: 'Episode de '+req.params.id,
channel: {
'name': 'Episode de '+req.params.id,
'type': 2
},
videos: data
});
2015-09-23 16:32:17 -04:00
});
});
db.close();
});
module.exports = router;