Giter VIP home page Giter VIP logo

node-azure-media's Introduction

Azure Media for Node.js

Azure's Media REST API provides a way to store, encode, and deliver media (video and images). This library makes using the API easier.

var AzureMedia = require('azure-media');
var myconfig = require('./myconfig');

var api = new AzureMedia(myconfig); // {client_id: 'your azure media id', client_secret: 'your azure media secret'} 
api.init(function (err) {
    // do your work here or after this callback
});

Looking for Maintainer(s)

This project is not maintained and likely out of date. If you'd like to take over this project (even just by claiming the npm name for your project) open an issue and let me know.

Install

npm install azure-media

Using Microsoft's Documentation

All of the data structures and endpoints used in this library are documented in Azure Media Service REST API Reference.

Each subsection is modeled based on its "Entity Properties" section (eg. Asset Entity Properties).

Each model usable at API.rest.[lowercase model name] with create, get, update, list methods.

REST Endpoints

All REST endpoints are in the initialized api lib at api.rest.someendpoint (eg. api.rest.asset)

"data" is a JavaScript object for the appropriate endpoint model documented in the Properties section of each model in Azure Media Service REST API Reference.
Callbacks generally return an object, called a model. It uses VeryModel. VeryModel instances behave like normal objects. If you want a simpler object, call .toObject() and use the returned value.

Each endpoint will have some of the following methods:

update

Signature: update(id, data, callback)
Callback: function (err, model)

create

Signature: create(data, callback)
Callback: function(err, model)

Example:

api.rest.asset.create({Name: 'Some Asset'}, function (err, asset) {
    if (err) {
        console.log(err);
    } else {
        console.log("Created asset: " + asset.Id);
    }
});

delete

Signature: delete(id, callback)
Callback: function(err)

get

Signature: get(id, callback)
Callback: function(err, model)

list

Signature: list(callback, query)
Callback: function(err, model)

The query parameter is a JavaScript object of the query parameters documented in OData Query String Options (eg: {'$filter': "Name eq 'Bill'"})

accesspolicy

AccessPolicys should be reused, rather than just creating a new one for every use. So rather than create, or trying to manage this yourself, use

Signature: findOrCreate(durationInMinutes, permissions, callback)
Callback: function (err, accesspolicy_model)

assetfileindex

ingestmanifestasset

job

Signature: cancel(id, callback)
Callback: function (err)

locator

notificationendpoint

tasktemplate

asset

contentkey

ingestmanifest

ingestmanifestfile

jobtemplate

mediaprocessor

task

Models

Most callbacks return a VeryModel instance. These are based on Microsoft's documentation and are implemented in /models/

Some models have extra ORM-like methods, allowing you to interact with the model itself which will work with the Azure REST API behind the scenes.

accesspolicy

assetfileindex

ingestmanifestasset

job

locator

notificationendpoint

tasktemplate

asset

contentkey

ingestmanifest

ingestmanifestfile

jobtemplate

mediaprocessor

task

Workflow Methods

uploadStream

api.uploadStream('somefile.mp4', fs.createReadStream('/some/file.mp4'), fs.statSync('/some/file.mp4').size, function (err, path, result) {
}, function (err, path) {
    if(!err) {
        console.log("done uploading");
    }
});

downloadStream

