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

Added browser test

This commit is contained in:
snobu
2019-10-01 10:00:07 +03:00
parent 4b2439f75c
commit ffb9c86a7f
3 changed files with 35 additions and 6 deletions

View File

@@ -24,5 +24,6 @@ jobs:
run: |
npm install
tsc --listEmittedFiles
npm test
env:
CI: true

View File

@@ -3,6 +3,7 @@ import puppeteer from 'puppeteer';
import { terminal as term } from 'terminal-kit';
import fs from 'fs';
import path from 'path';
import { AssertionError } from 'assert';
// Type in your username here (the one you use to
@@ -15,7 +16,7 @@ const outputDirectory: string = 'videos';
function sanityChecks() {
try {
const ytdlVer = execSync('youtube-dl --version');
term.green(`\nUsing youtube-dl version ${ytdlVer}`);
term.green(`Using youtube-dl version ${ytdlVer}\n`);
}
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.');
@@ -25,7 +26,7 @@ function sanityChecks() {
try {
const ffmpegVer = execSync('ffmpeg -version')
.toString().split('\n')[0];
term.green(`\nUsing ffmpeg version ${ffmpegVer}`);
term.green(`Using ffmpeg version ${ffmpegVer}\n`);
}
catch (e) {
console.error('FFmpeg is missing. You need a fairly recent release of FFmpeg in $PATH.');
@@ -38,12 +39,30 @@ function sanityChecks() {
}
if (args[0] == null || args[0].length < 10) {
console.error('Pass in video URL as first argument: \n' +
console.error('Pass in video URL as first argument:\n' +
'Example: npm start https://www.microsoftstream.com/video/6f1a382b-e20c-44c0-98fc-5608286e48bc\n');
process.exit(-1);
}
}
async function runBrowserTest() {
console.log('[BROWSER TEST] Launching headless Chrome...');
const browser = await puppeteer.launch({
// Switch to false if you need to login interactively
headless: true,
args: ['--disable-dev-shm-usage']
});
const page = await browser.newPage();
await page.goto("https://github.com/", { waitUntil: 'networkidle2' });
let pageTitle = await page.title();
await browser.close();
if (!pageTitle.includes('GitHub'))
{
process.exit(44);
}
console.log('[BROWSER TEST] PASS');
}
async function rentVideoForLater() {
console.log('Launching headless Chrome to perform the OpenID Connect dance...');
const browser = await puppeteer.launch({
@@ -126,5 +145,13 @@ async function exfiltrateCookie(page: puppeteer.Page) {
return `Authorization=${authzCookie.value}; Signature=${sigCookie.value}`;
}
sanityChecks();
rentVideoForLater();
// We should probably use Mocha or something
if (args[0] === 'test')
{
runBrowserTest();
}
else {
sanityChecks();
rentVideoForLater();
}

View File

@@ -4,7 +4,8 @@
"description": "",
"main": "destreamer.js",
"scripts": {
"start": "echo Transpiling TypeScript to JavaScript... && tsc && node ./destreamer.js"
"start": "echo Transpiling TypeScript to JavaScript... && tsc && node ./destreamer.js",
"test": "node ./destreamer.js test"
},
"keywords": [],
"author": "",