From b077b7b2b63343d5e19f37ac02c5855841317f6d Mon Sep 17 00:00:00 2001 From: WEBER Antoine Date: Wed, 23 Sep 2015 22:32:17 +0200 Subject: [PATCH] WIP: ajout d'une liste de serie --- app.js | 2 ++ routes/channel.js | 2 +- routes/show.js | 70 ++++++++++++++++++++++++++++++++++++++++++++ routes/show_list.js | 56 +++++++++++++++++++++++++++++++++++ views/index.jade | 5 +++- views/show_list.jade | 24 +++++++++++++++ 6 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 routes/show.js create mode 100644 routes/show_list.js create mode 100644 views/show_list.jade diff --git a/app.js b/app.js index f33c838..5aa5939 100644 --- a/app.js +++ b/app.js @@ -29,6 +29,8 @@ app.use('/users', require('./routes/users')); app.use('/file', require('./routes/file')); app.use('/channel', require('./routes/channel')); 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 app.use(function(req, res, next) { diff --git a/routes/channel.js b/routes/channel.js index 5ebb6e6..25889c8 100644 --- a/routes/channel.js +++ b/routes/channel.js @@ -56,7 +56,7 @@ router.get('/:id', function(req, res, next) { 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" + " 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) { //découpage des hints diff --git a/routes/show.js b/routes/show.js new file mode 100644 index 0000000..abd4f4d --- /dev/null +++ b/routes/show.js @@ -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; diff --git a/routes/show_list.js b/routes/show_list.js new file mode 100644 index 0000000..53aca9e --- /dev/null +++ b/routes/show_list.js @@ -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; diff --git a/views/index.jade b/views/index.jade index 50b248f..63b7769 100644 --- a/views/index.jade +++ b/views/index.jade @@ -6,4 +6,7 @@ block content ul each channel, i in channels 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 diff --git a/views/show_list.jade b/views/show_list.jade new file mode 100644 index 0000000..32ddb2e --- /dev/null +++ b/views/show_list.jade @@ -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" + } + }); + });