api.downloadStream(assetId, 'video/mp4', fs.createWriteStream('/some/download/path.mp4', function (err) {
});

getDownloadURL

api.getDownloadURL(assetId, 'video/mp4', fs.createWriteStream('/some/download/path.mp4', function (err, url) {
});

encodeVideo

api.encodeVideo(assetId, 'H264 Broadband SD 4x3', function (err, job)) {
});

node-azure-media's People

Contributors

fritzy avatar legastero avatar nimajalali avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

node-azure-media's Issues

Call update for assetfile fails

When I attempt to set the IsPrimary flag on an assetfile object, I get the following error:

.../node_modules/azure-media/node_modules/verymodel/lib/model.js:442
    merrors = meta.defs[field].validate(meta.data[field]);

The reason is that meta.defs[field].validate is a boolean instead of a function. This also occurs if you attempt to call update when setting IsEncrypted (or any other boolean field).

Note: This might be a bug inside of VeryModel.

Create thumbnail ?

How can i generate thumbnail from a video ?

Also Azure portal says :

Use Azure Active Directory (AAD) to connect to Azure Media Services API. The Access Control Service (ACS) keys will be deprecated on June 1st, 2018.

Please give us some guide to change this to AAD

Passing stream to uploadStream function causes a TypeError

I am using sails.js to redirect upload streams to AMS. When trying to pass a stream using
req.file('fieldname')._files[0].stream I get the following error stack trace:

_http_outgoing.js:301
    value = value.replace(/[\r\n]+[ \t]*/g, '');
                  ^

TypeError: value.replace is not a function
    at storeHeader (_http_outgoing.js:301:19)
    at ClientRequest.OutgoingMessage._storeHeader (_http_outgoing.js:217:9)
    at ClientRequest._implicitHeader (_http_client.js:167:8)
    at ClientRequest.OutgoingMessage.write (_http_outgoing.js:420:10)
    at Request.write (D:\prot1\node_modules\azure-media\node_modules\request\req
uest.js:1378:25)
    at PassThrough.ondata (C:\Users\HauskaNimi\AppData\Roaming\npm\node_modules\
sails\node_modules\skipper\node_modules\multiparty\node_modules\readable-stream\
lib\_stream_readable.js:572:20)
    at emitOne (events.js:77:13)
    at PassThrough.emit (events.js:169:7)
    at PassThrough.Readable.read (C:\Users\HauskaNimi\AppData\Roaming\npm\node_m
odules\sails\node_modules\skipper\node_modules\multiparty\node_modules\readable-
stream\lib\_stream_readable.js:405:10)
    at flow (C:\Users\HauskaNimi\AppData\Roaming\npm\node_modules\sails\node_mod
ules\skipper\node_modules\multiparty\node_modules\readable-stream\lib\_stream_re
adable.js:781:26)
    at resume_ (C:\Users\HauskaNimi\AppData\Roaming\npm\node_modules\sails\node_
modules\skipper\node_modules\multiparty\node_modules\readable-stream\lib\_stream
_readable.js:761:3)
    at C:\Users\HauskaNimi\AppData\Roaming\npm\node_modules\sails\node_modules\s
kipper\node_modules\multiparty\node_modules\readable-stream\lib\_stream_readable
.js:753:7
    at doNTCallback0 (node.js:407:9)
    at process._tickDomainCallback (node.js:377:13)

Here is a dump of the stream logged to console:

PassThrough {
  _readableState:
   ReadableState {
     highWaterMark: 16384,
     buffer: [ <Buffer 00 00 00 18 66 74 79 70 6d 70 34 32 00 00 00 00 6d 70 34
32 6d 70 34 31 00 00 21 cd 6d 6f 6f 76 00 00 00 6c 6d 76 68 64 00 00 00 00 d1 2d
 ac c7 d1 2d ... > ],
     length: 34084,
     pipes: null,
     pipesCount: 0,
     flowing: null,
     ended: false,
     endEmitted: false,
     reading: false,
     sync: false,
     needReadable: false,
     emittedReadable: true,
     readableListening: false,
     objectMode: false,
     defaultEncoding: 'utf8',
     ranOut: false,
     awaitDrain: 0,
     readingMore: false,
     decoder: null,
     encoding: null },
  readable: true,
  domain: null,
  _events:
   { end: { [Function: g] listener: [Function: onend] },
     prefinish: { [Function: g] listener: [Function] },
     drain: [Function],
     error: { [Function: g] listener: [Function] } },
  _eventsCount: 4,
  _maxListeners: undefined,
  _writableState:
   WritableState {
     highWaterMark: 16384,
     objectMode: false,
     needDrain: true,
     ending: false,
     ended: false,
     finished: false,
     decodeStrings: true,
     defaultEncoding: 'utf8',
     length: 39845,
     writing: true,
     corked: 0,
     sync: false,
     bufferProcessing: false,
     onwrite: [Function],
     writecb: [Function],
     writelen: 1,
     buffer: [ [Object], [Object], [Object], [Object] ],
     pendingcb: 5,
     prefinished: false,
     errorEmitted: false },
  writable: true,
  allowHalfOpen: true,
  _transformState:
   TransformState {
     afterTransform: [Function],
     needTransform: false,
     transforming: false,
     writecb: [Function],
     writechunk: <Buffer 0d>,
     writeencoding: 'buffer' },
  headers:
   { 'content-disposition': 'form-data; name="file"; filename="motion-test_01_2f
b_a.mp4"',
     'content-type': 'video/mp4' },
  name: 'file',
  filename: 'motion-test_01_2fb_a.mp4',
  byteOffset: 247,
  byteCount: 8871231,
  field: 'file' 
}

It seems like a bug to me, since the stream looks fine.

Cannot initiate Azure Media Service

Hi, fritzy, thanks for your work!
I tried to use it but encounter an error when initiate the service
Error Message:
[Error: options.uri is a required argument]

and here's my code:
var AzureMedia = require('azure-media');

var api = new AzureMedia("{client_id: '[MYACCOUNT]', client_secret: '[SECRETE]'} ");
api.init(function (err) {
if(err)
console.log(err);
else
console.log('success');
// do your work here or after this callback
});

Any comment on this? thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.