plex-web-downloader/routes/channel.js

63 lines
2.1 KiB
JavaScript
Raw Normal View History

2015-09-15 04:41:00 -04:00
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/:id', function(req, res, next) {
var config = require('../config');
var db = config.init_db();
var data = [];
2015-09-15 11:21:39 -04:00
var channel_info = [];
2015-09-15 04:41:00 -04:00
//on fais toute les opération de base a la suite
db.serialize(function() {
//db.run("CREATE TABLE if not exists user_info (info TEXT)");
//var stmt = db.prepare("INSERT INTO user_info VALUES (?)");
//for (var i = 0; i < 10; i++) {
// stmt.run("Ipsum " + i);
//}
//stmt.finalize();
2015-09-15 11:21:39 -04:00
db.get("SELECT id, name, section_type as type"
2015-09-22 08:56:32 -04:00
+ " FROM library_sections WHERE id = ? ORDER BY name ASC",req.params.id, function(err, row) {
2015-09-15 11:21:39 -04:00
channel_info = row;
});
db.each("SELECT i.id as id, i.title as title, t.hints as hints, p.file as file, i.duration as second, 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 = ? "
2015-09-15 04:41:00 -04:00
+ " ORDER BY i.title ASC",req.params.id, function(err, row) {
2015-09-15 11:21:39 -04:00
2015-09-15 04:41:00 -04:00
var tab = row.file.split('/');
var tab2 = tab[tab.length -1].split('\\');
var filename = tab2[tab2.length -1];
2015-09-15 11:21:39 -04:00
row.filename = filename;
//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;
2015-09-22 09:20:02 -04:00
//formattage des données
if(typeof row.info_meta !== 'undefined' && typeof row.info_meta.season !== 'undefined' && typeof row.info_meta.episode !== 'undefined'){
row.season_episode = "S"+row.info_meta.season.toString().replace(/^(\d)$/,'0$1')+"E"+row.info_meta.episode.toString().replace(/^(\d)$/,'0$1');
}
2015-09-15 11:21:39 -04:00
data.push(row);
2015-09-15 04:41:00 -04:00
},
//aprés toute les opération de la base
function() {
2015-09-15 11:21:39 -04:00
res.render('channel', { title: 'Liste des vidéos',videos: data, channel: channel_info });
2015-09-15 04:41:00 -04:00
});
});
db.close();
});
module.exports = router;