diff --git a/Metadata.ts b/Metadata.ts index 6fb9551..c9f4d8c 100644 --- a/Metadata.ts +++ b/Metadata.ts @@ -1,12 +1,8 @@ -import axios from 'axios'; +import axios, { AxiosError } from 'axios'; import { terminal as term } from 'terminal-kit'; +import { Metadata } from './Types'; -export interface Metadata { - title: string; - playbackUrl: string; -} - export async function getVideoMetadata(videoGuids: string[], session: any): Promise { let metadata: Metadata[]; videoGuids.forEach(async guid => { @@ -17,18 +13,13 @@ export async function getVideoMetadata(videoGuids: string[], session: any): Prom Authorization: `Bearer ${session.AccessToken}` } }) - .then(function (response) { + .then(response => { return response.data; }) - .catch(function (error) { + .catch((error: AxiosError) => { term.red('Error when calling Microsoft Stream API: ' + - `${error.response.status} ${error.response.reason}`); - console.error(error.response.status); - console.error(error.response.data); - console.error("Exiting..."); - if (argv.verbose) { - console.error(`[VERBOSE] ${error}`); - } + `${error.response?.status} ${error.response?.statusText}`); + term.red("This is an unrecoverable error. Exiting..."); process.exit(29); }); @@ -38,9 +29,9 @@ export async function getVideoMetadata(videoGuids: string[], session: any): Prom }); let playbackUrl = await content.then(data => { - if (argv.verbose) { - console.log(JSON.stringify(data, undefined, 2)); - } + // if (verbose) { + // console.log(JSON.stringify(data, undefined, 2)); + // } let playbackUrl = null; try { playbackUrl = data["playbackUrls"] @@ -63,6 +54,6 @@ export async function getVideoMetadata(videoGuids: string[], session: any): Prom }); }); - - return metadata; + + return metadata; } \ No newline at end of file diff --git a/BrowserTests.ts b/Tests.ts similarity index 100% rename from BrowserTests.ts rename to Tests.ts diff --git a/Types.ts b/Types.ts new file mode 100644 index 0000000..54248b2 --- /dev/null +++ b/Types.ts @@ -0,0 +1,10 @@ +export interface Session { + AccessToken: string; + ApiGatewayUri: string; + ApiGatewayVersion: string; +} + +export interface Metadata { + title: string; + playbackUrl: string; +} \ No newline at end of file diff --git a/destreamer.ts b/destreamer.ts index 94125d9..97ce31e 100644 --- a/destreamer.ts +++ b/destreamer.ts @@ -10,6 +10,7 @@ import path from 'path'; import yargs from 'yargs'; import sanitize from 'sanitize-filename'; + /** * exitCode 25 = cannot split videoID from videUrl * exitCode 27 = no hlsUrl in the API response @@ -38,14 +39,6 @@ const argv = yargs.options({ default: false, demandOption: false }, - verbose: { - alias: "v", - describe: `Print additional information to the console - (use this before opening an issue on GitHub)`, - type: "boolean", - default: false, - demandOption: false - } }).argv; if (argv.simulate){ @@ -124,8 +117,7 @@ async function DoInteractiveLogin(username?: string) { return { AccessToken: sessionInfo.AccessToken, ApiGatewayUri: sessionInfo.ApiGatewayUri, - ApiGatewayVersion: sessionInfo.ApiGatewayVersion, - Cookie: cookie + ApiGatewayVersion: sessionInfo.ApiGatewayVersion }; } ); @@ -174,7 +166,7 @@ async function rentVideoForLater(videoUrls: string[], outputDirectory: string, s } console.log("Fetching title and HLS URL..."); - let metadata: Metadata[] = await getVideoMetadata(videoGuids, session); + let metadata: Metadata[] = await getVideoMetadata(videoGuids, session: Session); metadata.forEach(video => { video.title = sanitize(video.title); @@ -190,9 +182,6 @@ async function rentVideoForLater(videoUrls: string[], outputDirectory: string, s youtubedlCmd = youtubedlCmd + " -s"; } - if (argv.verbose) { - console.log(`\n\n[VERBOSE] Invoking youtube-dl:\n${youtubedlCmd}\n\n`); - } execSync(youtubedlCmd, { stdio: 'inherit' }); } }