From 387afab77c79d924d4cf36b750aa6b8f307854c4 Mon Sep 17 00:00:00 2001 From: Nsikan Date: Wed, 7 Nov 2018 08:35:32 +0000 Subject: [PATCH 01/13] Add test for getting access token for videoIndexerV2 --- test/config.js | 4 ++++ test/vision/videoIndexerV2Test.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/vision/videoIndexerV2Test.js diff --git a/test/config.js b/test/config.js index f8167e2..0ac93ca 100644 --- a/test/config.js +++ b/test/config.js @@ -74,5 +74,9 @@ module.exports = { apiKey: "insert-key-here", appID: "insert-appID-here", versionID: "0.1" + }, + videoIndexerV2: { + endpoint: "api.videoindexer.ai", + apiKey: "insert-key-here" } } \ No newline at end of file diff --git a/test/vision/videoIndexerV2Test.js b/test/vision/videoIndexerV2Test.js new file mode 100644 index 0000000..4af3b5f --- /dev/null +++ b/test/vision/videoIndexerV2Test.js @@ -0,0 +1,31 @@ +const cognitive = require('../../src/index.js'); +const config = require('../config.js'); +const should = require('should'); + +describe.only('Video indexer', () => { + + const client = new cognitive.videoIndexerV2({ + apiKey: config.videoIndexerV2.apiKey + }); + + describe('Accounts Access Token', () => { + const requestParams = { + location: "trial", + allowEdit: false, + accountId: "your-account-id-here" + }; + + it('should get an accounts access token', done => { + client.getAccountsAccessToken(requestParams) + .then(response => { + should(response).not.be.undefined(); + should(response).be.a.String(); + done(); + }) + .catch(err => { + done(err); + }) + }) + }) + +}) From 9c91433f9d8ddc669cc1b66789453871a8963f29 Mon Sep 17 00:00:00 2001 From: Nsikan Essien Date: Mon, 12 Nov 2018 00:56:40 +0000 Subject: [PATCH 02/13] Add get accounts method for indexer v2 --- src/index.js | 3 +- src/vision/videoIndexerV2.js | 55 +++++++++++++++++++++++++++++++ test/vision/videoIndexerV2Test.js | 12 +++---- 3 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 src/vision/videoIndexerV2.js diff --git a/src/index.js b/src/index.js index 5fe8b43..51daa87 100644 --- a/src/index.js +++ b/src/index.js @@ -26,5 +26,6 @@ module.exports = { bingSpeech: require('./speech/bingSpeech'), bingEntitySearch: require('./search/bingEntitySearch'), contentModerator: require('./vision/contentModerator'), - videoIndexer: require('./vision/videoIndexer') + videoIndexer: require('./vision/videoIndexer'), + videoIndexerV2: require('./vision/videoIndexerV2') }; \ No newline at end of file diff --git a/src/vision/videoIndexerV2.js b/src/vision/videoIndexerV2.js new file mode 100644 index 0000000..fd31a5c --- /dev/null +++ b/src/vision/videoIndexerV2.js @@ -0,0 +1,55 @@ +const commonService = require('../commonService'); + +/** + * Video Indexer is a cloud service that enables you to extract the following insights from your videos using artificial intelligence technologies: + */ +class videoIndexerV2 extends commonService { + /** + * Constructor. + * + * @param {Object} obj + * @param {string} obj.apiKey + */ + constructor({ apiKey }) { + const endpoint = "api.videoindexer.ai/"; + super({ apiKey, endpoint }); + this.endpoints = [ + endpoint + ]; + } + + getAccounts({ + location, + generateAccessTokens, + allowEdit, + }) { + const operation = { + parameters: [ + { + name: 'location', + type: 'queryStringParam' + }, + { + name: 'generateAccessTokens', + type: 'queryStringParam' + },{ + name: 'allowEdit', + type: 'queryStringParam' + }, + ] + }; + + const requestParameters = { + location, + generateAccessTokens, + allowEdit + } + + return this.makeRequest({ + operation: operation, + parameters: requestParameters + }) + } +} + +module.exports = videoIndexerV2; \ No newline at end of file diff --git a/test/vision/videoIndexerV2Test.js b/test/vision/videoIndexerV2Test.js index 4af3b5f..3eb9f66 100644 --- a/test/vision/videoIndexerV2Test.js +++ b/test/vision/videoIndexerV2Test.js @@ -2,24 +2,24 @@ const cognitive = require('../../src/index.js'); const config = require('../config.js'); const should = require('should'); -describe.only('Video indexer', () => { +describe.only('Video Indexer V2', () => { const client = new cognitive.videoIndexerV2({ apiKey: config.videoIndexerV2.apiKey }); - describe('Accounts Access Token', () => { + describe('Get Accounts', () => { const requestParams = { location: "trial", allowEdit: false, - accountId: "your-account-id-here" + generateAccessTokens: true }; - it('should get an accounts access token', done => { - client.getAccountsAccessToken(requestParams) + it('should return an array showing url and accounts access token', done => { + client.getAccounts(requestParams) .then(response => { should(response).not.be.undefined(); - should(response).be.a.String(); + should(response).be.an.Array(); done(); }) .catch(err => { From 92abac315c8a07acd546d67f266c1fcc11dc95d8 Mon Sep 17 00:00:00 2001 From: Nsikan Essien Date: Mon, 12 Nov 2018 01:27:00 +0000 Subject: [PATCH 03/13] Add path, method and proper endpoint format to fix failing test --- src/vision/videoIndexerV2.js | 6 ++++-- test/config.js | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/vision/videoIndexerV2.js b/src/vision/videoIndexerV2.js index fd31a5c..3aedf05 100644 --- a/src/vision/videoIndexerV2.js +++ b/src/vision/videoIndexerV2.js @@ -11,7 +11,7 @@ class videoIndexerV2 extends commonService { * @param {string} obj.apiKey */ constructor({ apiKey }) { - const endpoint = "api.videoindexer.ai/"; + const endpoint = "api.videoindexer.ai"; super({ apiKey, endpoint }); this.endpoints = [ endpoint @@ -36,7 +36,9 @@ class videoIndexerV2 extends commonService { name: 'allowEdit', type: 'queryStringParam' }, - ] + ], + path: `auth/${location}/Accounts`, + method: 'GET' }; const requestParameters = { diff --git a/test/config.js b/test/config.js index 0ac93ca..2dc17aa 100644 --- a/test/config.js +++ b/test/config.js @@ -76,7 +76,6 @@ module.exports = { versionID: "0.1" }, videoIndexerV2: { - endpoint: "api.videoindexer.ai", apiKey: "insert-key-here" } } \ No newline at end of file From 6c761fe7965fce43a05d1a3eb8c7ae5db58515d0 Mon Sep 17 00:00:00 2001 From: Nsikan Essien Date: Mon, 12 Nov 2018 15:01:57 +0000 Subject: [PATCH 04/13] Add method jsdocs and use CommonService route params --- src/vision/videoIndexerV2.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/vision/videoIndexerV2.js b/src/vision/videoIndexerV2.js index 3aedf05..f3f68e9 100644 --- a/src/vision/videoIndexerV2.js +++ b/src/vision/videoIndexerV2.js @@ -18,6 +18,15 @@ class videoIndexerV2 extends commonService { ]; } + /** + * Get Accounts - returns the account details associated + * with an API key. + * @param {Object} obj + * @param {string} obj.location + * @param {boolean} obj.generateAccessTokens + * @param {boolean} obj.allowEdit + * @returns {Promise<[Object]>} A promise containing an array of objects + */ getAccounts({ location, generateAccessTokens, @@ -27,17 +36,23 @@ class videoIndexerV2 extends commonService { parameters: [ { name: 'location', - type: 'queryStringParam' + required: true, + type: 'routeParam', + typeName: 'string' }, { name: 'generateAccessTokens', - type: 'queryStringParam' + required: false, + type: 'queryStringParam', + typeName: 'boolean', },{ name: 'allowEdit', - type: 'queryStringParam' + required: false, + type: 'queryStringParam', + typeName: 'boolean' }, ], - path: `auth/${location}/Accounts`, + path: `auth/{location}/Accounts`, method: 'GET' }; From 558a0bf5d096df70e348c28cd381125b64aa8124 Mon Sep 17 00:00:00 2001 From: Nsikan Essien Date: Mon, 12 Nov 2018 16:01:20 +0000 Subject: [PATCH 05/13] Add assertions for getAccounts response content --- test/vision/videoIndexerV2Test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/vision/videoIndexerV2Test.js b/test/vision/videoIndexerV2Test.js index 3eb9f66..94f4595 100644 --- a/test/vision/videoIndexerV2Test.js +++ b/test/vision/videoIndexerV2Test.js @@ -15,11 +15,14 @@ describe.only('Video Indexer V2', () => { generateAccessTokens: true }; - it('should return an array showing url and accounts access token', done => { + it('should return an array contain an object with url, id and accounts access token', done => { client.getAccounts(requestParams) .then(response => { should(response).not.be.undefined(); should(response).be.an.Array(); + should(response[0]).have.property('id'); + should(response[0]).have.property('url'); + should(response[0]).have.property('accessToken'); done(); }) .catch(err => { From 9a46395f6c47e1df33b05989ea6112900880eb8b Mon Sep 17 00:00:00 2001 From: Nsikan Essien Date: Mon, 12 Nov 2018 17:10:33 +0000 Subject: [PATCH 06/13] Add typescript definitions --- src/index.d.ts | 2 ++ src/vision/videoIndexerV2.d.ts | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/vision/videoIndexerV2.d.ts diff --git a/src/index.d.ts b/src/index.d.ts index 4dd5725..00490ce 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -22,6 +22,8 @@ export * from './vision/emotion'; export * from './vision/face'; export * from './vision/video'; +export * from './vision/videoIndexerV2' + export interface ContentTypeHeaders { /** * Media type of the body sent to the API. diff --git a/src/vision/videoIndexerV2.d.ts b/src/vision/videoIndexerV2.d.ts new file mode 100644 index 0000000..f34bfb2 --- /dev/null +++ b/src/vision/videoIndexerV2.d.ts @@ -0,0 +1,20 @@ +import { CommonConstructorOptions, ContentTypeHeaders, OcpApimSubscriptionKeyHeaders, ContentTypeHeaderTypes } from "../index"; + +/** + * Video Indexer is a cloud service that enables you to extract the following insights from your videos using artificial intelligence technologies: + */ +export class videoIndexer { + + constructor(options: videoIndexerV2Options); + getAccounts(options: GetAccountOptions): Promise; +} + +export interface videoIndexerV2Options { + apiKey: string +} + +export interface GetAccountOptions { + location: string + generateAccessTokens?: boolean, + allowEdit?: boolean, +} From 2d7591fac22353a4c83a2a629284b3dd4521bd35 Mon Sep 17 00:00:00 2001 From: Nsikan Essien Date: Mon, 12 Nov 2018 19:50:01 +0000 Subject: [PATCH 07/13] Add test for Get Access Token api --- src/vision/videoIndexerV2.js | 41 +++++++++++++++++++++++++++++++ test/config.js | 3 ++- test/vision/videoIndexerV2Test.js | 19 ++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/vision/videoIndexerV2.js b/src/vision/videoIndexerV2.js index f3f68e9..f9a8adf 100644 --- a/src/vision/videoIndexerV2.js +++ b/src/vision/videoIndexerV2.js @@ -67,6 +67,47 @@ class videoIndexerV2 extends commonService { parameters: requestParameters }) } + + getAccountAccessToken({ + location, + accountId, + allowEdit, + }){ + const operation = { + parameters: [ + { + name: 'location', + required: true, + type: 'routeParam', + typeName: 'string' + }, + { + name: 'accountId', + required: true, + type: 'routeParam', + typeName: 'string', + },{ + name: 'allowEdit', + required: false, + type: 'queryStringParam', + typeName: 'boolean' + }, + ], + path: `auth/{location}/Accounts/{accountId}/AccessToken`, + method: 'GET' + }; + + const requestParameters = { + location, + accountId, + allowEdit + } + + return this.makeRequest({ + operation: operation, + parameters: requestParameters + }) + } } module.exports = videoIndexerV2; \ No newline at end of file diff --git a/test/config.js b/test/config.js index 2dc17aa..86681c7 100644 --- a/test/config.js +++ b/test/config.js @@ -76,6 +76,7 @@ module.exports = { versionID: "0.1" }, videoIndexerV2: { - apiKey: "insert-key-here" + apiKey: "insert-key-here", + accountId: "insert-accountId-here" } } \ No newline at end of file diff --git a/test/vision/videoIndexerV2Test.js b/test/vision/videoIndexerV2Test.js index 94f4595..05f93df 100644 --- a/test/vision/videoIndexerV2Test.js +++ b/test/vision/videoIndexerV2Test.js @@ -31,4 +31,23 @@ describe.only('Video Indexer V2', () => { }) }) + describe('Get Account Access Tokens', () => { + const requestParams = { + location: "trial", + accountId: config.videoIndexerV2.accountId, + allowEdit: false + }; + + it('should return an account access token', done => { + client.getAccountAccessToken(requestParams) + .then(response => { + should(response).not.be.undefined(); + should(response).startWith("ey", "the encoding of brackets alwys generates this at the start"); + done(); + }) + .catch(err => { + done(err); + }) + }) + }) }) From 93105638896f6e2e2b8975700bc9213384c3e078 Mon Sep 17 00:00:00 2001 From: Nsikan Essien Date: Mon, 12 Nov 2018 20:08:09 +0000 Subject: [PATCH 08/13] Add jsdocs and ts declarations --- src/vision/videoIndexerV2.d.ts | 7 +++++++ src/vision/videoIndexerV2.js | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/src/vision/videoIndexerV2.d.ts b/src/vision/videoIndexerV2.d.ts index f34bfb2..f5f80de 100644 --- a/src/vision/videoIndexerV2.d.ts +++ b/src/vision/videoIndexerV2.d.ts @@ -7,6 +7,7 @@ export class videoIndexer { constructor(options: videoIndexerV2Options); getAccounts(options: GetAccountOptions): Promise; + getAccountAccessToken(options: GetAccountAccessTokenOptions): Promise } export interface videoIndexerV2Options { @@ -18,3 +19,9 @@ export interface GetAccountOptions { generateAccessTokens?: boolean, allowEdit?: boolean, } + +export interface GetAccountAccessTokenOptions { + location: string, + accountId: string, + allowEdit?: boolean +} diff --git a/src/vision/videoIndexerV2.js b/src/vision/videoIndexerV2.js index f9a8adf..b467c36 100644 --- a/src/vision/videoIndexerV2.js +++ b/src/vision/videoIndexerV2.js @@ -68,6 +68,14 @@ class videoIndexerV2 extends commonService { }) } + /** + * Get Account Access Token - returns an account access token as a string. + * @param {Object} obj + * @param {string} obj.location + * @param {boolean} obj.accountId + * @param {boolean} obj.allowEdit + * @returns {Promise} A promise containing an array of objects + */ getAccountAccessToken({ location, accountId, From 027ceaa91d048456f23303eb9b89540f8bc55ee3 Mon Sep 17 00:00:00 2001 From: Nsikan Essien Date: Tue, 13 Nov 2018 21:34:01 +0000 Subject: [PATCH 09/13] Add test and implementation for get user access token --- src/vision/videoIndexerV2.js | 42 ++++++++++++++++++++++++++++++- test/vision/videoIndexerV2Test.js | 21 +++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/vision/videoIndexerV2.js b/src/vision/videoIndexerV2.js index b467c36..e5247f6 100644 --- a/src/vision/videoIndexerV2.js +++ b/src/vision/videoIndexerV2.js @@ -74,7 +74,7 @@ class videoIndexerV2 extends commonService { * @param {string} obj.location * @param {boolean} obj.accountId * @param {boolean} obj.allowEdit - * @returns {Promise} A promise containing an array of objects + * @returns {Promise} A promise containing an access token */ getAccountAccessToken({ location, @@ -116,6 +116,46 @@ class videoIndexerV2 extends commonService { parameters: requestParameters }) } + + /** + * Get User Access Token - returns a user access token as a string. + * @param {Object} obj + * @param {string} obj.location + * @param {boolean} obj.allowEdit + * @returns {Promise} A promise containing an access token + */ + getUserAccessToken({ + location, + allowEdit, + }){ + const operation = { + parameters: [ + { + name: 'location', + required: true, + type: 'routeParam', + typeName: 'string' + },{ + name: 'allowEdit', + required: false, + type: 'queryStringParam', + typeName: 'boolean' + }, + ], + path: `auth/{location}/Users/Me/AccessToken`, + method: 'GET' + }; + + const requestParameters = { + location, + allowEdit + } + + return this.makeRequest({ + operation: operation, + parameters: requestParameters + }) + } } module.exports = videoIndexerV2; \ No newline at end of file diff --git a/test/vision/videoIndexerV2Test.js b/test/vision/videoIndexerV2Test.js index 05f93df..900a22a 100644 --- a/test/vision/videoIndexerV2Test.js +++ b/test/vision/videoIndexerV2Test.js @@ -31,7 +31,7 @@ describe.only('Video Indexer V2', () => { }) }) - describe('Get Account Access Tokens', () => { + describe('Get Account Access Token', () => { const requestParams = { location: "trial", accountId: config.videoIndexerV2.accountId, @@ -50,4 +50,23 @@ describe.only('Video Indexer V2', () => { }) }) }) + + describe('Get User Access Token', () => { + const requestParams = { + location: "trial", + allowEdit: false + }; + + it('should return a user access token', done => { + client.getUserAccessToken(requestParams) + .then(response => { + should(response).not.be.undefined(); + should(response).startWith("ey", "the encoding of brackets alwys generates this at the start"); + done(); + }) + .catch(err => { + done(err); + }) + }) + }) }) From 8f8e9b15bed514e1d8ea1c26f4a2dcac5c5da6ea Mon Sep 17 00:00:00 2001 From: Nsikan Essien Date: Wed, 14 Nov 2018 09:00:42 +0000 Subject: [PATCH 10/13] Add type definitions --- src/vision/videoIndexerV2.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/vision/videoIndexerV2.d.ts b/src/vision/videoIndexerV2.d.ts index f5f80de..8a607ac 100644 --- a/src/vision/videoIndexerV2.d.ts +++ b/src/vision/videoIndexerV2.d.ts @@ -8,6 +8,7 @@ export class videoIndexer { constructor(options: videoIndexerV2Options); getAccounts(options: GetAccountOptions): Promise; getAccountAccessToken(options: GetAccountAccessTokenOptions): Promise + getUserAccessToken(options: GetUserAccessTokenOptions): Promise } export interface videoIndexerV2Options { @@ -25,3 +26,8 @@ export interface GetAccountAccessTokenOptions { accountId: string, allowEdit?: boolean } + +export interface GetUserAccessTokenOptions { + location: string, + allowEdit?: boolean +} From 4f24e27a4e313d9fc56f1d0ce8275d7f34a8485e Mon Sep 17 00:00:00 2001 From: Nsikan Essien Date: Fri, 16 Nov 2018 22:26:06 +0000 Subject: [PATCH 11/13] Add test for Operations upload video API --- src/vision/videoIndexerV2.js | 158 ++++++++++++++++++++++++++++++ test/vision/videoIndexerV2Test.js | 45 ++++++++- 2 files changed, 202 insertions(+), 1 deletion(-) diff --git a/src/vision/videoIndexerV2.js b/src/vision/videoIndexerV2.js index e5247f6..a5d6538 100644 --- a/src/vision/videoIndexerV2.js +++ b/src/vision/videoIndexerV2.js @@ -1,4 +1,5 @@ const commonService = require('../commonService'); +const querystring = require('querystring'); /** * Video Indexer is a cloud service that enables you to extract the following insights from your videos using artificial intelligence technologies: @@ -16,6 +17,8 @@ class videoIndexerV2 extends commonService { this.endpoints = [ endpoint ]; + // https://docs.microsoft.com/en-us/azure/media-services/media-services-media-encoder-standard-formats + this.supportedFormats = ['flv', 'mxf', 'gxf', 'ts', 'ps', '3gp', '3gpp', 'mpg', 'wmv', 'asf', 'avi', 'mp4', 'm4a', 'm4v', 'isma', 'ismv', 'dvr-ms', 'mkv', 'wav', 'mov'] } /** @@ -156,6 +159,161 @@ class videoIndexerV2 extends commonService { parameters: requestParameters }) } + + /** + * Uploads a video to the Video Indexer + */ + uploadVideo(params){ + if(!params.path && !params.videoUrl) { + throw new Error('no video to upload. A video must be specified, either via videoUrl or a path'); + } + + const pathToVideo = (params.path) ? params.path : params.videoUrl; + + const isFormatSupported = this.supportedFormats.filter(sf => { + return pathToVideo.endsWith(sf); + }).length + if (isFormatSupported == 0) { + return Promise.reject(reject(new Error('Unsupported format. Supported formats are ' + this.supportedFormats.join(',')))); + } + + const requestHeaders = {}; + + if(params.videoUrl && !((/(http)s?(:\/\/)/).test(params.videoUrl))){ + // video should point to public url + throw new Error('videoUrl is not an http/https link. A videoUrl must contain a public path'); + } else if(params.videoUrl) { + // video needs to be url encoded + params.videoUrl = querystring.stringify(params.videoUrl); + } + + if(params.path && ((/(http)s?(:\/\/)/).test(params.path))){ + // path should not point to public url + throw new Error('path is an http/https link. A path must point to a local path'); + } else if(params.path) { + // set content type as video will be sent in request body + requestHeaders['Content-Type'] = 'multipart/form-data'; + } + + const operation = { + parameters: [ + { + name: 'location', + required: true, + type: 'routeParam', + typeName: 'string' + },{ + name: 'accountId', + required: true, + type: 'routeParam', + typeName: 'string', + },{ + name: 'accessToken', + required: true, + type: 'queryStringParam', + typeName: 'string' + },{ + name: 'name', + required: true, + type: 'queryStringParam', + typeName: 'string' + },{ + name: 'indexingPreset', + required: false, + type: 'queryStringParam', + typeName: 'string', + options: ['Default',"AudioOnly","DefaultWithNoiseReduction"] + },{ + name: 'description', + required: false, + type: 'queryStringParam', + typeName: 'string' + },{ + name: 'partition', + required: false, + type: 'queryStringParam', + typeName: 'string' + },{ + name: 'externalId', + required: false, + type: 'queryStringParam', + typeName: 'string' + },{ + name: 'callbackUrl', + required: false, + type: 'queryStringParam', + typeName: 'string' + },{ + name: 'metadata', + required: false, + type: 'queryStringParam', + typeName: 'string' + },{ + name: 'language', + required: false, + type: 'queryStringParam', + typeName: 'string', + options: ['ar-EG',"zh-Hans","en-US","fr-FR", "de-DE", "it-IT", "ja-JP", "pt-BR", "ru-RU", "es-ES", "auto"] + },{ + name: 'videoUrl', + required: false, + type: 'queryStringParam', + typeName: 'string' + },{ + name: 'fileName', + required: false, + type: 'queryStringParam', + typeName: 'string' + },{ + name: 'streamingPreset', + required: false, + type: 'queryStringParam', + typeName: 'string', + options: ['Default',"SingleBitrate","AdaptiveBitrate","NoStreaming"] + },{ + name: 'linguisticModelId', + required: false, + type: 'queryStringParam', + typeName: 'string' + },{ + name: 'privacy', + required: false, + type: 'queryStringParam', + typeName: 'string', + options: ['Private','Public'] + },{ + name: 'externalUrl', + required: false, + type: 'queryStringParam', + typeName: 'string' + },{ + name: 'assetId', + required: false, + type: 'queryStringParam', + typeName: 'string' + },{ + name: 'priority', + required: false, + type: 'queryStringParam', + typeName: 'string', + options: ['Low','Normal','High'] + },{ + "name": "path", + "description": "The path to the file", + "required": false, + "typeName": "string" + } + ], + path: '{location}/Accounts/{accountId}/Videos', + method: 'POST' + }; + + return this.makeRequest({ + operation: operation, + parameters: params, + headers: requestHeaders + }); + } } module.exports = videoIndexerV2; \ No newline at end of file diff --git a/test/vision/videoIndexerV2Test.js b/test/vision/videoIndexerV2Test.js index 900a22a..6cc3530 100644 --- a/test/vision/videoIndexerV2Test.js +++ b/test/vision/videoIndexerV2Test.js @@ -2,12 +2,15 @@ const cognitive = require('../../src/index.js'); const config = require('../config.js'); const should = require('should'); -describe.only('Video Indexer V2', () => { +describe('Video Indexer V2', () => { const client = new cognitive.videoIndexerV2({ apiKey: config.videoIndexerV2.apiKey }); + const videoUrl = 'https://mparnisari.blob.core.windows.net/storage/video_girl_laughing.mp4'; + const videoPath = './test/assets/video_girl_laughing.mp4'; + describe('Get Accounts', () => { const requestParams = { location: "trial", @@ -69,4 +72,44 @@ describe.only('Video Indexer V2', () => { }) }) }) + + describe.only('Upload Video', () => { + let accessToken; + const videoName = 'A girl laughing'; + + beforeEach('generate an access token', (done) => { + const requestParams = { + location: "trial", + accountId: config.videoIndexerV2.accountId, + allowEdit: true + }; + client.getAccountAccessToken(requestParams) + .then(response => { + accessToken = response; + done(); + }) + }); + + it(`should return a json with state, "Uploaded" or "Processing", and a video with name, ${videoName} and a Video id`, done => { + const requestParams = { + path: videoPath, + location: "trial", + accountId: config.videoIndexerV2.accountId, + accessToken: accessToken, + name: videoName, + privacy: 'Public' + }; + + client.uploadVideo(requestParams) + .then(response => { + should(response).have.property('name', requestParams.name); + should(response.state).be.equalOneOf('Processing', 'Uploaded') + should(response.id).not.be.null(); + done(); + }) + .catch(err => { + done(err); + }) + }); + }) }) From a320fd5cb272572f810ec96236a8dcd08a042951 Mon Sep 17 00:00:00 2001 From: Nsikan Essien Date: Thu, 6 Jun 2019 07:32:58 +0100 Subject: [PATCH 12/13] Error handling for access token generation failure --- test/vision/videoIndexerV2Test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/vision/videoIndexerV2Test.js b/test/vision/videoIndexerV2Test.js index 6cc3530..2be6dea 100644 --- a/test/vision/videoIndexerV2Test.js +++ b/test/vision/videoIndexerV2Test.js @@ -88,6 +88,9 @@ describe('Video Indexer V2', () => { accessToken = response; done(); }) + .catch((err) => { + done(err); + }) }); it(`should return a json with state, "Uploaded" or "Processing", and a video with name, ${videoName} and a Video id`, done => { From bb2ede7a455d39703bcc6ecf005366ae52749328 Mon Sep 17 00:00:00 2001 From: Nsikan Essien Date: Thu, 6 Jun 2019 07:33:15 +0100 Subject: [PATCH 13/13] Remove old video indexer library --- src/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.js b/src/index.js index 7291774..2ab3b95 100644 --- a/src/index.js +++ b/src/index.js @@ -25,6 +25,5 @@ module.exports = { bingSpeech: require('./speech/bingSpeech'), bingEntitySearch: require('./search/bingEntitySearch'), contentModerator: require('./vision/contentModerator'), - videoIndexer: require('./vision/videoIndexer'), videoIndexerV2: require('./vision/videoIndexerV2') }; \ No newline at end of file