plex-web-downloader/routes/show.js

74 lines
2.0 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/:incoming_chan', function(req, res, next) {
var config = res.locals.config;
2015-09-23 16:32:17 -04:00
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-24 12:25:48 -04:00
db.each("SELECT episode.id as id, episode.title as titre, episode.[index] as episode, episode.duration as second, season.[index] as saison, show.title as serie "+
2015-09-23 19:05:13 -04:00
"FROM metadata_items episode,metadata_items season,metadata_items show "+
"WHERE episode.parent_id=season.id AND season.parent_id = show.id AND show.id = ? ",req.params.id, function(err, row) {
2015-09-24 12:15:40 -04:00
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;
2015-09-24 12:15:40 -04:00
*/
2015-09-23 16:32:17 -04:00
2015-09-24 12:15:40 -04:00
if(typeof row.episode !== '' && row.saison !== '' ){
row.season_episode = "S"+addZero(row.saison)+"E"+addZero(row.episode );
2015-09-23 19:05:13 -04:00
}
2015-09-23 16:32:17 -04:00
2015-09-24 12:15:40 -04:00
row.duree = formatDuree(row.second);
2015-09-23 16:32:17 -04:00
data.push(row);
},
function() {
2015-09-24 12:15:40 -04:00
//a la fin du foreach
});
2015-09-24 12:22:21 -04:00
db.close(function(){
//aprés toute les opération de la base
var titre = "Série inexistante";
2015-09-24 12:25:48 -04:00
if(data.length > 0){
2015-09-24 12:27:42 -04:00
titre = 'Episode de '+data[0].serie;
2015-09-24 12:22:21 -04:00
}
res.render('show',{
title: titre,
videos: data,
2015-10-07 12:16:39 -04:00
channel_id: req.params.incoming_chan,
show_id: req.params.id
2015-09-24 12:22:21 -04:00
});
});
2015-09-24 12:15:40 -04:00
2015-09-23 16:32:17 -04:00
});
2015-09-24 12:22:21 -04:00
2015-09-23 16:32:17 -04:00
});
module.exports = router;