Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

code import

  • Loading branch information...
commit 0d9f210f5d7a08de671fdd8f33ed46c48814fed9 1 parent 539cd7a
Conrad Pankoff authored
1  .gitignore
View
@@ -0,0 +1 @@
+/test*.mp3
26 LICENSE.md
View
@@ -0,0 +1,26 @@
+Copyright (c) 2011, Deoxxa Development
+======================================
+All rights reserved.
+--------------------
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+3. Neither the name of Deoxxa Development nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY DEOXXA DEVELOPMENT ''AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL DEOXXA DEVELOPMENT BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
132 README.md
View
@@ -0,0 +1,132 @@
+Mediainfo
+=========
+
+Wrapper around the `mediainfo` command for obtaining information about media
+files.
+
+Overview
+--------
+
+This module provides an interface to the `mediainfo` command. It returns the
+(parsed) output of the command with all the keys lower-cased. There's not a lot
+to say here.
+
+Usage
+-----
+
+The module exposes just one function, which has a signature of:
+
+`mediainfo("/path/to/file", "/path/to/other/file", [...], callback)`
+
+The callback function is called, in familiar node fashion, with two arguments.
+The first is an Error object on error, or null on success. The second argument
+is an array of objects, forming what you'd expect from the output of mediainfo,
+if it were mangled into a JSON object.
+
+It's really easier to just see the output, so here:
+
+```
+[
+ {
+ tracks: [
+ {
+ type: 'Audio',
+ format: 'MPEG Audio',
+ format_version: 'Version 1',
+ format_profile: 'Layer 3',
+ mode: 'Joint stereo',
+ duration: '3mn 2s',
+ bit_rate_mode: 'Constant',
+ bit_rate: '320 Kbps',
+ channel_s_: '2 channels',
+ sampling_rate: '44.1 KHz',
+ compression_mode: 'Lossy',
+ stream_size: '6.97 MiB (100%)',
+ writing_library: 'LAME3.97'
+ }
+ ],
+ complete_name: 'test1.mp3',
+ format: 'MPEG Audio',
+ file_size: '6.98 MiB',
+ duration: '3mn 2s',
+ overall_bit_rate: '320 Kbps',
+ album: 'We No Speak Americano (High Rankin\'s Bait n Wobble Mix)',
+ track_name: 'We No Speak Americano (High Rankin\'s Bait n Wobble Mix)',
+ track_name_position: '1',
+ track_name_total: '1',
+ performer: 'Yolanda Be Cool & DCUP',
+ accompaniment: 'High Rankin',
+ genre: 'Dubstep',
+ recorded_date: '2010',
+ writing_library: 'LAME in FL Studio 8 / LAME3.97'
+ },
+ {
+ tracks: [
+ {
+ type: 'Audio',
+ format: 'MPEG Audio',
+ format_version: 'Version 1',
+ format_profile: 'Layer 3',
+ mode: 'Joint stereo',
+ duration: '3mn 2s',
+ bit_rate_mode: 'Constant',
+ bit_rate: '320 Kbps',
+ channel_s_: '2 channels',
+ sampling_rate: '44.1 KHz',
+ compression_mode: 'Lossy',
+ stream_size: '6.97 MiB (100%)',
+ writing_library: 'LAME3.97'
+ }
+ ],
+ complete_name: 'test2.mp3',
+ format: 'MPEG Audio',
+ file_size: '6.98 MiB',
+ duration: '3mn 2s',
+ overall_bit_rate: '320 Kbps',
+ album: 'We No Speak Americano (High Rankin\'s Bait n Wobble Mix)',
+ track_name: 'We No Speak Americano (High Rankin\'s Bait n Wobble Mix)',
+ track_name_position: '1',
+ track_name_total: '1',
+ performer: 'Yolanda Be Cool & DCUP',
+ accompaniment: 'High Rankin',
+ genre: 'Dubstep',
+ recorded_date: '2010',
+ writing_library: 'LAME in FL Studio 8 / LAME3.97'
+ }
+]
+```
+
+(bite me, it's a decent track)
+
+Example
+-------
+
+```javascript
+var mediainfo = require("mediainfo");
+
+mediainfo("/path/to/something.mp3", function(err, res) {
+ if (err) {
+ return console.log(err);
+ }
+
+ console.log(res);
+});
+```
+
+Requirements
+------------
+
+The `mediainfo` command has to be available somewhere in the PATH of the user
+node is running as.
+
+License
+-------
+
+BSD, 3-clause. A copy is included.
+
+Contact
+-------
+
+* Email: [deoxxa@fknsrs.biz](mailto:deoxxa@fknsrs.biz)
+* Github: [deoxxa](https://github.com/deoxxa)
+* Twitter: [deoxxa](http://twitter.com/#!/deoxxa)
12 example.js
View
@@ -0,0 +1,12 @@
+#!/usr/bin/env node
+
+var util = require("util"),
+ mediainfo = require("mediainfo");
+
+mediainfo("test1.mp3", "test2.mp3", function(err, res) {
+ if (err) {
+ return console.log(err);
+ }
+
+ console.log(util.inspect(res, null, null, true));
+});
81 lib/mediainfo.js
View
@@ -0,0 +1,81 @@
+var child_process = require("child_process"),
+ expat = require("node-expat");
+
+module.exports = function() {
+ var files = Array.prototype.slice.apply(arguments);
+
+ var done = files.pop();
+
+ child_process.execFile("mediainfo", ["--Output=XML"].concat(files), function(err, stdout, stderr) {
+ if (err) {
+ return done(err);
+ }
+
+ var files = [],
+ file = null,
+ track = null,
+ key = null;
+
+ var parser = new expat.Parser();
+
+ parser.on("startElement", function(name, attribs) {
+ name = name.toLowerCase();
+
+ if (file === null && name === "file") {
+ file = {tracks: []};
+
+ for (var k in attribs) {
+ file[k.toLowerCase()] = attribs[k];
+ }
+
+ return;
+ }
+
+ if (track === null && name === "track") {
+ if (attribs.type === "General") {
+ track = file;
+ } else {
+ track = {};
+
+ for (var k in attribs) {
+ track[k.toLowerCase()] = attribs[k];
+ }
+ }
+
+ return;
+ }
+
+ if (track !== null) {
+ key = name;
+ }
+ });
+
+ parser.on("endElement", function(name) {
+ name = name.toLowerCase();
+
+ if (track !== null && name === "track") {
+ if (track !== file) { file.tracks.push(track); }
+ track = null;
+ }
+
+ if (file !== null && name === "file") {
+ files.push(file);
+ file = null;
+ }
+
+ key = null;
+ });
+
+ parser.on("text", function(text) {
+ if (track !== null && key !== null) {
+ track[key] = (track[key] || "") + text;
+ }
+ });
+
+ if (!parser.parse(stdout)) {
+ return done(Error(parser.getError()));
+ }
+
+ return done(null, files);
+ });
+};
31 package.json
View
@@ -0,0 +1,31 @@
+{
+ "name": "mediainfo",
+ "description": "Wrapper around the `mediainfo' program for obtaining information about media files",
+ "version": "0.0.0",
+ "author": {
+ "name": "Conrad Pankoff",
+ "email": "deoxxa@fknsrs.biz",
+ "url": "http://www.fknsrs.biz/"
+ },
+ "url": "http://github.com/deoxxa/node-mediainfo",
+ "license" : "BSD",
+ "repository" : { "type":"git", "url":"git://github.com/deoxxa/node-mediainfo.git" },
+ "keywords" : [
+ "mediainfo",
+ "media",
+ "audio",
+ "video",
+ "mp3",
+ "flac",
+ "ogg",
+ "mkv",
+ "avi"
+ ],
+ "main": "./lib/mediainfo",
+ "engines": {
+ "node" : ">=0.6.11"
+ },
+ "dependencies": {
+ "node-expat": "1.4.x"
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.