1
0
mirror of https://github.com/snobu/destreamer.git synced 2026-01-25 01:12:18 +00:00

Mid-apocalypse progress

This commit is contained in:
snobu
2020-04-05 17:20:10 +03:00
parent 37d596b4f0
commit 73aeb92e66
5 changed files with 74 additions and 69 deletions

View File

@@ -1,13 +1,15 @@
import axios, { AxiosError } from 'axios';
import { terminal as term } from 'terminal-kit';
import { Metadata } from './Types';
import { Metadata, Session } from './Types';
export async function getVideoMetadata(videoGuids: string[], session: any): Promise<Metadata[]> {
let metadata: Metadata[];
export async function getVideoMetadata(videoGuids: string[], session: Session): Promise<Metadata[]> {
let metadata: Metadata[] = [];
videoGuids.forEach(async guid => {
let apiUrl = `${session.ApiGatewayUri}videos/${guid}?api-version=${session.ApiGatewayVersion}`;
console.log(`Calling ${apiUrl}`);
let content = axios.get(
`${session.ApiGatewayUri}videos/${guid}?api-version=${session.ApiGatewayVersion}`,
apiUrl,
{
headers: {
Authorization: `Bearer ${session.AccessToken}`
@@ -18,20 +20,18 @@ export async function getVideoMetadata(videoGuids: string[], session: any): Prom
})
.catch((error: AxiosError) => {
term.red('Error when calling Microsoft Stream API: ' +
`${error.response?.status} ${error.response?.statusText}`);
term.red("This is an unrecoverable error. Exiting...");
`${error.response?.status} ${error.response?.statusText}\n`);
console.dir(error.response?.data);
term.red("This is an unrecoverable error. Exiting...\n");
process.exit(29);
});
let title = await content.then(data => {
let title: string = await content.then(data => {
return data["name"];
});
let playbackUrl = await content.then(data => {
// if (verbose) {
// console.log(JSON.stringify(data, undefined, 2));
// }
let playbackUrl: string = await content.then(data => {
let playbackUrl = null;
try {
playbackUrl = data["playbackUrls"]
@@ -41,19 +41,24 @@ export async function getVideoMetadata(videoGuids: string[], session: any): Prom
{ return item["playbackUrl"]; })[0];
}
catch (e) {
console.error(`Error fetching HLS URL: ${e}.\n playbackUrl is ${playbackUrl}`);
console.error(`Error fetching HLS URL: ${e.message}.\n playbackUrl is ${playbackUrl}`);
process.exit(27);
}
return playbackUrl;
});
console.log(`title = ${title} \n playbackUrl = ${playbackUrl}`)
metadata.push({
title: title,
playbackUrl: playbackUrl
});
});
console.log(`metadata--------`)
console.dir(metadata);
return metadata;
}