From ad522691af49a6288f5007508ba52f6f6ac73db7 Mon Sep 17 00:00:00 2001 From: Ady Levy Date: Sat, 4 Jun 2016 21:23:32 +0300 Subject: [PATCH 1/3] Node compatibility issues (some packages needs update) --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fcedc56..81258ae 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "node": ">=0.6.11" }, "dependencies": { - "node-expat": "2.0.x", - "filesize-parser": "~0.0.2" + "node-expat": "~2.3.13", + "filesize-parser": "~1.4.1" } } From ecaf1132c6499b58f2686c814dc35ecf53e0293b Mon Sep 17 00:00:00 2001 From: Ady Levy Date: Sat, 4 Jun 2016 22:21:26 +0300 Subject: [PATCH 2/3] exposed as API --- .babelrc | 3 + README.md | 103 ++----------------------- example.js | 4 +- index.js | 1 + package.json | 29 ++++--- server/index.js | 14 ++++ server/mediainfo/index.js | 30 +++++++ {lib => server/mediainfo}/mediainfo.js | 2 +- 8 files changed, 79 insertions(+), 107 deletions(-) create mode 100644 .babelrc create mode 100644 index.js create mode 100644 server/index.js create mode 100644 server/mediainfo/index.js rename {lib => server/mediainfo}/mediainfo.js (97%) diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..bea32a4 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": [ "es2015" ] +} diff --git a/README.md b/README.md index 4a65a08..5d47769 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ Mediainfo Wrapper around the `mediainfo` command for obtaining information about media files. +Exposed as API to supply info of urls Overview -------- @@ -10,108 +11,21 @@ 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. +I have extended it to be a web service providing info of url's Usage ----- -The module exposes just one function, which has a signature of: +Once deployed you can pass url to the /info endpoint like this: -`mediainfo("/path/to/file", "/path/to/other/file", [...], callback)` +http://localhost:8080/info?url=http://myfile.mp4 -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) +response would be a json with info of that mp4 Example ------- -```javascript -var mediainfo = require("mediainfo"); - -mediainfo("/path/to/something.mp3", function(err, res) { - if (err) { - return console.log(err); - } - - console.log(res); -}); -``` +http://localhost:8080/info?url=http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4 Requirements ------------ @@ -122,11 +36,10 @@ node is running as. License ------- +For media-info wrapper: 3-clause BSD. A copy is included with the source. Contact ------- -* GitHub ([deoxxa](http://github.com/deoxxa)) -* Twitter ([@deoxxa](http://twitter.com/deoxxa)) -* Email ([deoxxa@fknsrs.biz](mailto:deoxxa@fknsrs.biz)) +* Email ([adylevy@gmail.com](mailto:adylevy@gmail.com)) diff --git a/example.js b/example.js index b0f3e69..c00d54a 100755 --- a/example.js +++ b/example.js @@ -1,9 +1,9 @@ #!/usr/bin/env node var util = require("util"), - mediainfo = require("./"); + mediainfo = require("./server/mediainfo/mediainfo.js"); -mediainfo("test1.mp3", "test2.mp3", function(err, res) { +mediainfo("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", function(err, res) { if (err) { return console.log(err); } diff --git a/index.js b/index.js new file mode 100644 index 0000000..d54c17c --- /dev/null +++ b/index.js @@ -0,0 +1 @@ +require('./server'); diff --git a/package.json b/package.json index 81258ae..9f05743 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,21 @@ { "name": "mediainfo", - "description": "Wrapper around the `mediainfo' program for obtaining information about media files", - "version": "0.0.2", + "description": "Node micro service to return media-info for given url", + "version": "0.0.1", "author": { - "name": "Conrad Pankoff", - "email": "deoxxa@fknsrs.biz", - "url": "http://www.fknsrs.biz/" + "name": "Ady Levy", + "email": "ady.levy@teamaol.com", + "url": "http://www.adylevy.com/" }, - "url": "http://github.com/deoxxa/node-mediainfo", + "url": "https://github.com/adylevy/node-mediainfo", "license": "BSD", "repository": { "type": "git", - "url": "git://github.com/deoxxa/node-mediainfo.git" + "url": "git://github.com/adylevy/node-mediainfo.git" + }, + "scripts": { + "start": "babel-node index.js", + "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [ "mediainfo", @@ -24,12 +28,19 @@ "mkv", "avi" ], - "main": "./lib/mediainfo", + "main": "index.js", "engines": { "node": ">=0.6.11" }, "dependencies": { "node-expat": "~2.3.13", - "filesize-parser": "~1.4.1" + "filesize-parser": "~1.4.1", + "express": "^4.13.3", + "cors": "^2.7.1" + }, + "devDependencies": { + "babel-cli": "^6.9.0", + "babel-core": "^6.9.0", + "babel-preset-es2015": "^6.9.0" } } diff --git a/server/index.js b/server/index.js new file mode 100644 index 0000000..3252138 --- /dev/null +++ b/server/index.js @@ -0,0 +1,14 @@ +import http from 'http'; +import express from 'express'; +import cors from 'cors'; +import mediainfo from './mediainfo' + +var app = express(); +app.server = http.createServer(app); +app.use(cors()); +app.use('/info', mediainfo()); +app.server.listen(process.env.PORT || 8080); + +console.log(`Started on port ${app.server.address().port}`); + +export default app; diff --git a/server/mediainfo/index.js b/server/mediainfo/index.js new file mode 100644 index 0000000..2dd9bab --- /dev/null +++ b/server/mediainfo/index.js @@ -0,0 +1,30 @@ +import { Router } from 'express'; +import mediainfo from './mediainfo.js'; + +export default function () { + var api = Router(); + + api.get('/', (req, res) => { + var url = req.query.url; + + if (url && url != ''){ + mediainfo(url, function(err, mediaResult) { + if (err) { + res.json({ + error:err + }) + } + res.json(mediaResult); + }); + + } + else{ + res.json({ + error:'url not provided.' + }) + } + + }); + return api; +} + diff --git a/lib/mediainfo.js b/server/mediainfo/mediainfo.js similarity index 97% rename from lib/mediainfo.js rename to server/mediainfo/mediainfo.js index 27d8550..cb3b651 100644 --- a/lib/mediainfo.js +++ b/server/mediainfo/mediainfo.js @@ -47,7 +47,7 @@ module.exports = function() { } if (track !== null) { - key = name; + key = name.replace(/\_+$/g,''); } }); From f1892daffa0bc0129a90893d324ade9a3bfc930b Mon Sep 17 00:00:00 2001 From: Ady Levy Date: Sat, 4 Jun 2016 22:24:04 +0300 Subject: [PATCH 3/3] exposed as API --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 5d47769..1e11845 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,3 @@ License For media-info wrapper: 3-clause BSD. A copy is included with the source. -Contact -------- - -* Email ([adylevy@gmail.com](mailto:adylevy@gmail.com))