├── .npmignore ├── README.md ├── index.js ├── lib ├── License.html ├── linux32 │ ├── libmediainfo.so.0 │ ├── libzen.so.0 │ └── mediainfo ├── linux64 │ ├── libmediainfo.so.0 │ ├── libzen.so.0 │ └── mediainfo ├── osx64 │ └── mediainfo └── win32 │ ├── MediaInfo.dll │ └── mediainfo.exe └── package.json /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | logs 3 | npm-debug.log 4 | *.DS_Store 5 | *.swp -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mediainfo-wrapper 2 | 3 | node wrapper for mediainfo. 4 | 5 | This product uses [MediaInfo](http://mediaarea.net/MediaInfo) library, Copyright (c) 2002-2014 [MediaArea.net SARL](mailto:Info@MediaArea.net) 6 | 7 | _Warning: contains 24MiB of binaries for osx, linux, windows. You can delete the platforms you don't need_ 8 | 9 | ### Usage 10 | 11 | npm install mediainfo-wrapper 12 | 13 | then: 14 | 15 | ```js 16 | var mi = require('mediainfo-wrapper'); 17 | mi('foo/bar.mkv', 'foo/bar2.avi').then(function(data) { 18 | for (var i in data) { 19 | console.log('%s parsed', data[i].file); 20 | console.log('MediaInfo data:', data[i]); 21 | } 22 | }).catch(function (e){console.error(e)}); 23 | ``` 24 | 25 | ### Using child_process power 26 | 27 | You can pass an object as first argument to use exec options. See [Node child_process](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback). 28 | 29 | ```js 30 | require('mediainfo-wrapper')({maxBuffer: 'infinity'}, 'foo/bar.mkv', 'foo/bar2.avi').then... 31 | ``` 32 | 33 | ### Glob 34 | 35 | You can use glob to match files: 36 | 37 | ```js 38 | require('mediainfo-wrapper')('foo/bar.mkv', 'foo2/*', 'foo3/*.ogg').then... 39 | ``` 40 | 41 | ### Cleaning unneccesary binaries 42 | 43 | You can clean unneeded binaries, with gulp and nwjs for example: 44 | 45 | ```js 46 | var del = require('del'); 47 | var path = require('path'); 48 | var pkJson = require('./package.json'); 49 | 50 | // clean mediainfo-wrapper 51 | gulp.task('clean:mediainfo', () => { 52 | return Promise.all(['linux32','linux64'].map((platform) => { 53 | console.log('clean:mediainfo', platform); 54 | const sources = path.join(releasesDir, pkJson.name, platform); 55 | return del([ 56 | path.join(sources, 'node_modules/mediainfo-wrapper/lib/*'), 57 | path.join(sources, pkJson.name + '.app/Contents/Resources/app.nw/node_modules/mediainfo-wrapper/lib/*'), 58 | '!'+path.join(sources, 'node_modules/mediainfo-wrapper/lib/'+platform), 59 | '!'+path.join(sources, pkJson.name + '.app/Contents/Resources/app.nw/node_modules/mediainfo-wrapper/lib/'+platform) 60 | ]); 61 | })); 62 | }); 63 | ``` 64 | Or you can use bash script to do this, e.g to clean all binaries except OSX 64 you can run this from your project root: 65 | ```bash 66 | find ./node_modules/mediainfo-wrapper/lib/* -maxdepth 1 -type d -not -name "osx64" | xargs rm -rf 67 | ``` 68 | 69 | ### License 70 | The MIT License 71 | 72 | - Copyright (c) 2016 vankasteelj 73 | 74 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 75 | 76 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 77 | 78 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 79 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var path = require('path'), 2 | xml2js = require('xml2js'), 3 | glob = require('glob'), 4 | exec = require('child_process').exec; 5 | 6 | function getCmd() { 7 | var arch = process.arch.match(/64/) ? '64' : '32'; 8 | 9 | switch (process.platform) { 10 | case 'darwin': 11 | return safeLocalPath(path.join(__dirname, '/lib/osx64/mediainfo')); 12 | case 'win32': 13 | return safeLocalPath(path.join(__dirname, '/lib/win32/mediainfo.exe')); 14 | case 'linux': 15 | return "LD_LIBRARY_PATH=" + safeLocalPath(path.join(__dirname, '/lib/linux' + arch)) + " " + safeLocalPath(path.join(__dirname, '/lib/linux' + arch, '/mediainfo')); 16 | default: 17 | throw 'unsupported platform'; 18 | } 19 | } 20 | 21 | function buildOutput(obj) { 22 | var out = {}; 23 | var idVid = idAud = idTex = idMen = idOth = 0; 24 | 25 | for (var i in obj.track) { 26 | if (obj.track[i]['$']['type'] === 'General') { 27 | out.file = obj.track[i]['Complete_name'][0]; 28 | out.general = {}; 29 | for (var f in obj.track[i]) { 30 | if (f !== '$') out.general[f.toLowerCase()] = obj.track[i][f]; 31 | } 32 | } else if (obj.track[i]['$']['type'] === 'Video') { 33 | if (!idVid) out.video = []; 34 | out.video[idVid] = {}; 35 | for (var f in obj.track[i]) { 36 | if (f !== '$') out.video[idVid][f.toLowerCase()] = obj.track[i][f]; 37 | } 38 | idVid++; 39 | } else if (obj.track[i]['$']['type'] === 'Audio') { 40 | if (!idAud) out.audio = []; 41 | out.audio[idAud] = {}; 42 | for (var f in obj.track[i]) { 43 | if (f !== '$') out.audio[idAud][f.toLowerCase()] = obj.track[i][f]; 44 | } 45 | idAud++; 46 | } else if (obj.track[i]['$']['type'] === 'Text') { 47 | if (!idTex) out.text = []; 48 | out.text[idTex] = {}; 49 | for (var f in obj.track[i]) { 50 | if (f !== '$') out.text[idTex][f.toLowerCase()] = obj.track[i][f]; 51 | } 52 | idTex++; 53 | } else if (obj.track[i]['$']['type'] === 'Menu') { 54 | if (!idMen) out.menu = []; 55 | out.menu[idMen] = {}; 56 | for (var f in obj.track[i]) { 57 | if (f !== '$') out.menu[idMen][f.toLowerCase()] = obj.track[i][f]; 58 | } 59 | idMen++; 60 | } else { 61 | if (!idOth) out.other = []; 62 | out.other[idOth] = {}; 63 | for (var f in obj.track[i]) { 64 | if (f !== '$') out.other[idOth][f.toLowerCase()] = obj.track[i][f]; 65 | } 66 | idOth++; 67 | } 68 | } 69 | return out; 70 | } 71 | 72 | function buildJson(xml) { 73 | return new Promise(function (resolve, reject) { 74 | xml2js.parseString(xml, function (err, obj) { 75 | if (err) return reject(err); 76 | if (!obj['Mediainfo']) return reject('Something went wrong'); 77 | 78 | obj = obj['Mediainfo']; 79 | 80 | var out = []; 81 | 82 | if (Array.isArray(obj.File)) { 83 | for (var i in obj.File) { 84 | out.push(buildOutput(obj.File[i])); 85 | } 86 | } else { 87 | out.push(buildOutput(obj.File)); 88 | } 89 | 90 | resolve(out); 91 | }); 92 | }); 93 | } 94 | 95 | function safeLocalPath(path) { 96 | if (process.platform.match('win32')) { 97 | path = '"' + path + '"';// wrap with double quotes 98 | } else { 99 | path = path.replace(/'/g, "'\"'\"'"); // escape single quotes 100 | path = "'" + path + "'";// wrap with single quotes 101 | } 102 | return path; 103 | } 104 | 105 | module.exports = function MediaInfo() { 106 | var args = [].slice.call(arguments); 107 | var cmd_options = typeof args[0] === "object" ? args.shift() : {}; 108 | var cmd = []; 109 | 110 | cmd.push(getCmd()); // base command 111 | cmd.push('--Output=XML --Full'); // args 112 | Array.prototype.slice.apply(args).forEach(function (val, idx) { 113 | var files = glob.sync(val, {cwd: (cmd_options.cwd || process.cwd()), nonull: true}); 114 | for (var i in files) { 115 | cmd.push(safeLocalPath(files[i])); // files 116 | } 117 | }); 118 | 119 | return new Promise(function (resolve, reject) { 120 | exec(cmd.join(' '), cmd_options, function (error, stdout, stderr) { 121 | if (error !== null || stderr !== '') return reject(error || stderr); 122 | buildJson(stdout).then(resolve).catch(reject); 123 | }); 124 | }); 125 | }; 126 | -------------------------------------------------------------------------------- /lib/License.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MediaInfo(Lib) License 6 | 7 | 8 | 9 |
10 |

MediaInfo(Lib) License

11 |

12 | Copyright (c) 2002-2014 MediaArea.net SARL. All rights reserved. 13 |

14 |

15 | Redistribution and use in source and binary forms, with or without modification, 16 | are permitted provided that the following conditions are met: 17 |

18 | 25 |

26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” 27 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 28 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 29 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 30 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 31 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 32 | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 34 | OF THE POSSIBILITY OF SUCH DAMAGE. 35 |

36 |
37 | 38 |
39 |
40 |

Alternate license for redistributions of the library in binary form:
41 | Redistributions in binary form must reproduce the following sentence (including the link to the website) in the documentation and/or other materials provided with the distribution.
42 | This product uses MediaInfo library, Copyright (c) 2002-2014 MediaArea.net SARL.

43 |
44 | 45 |
46 |
47 |

Third party libraries

48 |

49 | The software relies on third party libraries. Such libraries have their own license: 50 |

51 | 64 |
65 | 66 |
67 |
68 |

Contributors

69 | 76 |
77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /lib/linux32/libmediainfo.so.0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vankasteelj/mediainfo-wrapper/b4d650e3bf6dcd2edb312920095fae53bcd85219/lib/linux32/libmediainfo.so.0 -------------------------------------------------------------------------------- /lib/linux32/libzen.so.0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vankasteelj/mediainfo-wrapper/b4d650e3bf6dcd2edb312920095fae53bcd85219/lib/linux32/libzen.so.0 -------------------------------------------------------------------------------- /lib/linux32/mediainfo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vankasteelj/mediainfo-wrapper/b4d650e3bf6dcd2edb312920095fae53bcd85219/lib/linux32/mediainfo -------------------------------------------------------------------------------- /lib/linux64/libmediainfo.so.0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vankasteelj/mediainfo-wrapper/b4d650e3bf6dcd2edb312920095fae53bcd85219/lib/linux64/libmediainfo.so.0 -------------------------------------------------------------------------------- /lib/linux64/libzen.so.0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vankasteelj/mediainfo-wrapper/b4d650e3bf6dcd2edb312920095fae53bcd85219/lib/linux64/libzen.so.0 -------------------------------------------------------------------------------- /lib/linux64/mediainfo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vankasteelj/mediainfo-wrapper/b4d650e3bf6dcd2edb312920095fae53bcd85219/lib/linux64/mediainfo -------------------------------------------------------------------------------- /lib/osx64/mediainfo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vankasteelj/mediainfo-wrapper/b4d650e3bf6dcd2edb312920095fae53bcd85219/lib/osx64/mediainfo -------------------------------------------------------------------------------- /lib/win32/MediaInfo.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vankasteelj/mediainfo-wrapper/b4d650e3bf6dcd2edb312920095fae53bcd85219/lib/win32/MediaInfo.dll -------------------------------------------------------------------------------- /lib/win32/mediainfo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vankasteelj/mediainfo-wrapper/b4d650e3bf6dcd2edb312920095fae53bcd85219/lib/win32/mediainfo.exe -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mediainfo-wrapper", 3 | "version": "1.2.0", 4 | "description": "wrapper for mediainfo-prebuilt", 5 | "main": "index.js", 6 | "license": "MIT", 7 | "bugs": { 8 | "url": "https://github.com/vankasteelj/mediainfo-wrapper/issues" 9 | }, 10 | "dependencies": { 11 | "xml2js": "^0.4.16", 12 | "glob": "^7.0.3" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/vankasteelj/mediainfo-wrapper.git" 17 | }, 18 | "keywords": [ 19 | "mediainfo", 20 | "media", 21 | "metadata", 22 | "codecs" 23 | ], 24 | "author": { 25 | "name": "Jean van Kasteel", 26 | "email": "vankasteelj@gmail.com" 27 | } 28 | } --------------------------------------------------------------------------------