-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Video Indexer v2 #66
base: master
Are you sure you want to change the base?
Changes from 11 commits
387afab
9c91433
92abac3
6c761fe
558a0bf
9a46395
2d7591f
9310563
027ceaa
8f8e9b1
4f24e27
3c5b157
a320fd5
bb2ede7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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<Object[]>; | ||
getAccountAccessToken(options: GetAccountAccessTokenOptions): Promise<string> | ||
getUserAccessToken(options: GetUserAccessTokenOptions): Promise<string> | ||
} | ||
|
||
export interface videoIndexerV2Options { | ||
apiKey: string | ||
} | ||
|
||
export interface GetAccountOptions { | ||
location: string | ||
generateAccessTokens?: boolean, | ||
allowEdit?: boolean, | ||
} | ||
|
||
export interface GetAccountAccessTokenOptions { | ||
location: string, | ||
accountId: string, | ||
allowEdit?: boolean | ||
} | ||
|
||
export interface GetUserAccessTokenOptions { | ||
location: string, | ||
allowEdit?: boolean | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,319 @@ | ||
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: | ||
*/ | ||
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 | ||
]; | ||
// 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'] | ||
} | ||
|
||
/** | ||
* 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, | ||
allowEdit, | ||
}) { | ||
const operation = { | ||
parameters: [ | ||
{ | ||
name: 'location', | ||
required: true, | ||
type: 'routeParam', | ||
typeName: 'string' | ||
}, | ||
{ | ||
name: 'generateAccessTokens', | ||
required: false, | ||
type: 'queryStringParam', | ||
typeName: 'boolean', | ||
},{ | ||
name: 'allowEdit', | ||
required: false, | ||
type: 'queryStringParam', | ||
typeName: 'boolean' | ||
}, | ||
], | ||
path: `auth/{location}/Accounts`, | ||
method: 'GET' | ||
}; | ||
|
||
const requestParameters = { | ||
location, | ||
generateAccessTokens, | ||
allowEdit | ||
} | ||
|
||
return this.makeRequest({ | ||
operation: operation, | ||
parameters: requestParameters | ||
}) | ||
} | ||
|
||
/** | ||
* 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<string>} A promise containing an access token | ||
*/ | ||
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 | ||
}) | ||
} | ||
|
||
/** | ||
* 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<string>} 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 | ||
}) | ||
} | ||
|
||
/** | ||
* Uploads a video to the Video Indexer | ||
*/ | ||
uploadVideo(params){ | ||
if(!params.path && !params.videoUrl) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if I specify both? Which will be used? |
||
throw new Error('no video to upload. A video must be specified, either via videoUrl or a path'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this covered by tests? |
||
} | ||
|
||
const pathToVideo = (params.path) ? params.path : params.videoUrl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be simplified via |
||
|
||
const isFormatSupported = this.supportedFormats.filter(sf => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this covered by tests? |
||
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))){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line and line 190 can be simplified: |
||
// video should point to public url | ||
throw new Error('videoUrl is not an http/https link. A videoUrl must contain a public path'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this covered by tests? |
||
} 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this specific to the video indexer api? If not, can we pull this out into a separate file?