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}`);