WIP: ajout d'une liste de serie

This commit is contained in:
WEBER Antoine 2015-09-23 22:32:17 +02:00
parent ab4720f910
commit b077b7b2b6
6 changed files with 157 additions and 2 deletions

2
app.js
View File

@ -29,6 +29,8 @@ app.use('/users', require('./routes/users'));
app.use('/file', require('./routes/file')); app.use('/file', require('./routes/file'));
app.use('/channel', require('./routes/channel')); app.use('/channel', require('./routes/channel'));
app.use('/movie', require('./routes/movie')); app.use('/movie', require('./routes/movie'));
app.use('/show_list', require('./routes/show_list'));
app.use('/show', require('./routes/show'));
// catch 404 and forward to error handler // catch 404 and forward to error handler
app.use(function(req, res, next) { app.use(function(req, res, next) {

View File

@ -56,7 +56,7 @@ router.get('/:id', function(req, res, next) {
console.log("test2") 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" 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"
+ " FROM media_items t, metadata_items i, media_parts p " + " 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 = ? " + " WHERE p.media_item_id=t.id AND t.metadata_item_id = i.id AND i.title != '' AND t.library_section_id = ? "
+ " ORDER BY i.title ASC",req.params.id, function(err, row) { + " ORDER BY i.title ASC",req.params.id, function(err, row) {
//découpage des hints //découpage des hints

70
routes/show.js Normal file
View File

@ -0,0 +1,70 @@
var express = require('express');
var router = express.Router();
function btoa(string){
return new Buffer(string).toString('base64');
}
function atob(string){
return new Buffer(string, 'base64').toString('ascii');
}
/* GET home page. */
router.get('/:id', function(req, res, next) {
var config = require('../config');
var db = config.init_db();
var shows = {};
var id = atob(req.params.id);
console.log(id);
//on fais toute les opération de base a la suite
db.serialize(function() {
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"
+ " FROM media_items t, metadata_items i, media_parts p "
+ " WHERE p.media_item_id=t.id AND t.metadata_item_id = i.id AND i.title != '' AND t.hints LIKE '%show=?%' "
,id, function(err, row) {
console.log(err);
console.log(row);
//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;
//formattage des données
var tab = row.file.split('/');
var tab2 = tab[tab.length -1].split('\\');
var filename = tab2[tab2.length -1];
row.filename = filename;
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);
}
row.duree = formatDuree(row.second);
row.size = humanFileSize(row.size,true);
data.push(row);
},
//aprés toute les opération de la base
function() {
res.render('channel', { title: 'Liste des vidéos',channel:{
'name': "Liste de la série",
'type': 2
},videos: data });
});
});
db.close();
});
module.exports = router;

56
routes/show_list.js Normal file
View File

@ -0,0 +1,56 @@
var express = require('express');
var router = express.Router();
function btoa(string){
return new Buffer(string).toString('base64');
}
function atob(string){
return new Buffer(string, 'base64').toString('ascii');
}
/* GET home page. */
router.get('/:id', function(req, res, next) {
var config = require('../config');
var db = config.init_db();
var shows = {};
//on fais toute les opération de base a la suite
db.serialize(function() {
db.each("SELECT i.id as id, t.hints as hints, i.year as year"
+ " FROM media_items t, metadata_items i "
+ " WHERE t.metadata_item_id = i.id AND t.library_section_id = ? "
,req.params.id, function(err, row) {
//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;
var id = btoa(row.id);
shows[id] = {
'nom': params.show,
'id': id
};
if(row.year != '' && row.year != null)
show[id].year = row.year;
},
//aprés toute les opération de la base
function() {
console.log(shows);
res.render('show_list', { title: 'Liste des séries',shows: shows });
});
});
db.close();
});
module.exports = router;

View File

@ -6,4 +6,7 @@ block content
ul ul
each channel, i in channels each channel, i in channels
li li
a(href="/channel/#{channel.id}")= channel.name if(channel.type == 2)
a(href="/channel/#{channel.id}")= channel.name
else
a(href="/show_list/#{channel.id}")= channel.name

24
views/show_list.jade Normal file
View File

@ -0,0 +1,24 @@
extends layout
block content
h1= title
table(id="example", class="table table-striped table-bordered", cellspacing="0", width="100%")
thead
tr
th Série
th Année
tbody
each show, i in shows
tr
td
a(href="/show/#{show.id}")= show.nom
td= show.year
script.
$(document).ready(function() {
$('#example').DataTable({
"language": {
"url": "//cdn.datatables.net/plug-ins/1.10.8/i18n/French.json"
}
});
});