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:
1
.github/workflows/build.yaml
vendored
1
.github/workflows/build.yaml
vendored
@@ -24,5 +24,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
npm install
|
npm install
|
||||||
tsc --listEmittedFiles
|
tsc --listEmittedFiles
|
||||||
|
npm test
|
||||||
env:
|
env:
|
||||||
CI: true
|
CI: true
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import puppeteer from 'puppeteer';
|
|||||||
import { terminal as term } from 'terminal-kit';
|
import { terminal as term } from 'terminal-kit';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import { AssertionError } from 'assert';
|
||||||
|
|
||||||
|
|
||||||
// Type in your username here (the one you use to
|
// Type in your username here (the one you use to
|
||||||
@@ -15,7 +16,7 @@ const outputDirectory: string = 'videos';
|
|||||||
function sanityChecks() {
|
function sanityChecks() {
|
||||||
try {
|
try {
|
||||||
const ytdlVer = execSync('youtube-dl --version');
|
const ytdlVer = execSync('youtube-dl --version');
|
||||||
term.green(`\nUsing youtube-dl version ${ytdlVer}`);
|
term.green(`Using youtube-dl version ${ytdlVer}\n`);
|
||||||
}
|
}
|
||||||
catch (e) {
|
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.');
|
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 {
|
try {
|
||||||
const ffmpegVer = execSync('ffmpeg -version')
|
const ffmpegVer = execSync('ffmpeg -version')
|
||||||
.toString().split('\n')[0];
|
.toString().split('\n')[0];
|
||||||
term.green(`\nUsing ffmpeg version ${ffmpegVer}`);
|
term.green(`Using ffmpeg version ${ffmpegVer}\n`);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
console.error('FFmpeg is missing. You need a fairly recent release of FFmpeg in $PATH.');
|
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) {
|
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');
|
'Example: npm start https://www.microsoftstream.com/video/6f1a382b-e20c-44c0-98fc-5608286e48bc\n');
|
||||||
process.exit(-1);
|
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() {
|
async function rentVideoForLater() {
|
||||||
console.log('Launching headless Chrome to perform the OpenID Connect dance...');
|
console.log('Launching headless Chrome to perform the OpenID Connect dance...');
|
||||||
const browser = await puppeteer.launch({
|
const browser = await puppeteer.launch({
|
||||||
@@ -126,5 +145,13 @@ async function exfiltrateCookie(page: puppeteer.Page) {
|
|||||||
return `Authorization=${authzCookie.value}; Signature=${sigCookie.value}`;
|
return `Authorization=${authzCookie.value}; Signature=${sigCookie.value}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
sanityChecks();
|
// We should probably use Mocha or something
|
||||||
rentVideoForLater();
|
if (args[0] === 'test')
|
||||||
|
{
|
||||||
|
runBrowserTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
sanityChecks();
|
||||||
|
rentVideoForLater();
|
||||||
|
}
|
||||||
@@ -4,7 +4,8 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "destreamer.js",
|
"main": "destreamer.js",
|
||||||
"scripts": {
|
"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": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
|
|||||||
Reference in New Issue
Block a user