Skip to content

Instantly share code, notes, and snippets.

@andrewrk
Created December 16, 2012 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrewrk/4312843 to your computer and use it in GitHub Desktop.
Save andrewrk/4312843 to your computer and use it in GitHub Desktop.
mediablast server example
/node_modules

mediablast Server Example

Get the Server Running

npm install
npm start

Try the Audio Template

  1. Start the mediablast server: npm start
  2. Go to http://localhost:14007/admin/settings
  3. Put your s3 credentials into the audio template and press save.
  4. Open a window to http://localhost:14007/admin/status and move it to the side so you can watch it while you perform the test.
  5. Open another window to http://localhost:14007/admin/test
  6. Paste the audio template id into the box. The audio template id is c5014d30-47d1-11e2-bcfd-0800200c9a66.
  7. Use the file chooser input and choose an audio file.
  8. Watch the /admin/status window that you have open.
  9. Have a look at the files that were created in your s3 bucket.

Try the Image Template

  1. Start the mediablast server: npm start
  2. Go to http://localhost:14007/admin/settings
  3. Put your s3 credentials into the image template and press save.
  4. Open a window to http://localhost:14007/admin/status and move it to the side so you can watch it while you perform the test.
  5. Open another window to http://localhost:14007/admin/test
  6. Paste the image template id into the box. The image template id is c9961790-47d1-11e2-bcfd-0800200c9a66.
  7. Use the file chooser input and choose an image file.
  8. Watch the /admin/status window that you have open.
  9. Have a look at the files that were created in your s3 bucket.
{
"name": "mediablast-example",
"private": true,
"version": "0.0.0",
"description": "mediablast server example",
"author": "Andrew Kelley",
"license": "MIT",
"dependencies": {
"plan-callback": "~0.0.1",
"plan-transcode": "~0.0.2",
"plan-waveform": "~0.0.4",
"plan-s3-download": "~0.1.0",
"plan-s3-upload": "~0.1.4",
"plan-thumbnail": "~0.1.0",
"mediablast": "~0.0.1"
}
}
var mediablast = require('mediablast')
, http = require('http')
, path = require('path')
var env = {
NODE_ENV: process.env.NODE_ENV = process.env.NODE_ENV || 'dev',
HOST: process.env.HOST || '0.0.0.0',
PORT: parseInt(process.env.PORT || '14007', 10),
};
console.log("Using environment:", env);
var app = mediablast({
settingsFile: path.join(__dirname, "settings.json")
});
app.registerTask('audio.transcode', require('plan-transcode'));
app.registerTask('audio.waveform', require('plan-waveform'));
app.registerTask('image.thumbnail', require('plan-thumbnail'));
app.registerTask('s3.upload', require('plan-s3-upload'));
app.registerTask('s3.download', require('plan-s3-download'));
app.registerTask('meta.callback', require('plan-callback'));
var server = http.createServer(app);
server.listen(env.PORT, env.HOST, function() {
console.log("Listening at http://" + env.HOST + ":" + env.PORT);
if (process.send) process.send('online');
});
{
"completed_job_lifespan": 60,
"templates": {
"c5014d30-47d1-11e2-bcfd-0800200c9a66": {
"options": {
"s3.upload": {
"s3Key": "your s3 key",
"s3Secret": "your s3 secret",
"s3Bucket": "your s3 bucket"
}
},
"tasks": {
"original": {
"task": "s3.upload",
"options": {
"url": "{uuid}/original{ext}"
}
},
"waveform": {
"task": "audio.waveform",
"options": {
"width": 1800,
"height": 200,
"colorCenter": "0081daff",
"colorOuter": "004678ff",
"colorBg": "00000000"
}
},
"waveform_upload": {
"task": "s3.upload",
"options": {
"url": "{uuid}/waveform{ext}"
},
"dependencies": [
"waveform"
]
},
"preview": {
"task": "audio.transcode",
"options": {
"bit_rate": 192,
"sample_rate": 44100,
"format": "mp3"
}
},
"preview_upload": {
"task": "s3.upload",
"options": {
"url": "{uuid}/preview{ext}"
},
"dependencies": [
"preview"
]
}
}
},
"c9961790-47d1-11e2-bcfd-0800200c9a66": {
"options": {
"s3.upload": {
"s3Key": "your s3 key",
"s3Secret": "your s3 secret",
"s3Bucket": "your s3 bucket"
}
},
"tasks": {
"original": {
"task": "s3.upload",
"options": {
"url": "{uuid}/original{ext}"
}
},
"tiny": {
"task": "image.thumbnail",
"options": {
"format": "png",
"width": 30,
"height": 30,
"crop": false
}
},
"tiny_upload": {
"task": "s3.upload",
"options": {
"url": "{uuid}/tiny{ext}"
},
"dependencies": [
"tiny"
]
},
"medium": {
"task": "image.thumbnail",
"options": {
"format": "png",
"width": 56,
"height": 56,
"crop": false
}
},
"medium_upload": {
"task": "s3.upload",
"options": {
"url": "{uuid}/medium{ext}"
},
"dependencies": [
"medium"
]
}
}
}
},
"auth": {
"username": "admin",
"password": "3pTkHwHV"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment