From 832fa43aab40d0b168986a83c5248f68f861a1fd Mon Sep 17 00:00:00 2001 From: Greg Bekher Date: Sat, 12 Nov 2016 17:59:42 -0500 Subject: [PATCH 1/3] tweaks and parse song duration --- config.js | 2 +- package.json | 4 ++- server.js | 81 ++++++++++++++++++++++++++--------------------- webpack.config.js | 2 +- 4 files changed, 50 insertions(+), 39 deletions(-) diff --git a/config.js b/config.js index 41a433b..3170c70 100644 --- a/config.js +++ b/config.js @@ -11,6 +11,6 @@ module.exports = { mongoose: { debug: true }, - dev: false + dev: true } diff --git a/package.json b/package.json index 9df83bd..172498a 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "babel-preset-stage-0": "^6.5.0", "babel-runtime": "^6.6.1", "express": "^4.13.4", + "hh-mm-ss": "^1.1.0", "history": "^1.13.1", "id3js": "^1.1.3", "jquery": "^2.2.3", @@ -27,6 +28,7 @@ "mongoose": "^4.4.12", "mongoose-schema-extend": "^0.2.2", "multer": "^1.1.0", + "node-ffprobe": "^1.2.2", "proxy-middleware": "^0.15.0", "react": "^15.0.1", "react-document-title": "^2.0.1", @@ -39,6 +41,6 @@ "webpack": "^1.12.14" }, "devDependencies": { - "webpack-dev-middleware": "^1.6.1" + "webpack-dev-middleware": "^1.8.4" } } diff --git a/server.js b/server.js index eb51ea0..804fda6 100755 --- a/server.js +++ b/server.js @@ -1,3 +1,4 @@ +// imports var path = require('path'); var config = require('./config'); var express = require('express'); @@ -5,13 +6,14 @@ var webpack = require('webpack'); var util = require('util'); var fs = require('fs'); var id3 = require('id3js'); -var wpConfig = require('./webpack.config'); var async = require('async'); var _ = require('lodash'); -//var proxy = require('proxy-middleware'); var url = require('url'); var exec = require('child_process').exec; +var multer = require('multer'); +var probe = require('node-ffprobe'); +// mongo var mongoose = require('mongoose'); mongoose.set('debug', config.mongoose && config.mongoose.debug); require('./models/Song'); @@ -20,17 +22,19 @@ var database = mongoose.connect(config.db || '', config.dbOptions || {}, functio console.error('Mongo error:' + err.message); } }); + var SongSchema = mongoose.model('Song'); //use strict +// web & socket.io var app = express(); var server = require('http').Server(app); + +var wpConfig = require('./webpack.config'); var compiler = webpack(wpConfig); var io = require('socket.io')(server); var ioroutes = require('./io.js'); -//var fileupload = require('fileupload').createFileUpload(__dirname+'/uploads').middleware; -var multer = require('multer'); ioroutes(io); app.socket = io; @@ -40,7 +44,7 @@ app.use(multer({ dest: "./uploads" }).any()); -var port = 8302; +var port = config.http.port; var host = '0.0.0.0' app.set('view engine', 'html'); @@ -57,7 +61,8 @@ app.post('/upload', function(req, res) { console.log('uploading...'); //var mp3data = fs.readFileSync(__dirname+'/'+req.files[0].path); //console.log(audioMetaData.mp3(mp3data)); - id3({file: __dirname+'/'+req.files[0].path, type: id3.OPEN_LOCAL}, function(err, data) { + var songPath = __dirname+'/'+req.files[0].path; + id3({file: songPath, type: id3.OPEN_LOCAL}, function(err, data) { if (err) { console.log('Error parsing mp3 metadata' + err); res.redirect('/#/'); @@ -73,28 +78,32 @@ app.post('/upload', function(req, res) { console.log('song already in database'); } else { console.log('song not in db, adding'); - var songobj = { - title: title, - transform: 'None', - length: '3:'+String(myRandom(1,59)), - created: new Date(), - format: 'mp3', - artist: String(data.artist) || 'No artist', - album: String(data.album) || 'No album', - completed: false, - filename: filename - }; - new SongSchema(songobj).save(function(err, songitem) { - if (err) { - console.log('Mongoose error while saving '+err); - } else { - console.log('Saved song!'); - } + probe(songPath, function(err, ffData) { + var songobj = { + title: title, + transform: 'None', + length: require('hh-mm-ss').fromS(parseInt(ffData.format.duration)), + created: new Date(), + format: 'mp3', + artist: String(data.artist) || 'No artist', + album: String(data.album) || 'No album', + genre: String(ffData.metadata.genre) || 'Genre unknown', + completed: false, + filename: filename + }; + new SongSchema(songobj).save(function(err, songitem) { + if (err) { + console.log('Mongoose error while saving '+err); + } else { + console.log('Saved song!'); + } + }); + console.log('redirecting....'); + res.redirect('/app/#/view/'+filename); }); - console.log('redirecting....'); } }); - res.redirect('/app/#/view/'+filename); + res.redirect('/app/#/view/'+filename); } }); }); @@ -110,26 +119,26 @@ app.get('/transform/:id/:type', function(req, res) { var target = 'python '+__dirname+'/dream.py '+ __dirname+'/uploads/'+req.params.id+' '+req.params.type console.log('executing: '+target); exec(target, function(err, stdout, stderr) { - console.log('stdout: ${stdout}'); - console.log('stderr: ${stderr}'); - if (err) { - console.log('error '+err); - } + console.log('stdout: ${stdout}'); + console.log('stderr: ${stderr}'); + if (err) { + console.log('error '+err); + } }); } } //child_process. -); - res.redirect('/app/#/view/'+req.params.id); + ); + res.redirect('/app/#/view/'+req.params.id); }); + if (config.dev) { - // hot middleware that causes only issues app.use(require('webpack-dev-middleware')(compiler, { - noInfo: false, - quiet: false, - lazy: false, + noInfo: true, + quiet: true, + lazy: true, watchOptions: { aggregateTimeout: 300, poll: true diff --git a/webpack.config.js b/webpack.config.js index f9baa16..1af800e 100755 --- a/webpack.config.js +++ b/webpack.config.js @@ -10,7 +10,7 @@ module.exports = { ], devtool: 'eval-source-map', output: { - path: __dirname, + path: __dirname + '/build', filename: 'app.js', publicPath: '/pub/' }, From 129be8e3c566021332ed3bdeadb754ce935c3de7 Mon Sep 17 00:00:00 2001 From: Greg Bekher Date: Sun, 13 Nov 2016 14:58:10 -0500 Subject: [PATCH 2/3] add wavesurfer js, clean ui slightly, need to wavesurf output song next --- assets/components/Header.js | 34 +- assets/components/IndexPage.js | 8 +- assets/components/Loading.js | 15 + assets/components/MainPage.js | 2 +- assets/components/UploadPage.js | 9 +- assets/components/ViewOnePage.js | 170 ++++++--- build/app.js | 624 ++++++++++++++++--------------- build/css/main.css | 329 ++++++++++++++++ build/index.html | 3 + 9 files changed, 820 insertions(+), 374 deletions(-) create mode 100755 assets/components/Loading.js create mode 100644 build/css/main.css diff --git a/assets/components/Header.js b/assets/components/Header.js index fb0dc83..1647c0d 100755 --- a/assets/components/Header.js +++ b/assets/components/Header.js @@ -1,26 +1,44 @@ import React from 'react'; import { Link } from 'react-router'; +var css = { + navbar: { + background: "#7A6CBB" + }, + a: { + "font-size": "16px", + color: "#fff", + "text-shadow": "none", + }, + brand: { + "font-size": "22px", + color: "#fff", + "text-shadow": "none", + } +} export default class Header extends React.Component { render() { return ( -