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:
27
Metadata.ts
27
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<Metadata[]> {
|
||||
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"]
|
||||
|
||||
10
Types.ts
Normal file
10
Types.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export interface Session {
|
||||
AccessToken: string;
|
||||
ApiGatewayUri: string;
|
||||
ApiGatewayVersion: string;
|
||||
}
|
||||
|
||||
export interface Metadata {
|
||||
title: string;
|
||||
playbackUrl: string;
|
||||
}
|
||||
@@ -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' });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user