@ubstream/ubstream-node-client-sdk / Exports / LibrariesSelectionsClient
Class: LibrariesSelectionsClient
This class provides access to methods to create and download selections of medias.
Hierarchy
AbstractClient
↳ LibrariesSelectionsClient
Table of contents
Methods
Methods
createMediasSelection
▸ createMediasSelection(libraryId
, selectionParams
): Promise
<IPublicLibraryMediasSelectionData
>
Parameters
Name | Type | Description |
---|---|---|
libraryId | string | The uuid of the targeted library. |
selectionParams | IPublicLibraryMediasSelectionCreationParams | The uuids of selected medias and the selection type ('download') |
Returns
Promise
<IPublicLibraryMediasSelectionData
>
Promise object representing the created selection.
Summary
Create a selection of multiple medias.
Example
const selection = await client.libraries.selections.createMediasSelection(
"library_id",
{
medias: [
{
mediaId: 'media_id_1',
},
{
mediaId: 'media_id_2',
},
],
},
);
downloadSelection
▸ downloadSelection(libraryId
, selectionId
, options?
): Promise
<IUbstreamHttpResponseStream
>
Download a selection of medias. If you request low resolution or plain text, the resources might not be ready to be downloaded. To prevent this call prepareDownloadForMedia first and wait for the request completion by polling on getRequestStatus.
Parameters
Name | Type | Description |
---|---|---|
libraryId | string | The uuid of the targeted library. |
selectionId | string | The uuid of the targeted selection. |
options? | IPublicDownloadOptions | Options of the download. |
Returns
Promise
<IUbstreamHttpResponseStream
>
Promise object representing a readable stream, the content-type and the name of the downloaded file.
Summary
Download a selection of medias : this method can be used to download one or several variants of many medias.
Example
const response = await client.libraries.selections.downloadSelection (
"library_id",
"selection_id",
{
quality: PublicDownloadQuality.ORIGINAL,
language: "en",
multiLang: false,
includesMetadata: false,
metadataFormat: PublicDownloadMetadataFormat.JSON,
metadataStrategy: PublicDownloadMetadataStrategy.BY_FILE,
},
);
// Use the readable stream to retrieve the resource.
const writer = fs.createWriteStream(`./${response.filename}`);
await new Promise(((resolve, reject) => {
writer.on('error', (e) => {
reject(e);
})
writer.on('close', () => {
resolve(undefined);
})
response.stream.pipe(writer);
}))
prepareDownloadForSelection
▸ prepareDownloadForSelection(libraryId
, selectionId
, options?
): Promise
<IPublicHttpResponseDataWithRequestId
>
Parameters
Name | Type | Description |
---|---|---|
libraryId | string | The uuid of the targeted library. |
selectionId | string | The uuid of the targeted selection. |
options? | IPublicDownloadOptions | Options of the download. |
Returns
Promise
<IPublicHttpResponseDataWithRequestId
>
Promise object containing the request ID to use to check the request completion.
Summary
Prepare the download a selection of medias. The missing resources will be generated.
Example
const downloadOptions = {
quality: PublicDownloadQuality.LOWER,
language: "en",
multiLang: false,
includesMetadata: false,
metadataFormat: PublicDownloadMetadataFormat.JSON,
metadataStrategy: PublicDownloadMetadataStrategy.BY_FILE,
};
const prepareResponse = await client.libraries.selections.prepareDownloadForSelection (
"library_id",
"selection_id",
downloadOptions,
);
// Wait for the request completion here by polling on getRequestStatus:
// await client.requests.getRequestStatus(prepareResponse.requestId)
...
// start the download
const response = await client.libraries.selections.downloadSelection (
"library_id",
"selection_id",
downloadOptions,
);