Skip to content

Commit 78e5818

Browse files
authored
Fix login for private tenants, improved refresh reliability (#181)
1 parent 0be6ad8 commit 78e5818

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/TokenCache.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export class TokenCache {
5353
}
5454

5555

56-
export async function refreshSession(): Promise<Session> {
57-
const url = 'https://web.microsoftstream.com';
56+
export async function refreshSession(url: string): Promise<Session> {
57+
const videoId: string = url.split('/').pop() ?? process.exit(ERROR_CODE.INVALID_VIDEO_GUID);
5858

5959
const browser: puppeteer.Browser = await puppeteer.launch({
6060
executablePath: getPuppeteerChromiumPath(),
@@ -70,7 +70,7 @@ export async function refreshSession(): Promise<Session> {
7070
const page: puppeteer.Page = (await browser.pages())[0];
7171
await page.goto(url, { waitUntil: 'load' });
7272

73-
await browser.waitForTarget((target: puppeteer.Target) => target.url().includes(url), { timeout: 30000 });
73+
await browser.waitForTarget((target: puppeteer.Target) => target.url().includes(videoId), { timeout: 30000 });
7474

7575
let session: Session | null = null;
7676
let tries = 1;

src/destreamer.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ async function init(): Promise<void> {
4444

4545

4646
async function DoInteractiveLogin(url: string, username?: string): Promise<Session> {
47-
const videoId: string = url.split('/').pop() ?? process.exit(ERROR_CODE.INVALID_VIDEO_GUID);
4847

4948
logger.info('Launching headless Chrome to perform the OpenID Connect dance...');
5049

@@ -81,7 +80,7 @@ async function DoInteractiveLogin(url: string, username?: string): Promise<Sessi
8180
remember the credentials or it could still prompt the user for a password */
8281
}
8382

84-
await browser.waitForTarget((target: puppeteer.Target) => target.url().includes(videoId), { timeout: 150000 });
83+
await browser.waitForTarget((target: puppeteer.Target) => target.url().includes('microsoftstream.com'), { timeout: 150000 });
8584
logger.info('We are logged in.');
8685

8786
let session: Session | null = null;
@@ -142,16 +141,16 @@ async function downloadVideo(videoGUIDs: Array<string>, outputDirectories: Array
142141
return;
143142
}
144143

145-
for (const video of videos) {
144+
for (const [index, video] of videos.entries()) {
146145

147146
if (argv.skip && fs.existsSync(video.outPath)) {
148147
logger.info(`File already exists, skipping: ${video.outPath} \n`);
149148
continue;
150149
}
151150

152-
if (argv.keepLoginCookies) {
151+
if (argv.keepLoginCookies && index !== 0) {
153152
logger.info('Trying to refresh token...');
154-
session = await refreshSession();
153+
session = await refreshSession('https://web.microsoftstream.com/video/' + videoGUIDs[index]);
155154
}
156155

157156
const pbar: cliProgress.SingleBar = new cliProgress.SingleBar({

0 commit comments

Comments
 (0)