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

Pulled types separately

This commit is contained in:
snobu
2020-04-03 21:43:02 +03:00
parent 6091a6952e
commit 37d596b4f0
4 changed files with 24 additions and 34 deletions

View File

@@ -1,12 +1,8 @@
import axios from 'axios'; import axios, { AxiosError } from 'axios';
import { terminal as term } from 'terminal-kit'; 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<Metadata[]> { export async function getVideoMetadata(videoGuids: string[], session: any): Promise<Metadata[]> {
let metadata: Metadata[]; let metadata: Metadata[];
videoGuids.forEach(async guid => { videoGuids.forEach(async guid => {
@@ -17,18 +13,13 @@ export async function getVideoMetadata(videoGuids: string[], session: any): Prom
Authorization: `Bearer ${session.AccessToken}` Authorization: `Bearer ${session.AccessToken}`
} }
}) })
.then(function (response) { .then(response => {
return response.data; return response.data;
}) })
.catch(function (error) { .catch((error: AxiosError) => {
term.red('Error when calling Microsoft Stream API: ' + term.red('Error when calling Microsoft Stream API: ' +
`${error.response.status} ${error.response.reason}`); `${error.response?.status} ${error.response?.statusText}`);
console.error(error.response.status); term.red("This is an unrecoverable error. Exiting...");
console.error(error.response.data);
console.error("Exiting...");
if (argv.verbose) {
console.error(`[VERBOSE] ${error}`);
}
process.exit(29); process.exit(29);
}); });
@@ -38,9 +29,9 @@ export async function getVideoMetadata(videoGuids: string[], session: any): Prom
}); });
let playbackUrl = await content.then(data => { let playbackUrl = await content.then(data => {
if (argv.verbose) { // if (verbose) {
console.log(JSON.stringify(data, undefined, 2)); // console.log(JSON.stringify(data, undefined, 2));
} // }
let playbackUrl = null; let playbackUrl = null;
try { try {
playbackUrl = data["playbackUrls"] playbackUrl = data["playbackUrls"]
@@ -63,6 +54,6 @@ export async function getVideoMetadata(videoGuids: string[], session: any): Prom
}); });
}); });
return metadata; return metadata;
} }

10
Types.ts Normal file
View File

@@ -0,0 +1,10 @@
export interface Session {
AccessToken: string;
ApiGatewayUri: string;
ApiGatewayVersion: string;
}
export interface Metadata {
title: string;
playbackUrl: string;
}

View File

@@ -10,6 +10,7 @@ import path from 'path';
import yargs from 'yargs'; import yargs from 'yargs';
import sanitize from 'sanitize-filename'; import sanitize from 'sanitize-filename';
/** /**
* exitCode 25 = cannot split videoID from videUrl * exitCode 25 = cannot split videoID from videUrl
* exitCode 27 = no hlsUrl in the API response * exitCode 27 = no hlsUrl in the API response
@@ -38,14 +39,6 @@ const argv = yargs.options({
default: false, default: false,
demandOption: 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; }).argv;
if (argv.simulate){ if (argv.simulate){
@@ -124,8 +117,7 @@ async function DoInteractiveLogin(username?: string) {
return { return {
AccessToken: sessionInfo.AccessToken, AccessToken: sessionInfo.AccessToken,
ApiGatewayUri: sessionInfo.ApiGatewayUri, ApiGatewayUri: sessionInfo.ApiGatewayUri,
ApiGatewayVersion: sessionInfo.ApiGatewayVersion, ApiGatewayVersion: sessionInfo.ApiGatewayVersion
Cookie: cookie
}; };
} }
); );
@@ -174,7 +166,7 @@ async function rentVideoForLater(videoUrls: string[], outputDirectory: string, s
} }
console.log("Fetching title and HLS URL..."); 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 => { metadata.forEach(video => {
video.title = sanitize(video.title); video.title = sanitize(video.title);
@@ -190,9 +182,6 @@ async function rentVideoForLater(videoUrls: string[], outputDirectory: string, s
youtubedlCmd = youtubedlCmd + " -s"; youtubedlCmd = youtubedlCmd + " -s";
} }
if (argv.verbose) {
console.log(`\n\n[VERBOSE] Invoking youtube-dl:\n${youtubedlCmd}\n\n`);
}
execSync(youtubedlCmd, { stdio: 'inherit' }); execSync(youtubedlCmd, { stdio: 'inherit' });
} }
} }