Browse Source

Add player package, download music as mp3 for player

Josh Bicking 7 years ago
parent
commit
4b381264d2
6 changed files with 20 additions and 10 deletions
  1. 0 1
      app.js
  2. 1 0
      package.json
  3. 16 6
      routes/index.js
  4. 1 1
      views/file.hbs
  5. 1 1
      views/index.hbs
  6. 1 1
      views/youtube.hbs

+ 0 - 1
app.js

@@ -56,5 +56,4 @@ app.use(function(err, req, res, next) {
   });
 });
 
-
 module.exports = app;

+ 1 - 0
package.json

@@ -13,6 +13,7 @@
     "express-validator": "^3.1.2",
     "hbs": "~4.0.0",
     "morgan": "~1.7.0",
+    "player": "^0.6.1",
     "serve-favicon": "~2.3.0"
   }
 }

+ 16 - 6
routes/index.js

@@ -8,13 +8,24 @@ router.use(expressValidator());
 
 var child_process = require('child_process');
 
+var Player = require('player');
+
+/* Example player code
+var player = new Player('./downloads/Doodlebob - Bring Me to Life.mp3');
+// play now and callback when playend 
+player.play(function(err, player){
+    console.log('playend!');
+});
+player.play();
+*/
+
 /* GET home page. */
 router.get('/', function(req, res, next) {
-  res.render('index', { title: 'LAN Jukebox' });
+  res.render('index');
 });
 
 router.get('/youtube', function(req, res, next) {
-  res.render('youtube', { title: 'LAN Jukebox - Add a Youtube Video' });
+  res.render('youtube');
 });
 
 router.use(expressValidator({
@@ -41,18 +52,17 @@ router.post('/youtube', function(req, res) {
     
     if(errors){
 	res.render('youtube', {
-	    title: 'LAN Jukebox - Add a Youtube Video',
 	    errors:errors
 	});
     } else {
-	var youtube_dl = child_process.spawn('/usr/bin/youtube-dl', ['-x', '-o', 'downloads/%(title)s.%(ext)s', video]);
+	var youtube_dl = child_process.spawn('/usr/bin/youtube-dl', ['-x', '--audio-format', 'mp3', '-o', 'downloads/%(title)s.%(ext)s', video]);
 	// TODO eval video
-	res.render('index', { title: 'LAN Jukebox' });
+	res.render('index');
     }
 });
 
 router.get('/file', function(req, res, next) {
-  res.render('file', { title: 'LAN Jukebox - Add a Music File' });
+  res.render('file');
 });
 
 module.exports = router;

+ 1 - 1
views/file.hbs

@@ -1,5 +1,5 @@
 <a href="/">Back</a>
-<h1>{{title}}</h1>
+<h1>LAN Jukebox - Add a Music File</h1>
 {{#if errors}}
       {{#each errors}}
         <div class="alert alert-danger">{{msg}}</div>

+ 1 - 1
views/index.hbs

@@ -1,4 +1,4 @@
-<h1>{{title}}</h1>
+<h1>LAN Jukebox</h1>
 <a href="/youtube">Add a Youtube video</a><br/>
 <a href="/file">Add a music file</a><br/>
 <p>Allan put music player here</p>

+ 1 - 1
views/youtube.hbs

@@ -1,5 +1,5 @@
 <a href="/">Back</a>
-<h1>{{title}}</h1>
+<h1>LAN Jukebox - Add a Youtube Video</h1>
 {{#if errors}}
       {{#each errors}}
         <div class="alert alert-danger">{{msg}}</div>