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. */
2015-10-07 12:03:22 -04:00
router . get ( '/:id/:incoming_chan' , function ( req , res , next ) {
2015-09-29 17:04:17 -04:00
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
2017-09-27 09:09:25 -04:00
//we do all the basic operations following
2015-09-23 16:32:17 -04:00
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 ( ) {
2017-09-27 09:09:25 -04:00
//after all the operations of the database
2015-09-24 12:22:21 -04:00
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 ,
2015-10-07 12:03:22 -04:00
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 ;