From 7c0a2b53ce0e6db96e2962f70d7d13f7a861333d Mon Sep 17 00:00:00 2001 From: snobu Date: Mon, 30 Mar 2020 16:15:10 +0300 Subject: [PATCH] We need to move the interactive logon to its own method --- destreamer.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/destreamer.ts b/destreamer.ts index 80a091b..8b851f0 100644 --- a/destreamer.ts +++ b/destreamer.ts @@ -17,6 +17,8 @@ import axios from 'axios'; * exitCode 88 = error extracting cookies */ +let tokenCache = new TokenCache(); + const argv = yargs.options({ videoUrls: { type: 'array', alias: 'videourls', demandOption: true }, username: { type: 'string', demandOption: false }, @@ -85,6 +87,21 @@ function sanityChecks() { } async function rentVideoForLater(videoUrls: string[], outputDirectory: string, username?: string) { + + let accessToken = null; + + try { + accessToken = tokenCache.Read(); + console.log(`Read returned: ${accessToken}`); + process.exit(200); + } + catch (e) + { + console.log("cache is empty or expired"); + console.log(accessToken); + process.exit(404); + } + console.log('Launching headless Chrome to perform the OpenID Connect dance...'); const browser = await puppeteer.launch({ // Switch to false if you need to login interactively @@ -137,6 +154,8 @@ async function rentVideoForLater(videoUrls: string[], outputDirectory: string, u } ); + tokenCache.Write(session.AccessToken); + console.log(`ApiGatewayUri: ${session.ApiGatewayUri}`); console.log(`ApiGatewayVersion: ${session.ApiGatewayVersion}`);