This package contains an isomorphic SDK for VideoSearchClient.
- Node.js version 6.x.x or higher
- Browser JavaScript
npm install @azure/cognitiveservices-videosearch
npm install @azure/ms-rest-azure-js
The following sample performs a video search on 'Microsoft Azure' with conditions such as the length must be Short, pricing must be Free, etc. To know more, refer to the Azure Documentation on Bing Video Search
import {
VideoSearchClient,
VideoSearchModels
} from "@azure/cognitiveservices-videosearch";
import { CognitiveServicesCredentials } from "@azure/ms-rest-azure-js";
async function main(): Promise<void> {
const videoSearchKey = process.env["videoSearchKey"] || "<videoSearchKey>";
const videoSearchEndPoint =
process.env["videoSearchEndPoint"] || "<videoSearchEndPoint>";
const cognitiveServiceCredentials = new CognitiveServicesCredentials(
videoSearchKey
);
const client = new VideoSearchClient(cognitiveServiceCredentials, {
endpoint: videoSearchEndPoint
});
const query = "Microsoft Azure";
const options: VideoSearchModels.VideosSearchOptionalParams = {
acceptLanguage: "en-US",
location: "westus2",
length: "Short",
pricing: "Free",
resolution: "HD720p"
};
client.videos
.search(query, options)
.then(result => {
console.log("The result is: ");
console.log(result);
})
.catch(err => {
console.log("An error occurred:");
console.error(err);
});
}
main();
- index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>@azure/cognitiveservices-videosearch sample</title>
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
<script src="node_modules/@azure/cognitiveservices-videosearch/dist/cognitiveservices-videosearch.js"></script>
<script type="text/javascript">
const videoSearchKey = "<YOUR_VIDEO_SEARCH_KEY>";
const videoSearchEndPoint = "<YOUR_VIDEO_SEARCH_ENDPOINT>";
const cognitiveServiceCredentials = new msRest.ApiKeyCredentials({
inHeader: {
"Ocp-Apim-Subscription-Key": videoSearchKey
}
});
const client = new Azure.CognitiveservicesVideosearch.VideoSearchClient(
cognitiveServiceCredentials,
{
endpoint: videoSearchEndPoint
}
);
const query = "Microsoft Azure";
const options = {
acceptLanguage: "en-US",
location: "westus2",
length: "Short",
pricing: "Free",
resolution: "HD720p"
};
client.videos
.search(query, options)
.then(result => {
console.log("The result is: ");
console.log(result);
})
.catch(err => {
console.log("An error occurred:");
console.error(err);
});
</script>
</head>
<body></body>
</html>