1
0
mirror of https://github.com/snobu/destreamer.git synced 2026-01-16 21:12:13 +00:00

Login fixes (#50)

* automated update on install

* changed function name to be more significant

* Fixed the login procedure

-It's now initiated from a video url
-The login is done when we detect that the initial video page has loaded

* Minor fixes
- changed variable to camelCase
- added an exit log
This commit is contained in:
lukaarma
2020-04-10 18:20:55 +02:00
committed by GitHub
parent 2dd1a87905
commit 177c3dcf71

View File

@@ -77,7 +77,11 @@ function init() {
console.info(colors.blue("There will be no video downloaded, it's only a simulation\n"));
}
async function DoInteractiveLogin(username?: string): Promise<Session> {
async function DoInteractiveLogin(url: string, username?: string): Promise<Session> {
let videoId = url.split("/").pop() ?? (
console.log('Couldn\'t split the video Id from the first videoUrl'), process.exit(25)
);
console.log('Launching headless Chrome to perform the OpenID Connect dance...');
const browser = await puppeteer.launch({
@@ -85,10 +89,9 @@ async function DoInteractiveLogin(username?: string): Promise<Session> {
args: ['--disable-dev-shm-usage']
});
const page = (await browser.pages())[0];
console.log('Navigating to microsoftonline.com login page...');
console.log('Navigating to login page...');
// This breaks on slow connections, needs more reliable logic
await page.goto('https://web.microsoftstream.com', { waitUntil: 'networkidle2' });
await page.goto(url, { waitUntil: 'load' });
await page.waitForSelector('input[type="email"]');
if (username) {
@@ -96,16 +99,8 @@ async function DoInteractiveLogin(username?: string): Promise<Session> {
await page.click('input[type="submit"]');
}
await browser.waitForTarget(target => target.url().includes('microsoftstream.com/'), { timeout: 90000 });
await browser.waitForTarget(target => target.url().includes(videoId), { timeout: 150000 });
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.info('Got cookie. Consuming cookie...');
await sleep(4000);
console.info('Calling Microsoft Stream API...');
let sessionInfo: any;
let session = await page.evaluate(
@@ -119,12 +114,9 @@ async function DoInteractiveLogin(username?: string): Promise<Session> {
);
tokenCache.Write(session);
console.info('Wrote access token to token cache.');
console.log('Wrote access token to token cache.');
console.log("At this point Chromium's job is done, shutting it down...\n");
console.log(`ApiGatewayUri: ${session.ApiGatewayUri}`);
console.log(`ApiGatewayVersion: ${session.ApiGatewayVersion}`);
console.info("At this point Chromium's job is done, shutting it down...");
await browser.close();
return session;
@@ -241,7 +233,7 @@ async function main() {
let session = tokenCache.Read();
if (session == null) {
session = await DoInteractiveLogin(argv.username);
session = await DoInteractiveLogin(videoUrls[0], argv.username);
}