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

Less convoluted console coloring

This commit is contained in:
snobu
2020-04-09 12:42:14 +03:00
parent be783e84e4
commit 427b58d97d
5 changed files with 23 additions and 214 deletions

View File

@@ -1,5 +1,4 @@
import axios from 'axios';
import { terminal as term } from 'terminal-kit';
import { Metadata, Session } from './Types';
@@ -27,8 +26,6 @@ export async function getVideoMetadata(videoGuids: string[], session: Session):
posterImage = response.data["posterImage"]["medium"]["url"];
term.brightMagenta(`\n title = ${title}\n playbackUrl = ${playbackUrl}\n`);
metadata.push({
title: title,
playbackUrl: playbackUrl,

View File

@@ -1,7 +1,9 @@
import * as fs from 'fs';
import { Session } from './Types';
import { terminal as term } from 'terminal-kit';
import { bgGreen, bgYellow, green } from 'colors';
const jwtDecode = require('jwt-decode');
const tokenCacheFile = '.token_cache';
export class TokenCache {
@@ -9,7 +11,7 @@ export class TokenCache {
public Read(): Session | null {
let j = null;
if(!fs.existsSync(tokenCacheFile)) {
term.yellow(`${tokenCacheFile} not found.\n`);
console.warn(bgYellow.black(`${tokenCacheFile} not found.\n`));
return null;
}
@@ -27,16 +29,13 @@ export class TokenCache {
let timeLeft = exp - now;
let timeLeftInMinutes = Math.floor(timeLeft / 60);
console.log("\n");
console.log("\n");
if (timeLeft < 120) {
term.bgBrightYellow.black("Access token is expired.").bgDefaultColor("\n");
console.warn(bgYellow.black('\nAccess token has expired.'));
return null;
}
term.bgBrightGreen.black(`Access token still good for ${timeLeftInMinutes} minutes.`)
.bgDefaultColor("\n");
console.info(bgGreen.black(`\nAccess token still good for ${timeLeftInMinutes} minutes.\n`));
let session: Session = {
AccessToken: j.AccessToken,
@@ -53,7 +52,7 @@ export class TokenCache {
if (err) {
return console.error(err);
}
console.log("Fresh access token dropped into .token_cache");
console.info(green('Fresh access token dropped into .token_cache'));
});
}
}

View File

@@ -5,7 +5,7 @@ import { drawThumbnail } from './Thumbnail';
import { execSync } from 'child_process';
import puppeteer from 'puppeteer';
import { terminal as term } from 'terminal-kit';
import colors from 'colors';
import fs from 'fs';
import path from 'path';
import yargs from 'yargs';
@@ -45,7 +45,7 @@ const argv = yargs.options({
if (argv.simulate){
console.info('Video URLs: %s', argv.videoUrls);
console.info('Username: %s', argv.username);
term.blue("There will be no video downloaded, it's only a simulation\n");
console.info(colors.green('There will be no video downloaded, it\'s only a simulation\n'));
} else {
console.info('Video URLs: %s', argv.videoUrls);
console.info('Username: %s', argv.username);
@@ -57,7 +57,7 @@ if (argv.simulate){
function sanityChecks() {
try {
const ytdlVer = execSync('youtube-dl --version');
term.green(`Using youtube-dl version ${ytdlVer}`);
console.info(colors.green(`Using youtube-dl version ${ytdlVer}`));
}
catch (e) {
console.error('You need youtube-dl in $PATH for this to work. Make sure it is a relatively recent one, baked after 2019.');
@@ -67,7 +67,7 @@ function sanityChecks() {
try {
const ffmpegVer = execSync('ffmpeg -version')
.toString().split('\n')[0];
term.green(`Using ${ffmpegVer}\n`);
console.info(colors.green(`Using ${ffmpegVer}\n`));
}
catch (e) {
console.error('FFmpeg is missing. You need a fairly recent release of FFmpeg in $PATH.');
@@ -100,15 +100,15 @@ async function DoInteractiveLogin(username?: string): Promise<Session> {
}
await browser.waitForTarget(target => target.url().includes('microsoftstream.com/'), { timeout: 90000 });
console.log('We are logged in.');
console.info('We are logged in.');
// We may or may not need to sleep here.
// Who am i to deny a perfectly good nap?
await sleep(1500);
console.log('Got cookie. Consuming cookie...');
console.info('Got cookie. Consuming cookie...');
await sleep(4000);
console.log("Calling Microsoft Stream API...");
console.info("Calling Microsoft Stream API...");
let sessionInfo: any;
let session = await page.evaluate(
@@ -122,12 +122,12 @@ async function DoInteractiveLogin(username?: string): Promise<Session> {
);
tokenCache.Write(session);
console.log("Wrote access token to token cache.");
console.info("Wrote access token to token cache.");
console.log(`ApiGatewayUri: ${session.ApiGatewayUri}`);
console.log(`ApiGatewayVersion: ${session.ApiGatewayVersion}`);
console.log("At this point Chromium's job is done, shutting it down...");
console.info("At this point Chromium's job is done, shutting it down...");
await browser.close();
return session;
@@ -173,7 +173,7 @@ async function downloadVideo(videoUrls: string[], outputDirectory: string, sessi
let metadata: Metadata[] = await getVideoMetadata(videoGuids, session);
await Promise.all(metadata.map(async video => {
video.title = sanitize(video.title);
term.blue(`\nDownloading Video: ${video.title}\n`);
console.log(colors.blue(`\nDownloading Video: ${video.title}\n`));
// Very experimental inline thumbnail rendering
await drawThumbnail(video.posterImage, session.AccessToken);

196
package-lock.json generated
View File

@@ -30,19 +30,6 @@
"js-tokens": "^4.0.0"
}
},
"@cronvel/get-pixels": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/@cronvel/get-pixels/-/get-pixels-3.3.1.tgz",
"integrity": "sha512-jgDb8vGPkpjRDbiYyHTI2Bna4HJysjPNSiERzBnRJjCR/YqC3u0idTae0tmNECsaZLOpAWmlK9wiIwnLGIT9Bg==",
"requires": {
"jpeg-js": "^0.1.1",
"ndarray": "^1.0.13",
"ndarray-pack": "^1.1.1",
"node-bitmap": "0.0.1",
"omggif": "^1.0.5",
"pngjs": "^2.0.0"
}
},
"@sindresorhus/jimp": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/jimp/-/jimp-0.3.0.tgz",
@@ -121,12 +108,6 @@
"resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.0.tgz",
"integrity": "sha1-nKUs2jY/aZxpRmwqbM2q2RPqenM="
},
"@types/nextgen-events": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@types/nextgen-events/-/nextgen-events-1.1.0.tgz",
"integrity": "sha512-vRh1NWJKNuhdeo0x85veoA7gZTC9IIC9LSmFUHT5Vk50rH/SDvXy4gKarcT4rLfBWxOIfyozpX/IHAAnz4oWTg==",
"dev": true
},
"@types/node": {
"version": "13.9.5",
"resolved": "https://registry.npmjs.org/@types/node/-/node-13.9.5.tgz",
@@ -142,15 +123,6 @@
"@types/node": "*"
}
},
"@types/terminal-kit": {
"version": "1.28.1",
"resolved": "https://registry.npmjs.org/@types/terminal-kit/-/terminal-kit-1.28.1.tgz",
"integrity": "sha512-WtBTVRxwTIWkEBAU33U0MEVaiOX+X0yvNy4jOfFkT3khSTPz1f79ayyTRSqKE2StZKJqU78Tz7sPQwwhAf12MQ==",
"dev": true,
"requires": {
"@types/nextgen-events": "*"
}
},
"@types/yargs": {
"version": "15.0.4",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.4.tgz",
@@ -405,14 +377,6 @@
"integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==",
"dev": true
},
"chroma-js": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/chroma-js/-/chroma-js-2.1.0.tgz",
"integrity": "sha512-uiRdh4ZZy+UTPSrAdp8hqEdVb1EllLtTHOt5TMaOjJUvi+O54/83Fc5K2ld1P+TJX+dw5B+8/sCgzI6eaur/lg==",
"requires": {
"cross-env": "^6.0.3"
}
},
"cli-cursor": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz",
@@ -461,6 +425,11 @@
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
},
"colors": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
"integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA=="
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@@ -482,52 +451,6 @@
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"cross-env": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/cross-env/-/cross-env-6.0.3.tgz",
"integrity": "sha512-+KqxF6LCvfhWvADcDPqo64yVIB31gv/jQulX2NGzKS/g3GEVz6/pt4wjHFtFWsHMddebWD/sDthJemzM4MaAag==",
"requires": {
"cross-spawn": "^7.0.0"
},
"dependencies": {
"cross-spawn": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.1.tgz",
"integrity": "sha512-u7v4o84SwFpD32Z8IIcPZ6z1/ie24O6RU3RbtL5Y316l3KuHVPx9ItBgWQ6VlfAFnRnTtMUrsQ9MUUTuEZjogg==",
"requires": {
"path-key": "^3.1.0",
"shebang-command": "^2.0.0",
"which": "^2.0.1"
}
},
"path-key": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
"integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q=="
},
"shebang-command": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
"integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
"requires": {
"shebang-regex": "^3.0.0"
}
},
"shebang-regex": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A=="
},
"which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
"requires": {
"isexe": "^2.0.0"
}
}
}
},
"cross-spawn": {
"version": "6.0.5",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz",
@@ -547,14 +470,6 @@
}
}
},
"cwise-compiler": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/cwise-compiler/-/cwise-compiler-1.1.3.tgz",
"integrity": "sha1-9NZnQQ6FDToxOn0tt7HlBbsDTMU=",
"requires": {
"uniq": "^1.0.0"
}
},
"debug": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
@@ -1106,16 +1021,6 @@
}
}
},
"iota-array": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/iota-array/-/iota-array-1.0.0.tgz",
"integrity": "sha1-ge9X/l0FgUzVjCSDYyqZwwoOgIc="
},
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
},
"is-extglob": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
@@ -1171,11 +1076,6 @@
"plist": "^3.0.1"
}
},
"jpeg-js": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/jpeg-js/-/jpeg-js-0.1.2.tgz",
"integrity": "sha1-E1uZLAV1yYXPoPSUoyJ+0jhYPs4="
},
"jpgjs": {
"version": "github:notmasteryet/jpgjs#f1d30922fda93417669246f5a25cf2393dd9c108",
"from": "github:notmasteryet/jpgjs"
@@ -1213,11 +1113,6 @@
"resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz",
"integrity": "sha1-fYa9VmefWM5qhHBKZX3TkruoGnk="
},
"lazyness": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/lazyness/-/lazyness-1.1.1.tgz",
"integrity": "sha512-rYHC6l6LeRlJSt5jxpqN8z/49gZ0CqLi89HAGzJjHahCFlqEjFGFN9O15hmzSzUGFl7zN/vOWduv/+0af3r/kQ=="
},
"levn": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz",
@@ -1334,39 +1229,11 @@
"integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=",
"dev": true
},
"ndarray": {
"version": "1.0.19",
"resolved": "https://registry.npmjs.org/ndarray/-/ndarray-1.0.19.tgz",
"integrity": "sha512-B4JHA4vdyZU30ELBw3g7/p9bZupyew5a7tX1Y/gGeF2hafrPaQZhgrGQfsvgfYbgdFZjYwuEcnaobeM/WMW+HQ==",
"requires": {
"iota-array": "^1.0.0",
"is-buffer": "^1.0.2"
}
},
"ndarray-pack": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/ndarray-pack/-/ndarray-pack-1.2.1.tgz",
"integrity": "sha1-jK6+qqJNXs9w/4YCBjeXfajuWFo=",
"requires": {
"cwise-compiler": "^1.1.2",
"ndarray": "^1.0.13"
}
},
"nextgen-events": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/nextgen-events/-/nextgen-events-1.3.0.tgz",
"integrity": "sha512-eBz5mrO4Hw2eenPVm0AVPHuAzg/RZetAWMI547RH8O9+a0UYhCysiZ3KoNWslnWNlHetb9kzowEshsKsmFo2YQ=="
},
"nice-try": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz",
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ=="
},
"node-bitmap": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/node-bitmap/-/node-bitmap-0.0.1.tgz",
"integrity": "sha1-GA6scAPgxwdhjvMTaPYvhLKmkJE="
},
"npm-run-path": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz",
@@ -1375,11 +1242,6 @@
"path-key": "^2.0.0"
}
},
"omggif": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/omggif/-/omggif-1.0.10.tgz",
"integrity": "sha512-LMJTtvgc/nugXj0Vcrrs68Mn2D1r0zf630VNtqtpI1FEO7e+O9FP4gqs9AcnBaSEeoHIPm28u6qgPR0oyEpGSw=="
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
@@ -1538,11 +1400,6 @@
}
}
},
"pngjs": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/pngjs/-/pngjs-2.3.1.tgz",
"integrity": "sha1-EdHhK5y2TWPjDBQ6Mw9MH1Z9qF8="
},
"prelude-ls": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz",
@@ -1718,24 +1575,11 @@
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
"integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc="
},
"setimmediate": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
"integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU="
},
"setprototypeof": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
"integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
},
"seventh": {
"version": "0.7.35",
"resolved": "https://registry.npmjs.org/seventh/-/seventh-0.7.35.tgz",
"integrity": "sha512-8uGsybZk/XBSv7BvyjbSeK+R8vpWh2jkZJq0UIMVlJTr9CZsCLTfGWKtcBxmHzMUbzSPxa134prhvZA8GuIx/w==",
"requires": {
"setimmediate": "^1.0.5"
}
},
"shebang-command": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz",
@@ -1784,11 +1628,6 @@
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
},
"string-kit": {
"version": "0.11.6",
"resolved": "https://registry.npmjs.org/string-kit/-/string-kit-0.11.6.tgz",
"integrity": "sha512-rI3KOfSgFg02+BSP/ocUl8E3hoqV8C8OsMHUZhIy2BHfP8V0HV0iGwM67Zzepv+U9XryH01tHO8EAIaIK66Eqg=="
},
"string-width": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz",
@@ -1909,21 +1748,6 @@
"term-img": "^4.1.0"
}
},
"terminal-kit": {
"version": "1.35.2",
"resolved": "https://registry.npmjs.org/terminal-kit/-/terminal-kit-1.35.2.tgz",
"integrity": "sha512-PCNmMKjlcGQN/OlQ+nzdgPmrS0kmPcOqPCmHPrxCfOuvz0fQ1fZLiyivRIcwzY9bnm624VVsywUis+iPA3Hq5A==",
"requires": {
"@cronvel/get-pixels": "^3.3.1",
"chroma-js": "^2.1.0",
"lazyness": "^1.1.1",
"ndarray": "^1.0.19",
"nextgen-events": "^1.3.0",
"seventh": "^0.7.35",
"string-kit": "^0.11.6",
"tree-kit": "^0.6.2"
}
},
"text-table": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz",
@@ -1955,11 +1779,6 @@
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
"integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw=="
},
"tree-kit": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/tree-kit/-/tree-kit-0.6.2.tgz",
"integrity": "sha512-95UzJA0EMbFfu5sGUUOoXixQMUGkwu82nGM4lmqLyQl+R4H3FK+lS0nT8TZJ5x7JhSHy+saVn7/AOqh6d+tmOg=="
},
"truncate-utf8-bytes": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz",
@@ -2008,11 +1827,6 @@
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz",
"integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w=="
},
"uniq": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/uniq/-/uniq-1.0.1.tgz",
"integrity": "sha1-sxxa6CVIRKOoKBVBzisEuGWnNP8="
},
"unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",

View File

@@ -19,7 +19,6 @@
"devDependencies": {
"@types/jwt-decode": "^2.2.1",
"@types/puppeteer": "^1.20.0",
"@types/terminal-kit": "^1.28.1",
"@types/yargs": "^15.0.3",
"@typescript-eslint/eslint-plugin": "^2.25.0",
"@typescript-eslint/parser": "^2.25.0",
@@ -27,11 +26,11 @@
},
"dependencies": {
"axios": "^0.19.2",
"colors": "^1.4.0",
"jwt-decode": "^2.2.0",
"puppeteer": "^2.1.1",
"sanitize-filename": "^1.6.3",
"terminal-image": "^0.2.0",
"terminal-kit": "^1.35.2",
"typescript": "^3.8.3",
"yargs": "^15.0.3"
}