Added automatic BME login option

Signed-off-by: Balazs Toldi <balazs@toldi.eu>
This commit is contained in:
Balazs Toldi 2022-03-19 16:59:58 +01:00
parent f2810df95d
commit 0a80a0086a
Signed by: Bazsalanszky
GPG key ID: 6C7D440036F99D58
2 changed files with 27 additions and 2 deletions

View file

@ -16,6 +16,18 @@ export const argv: any = yargs.options({
describe: 'The username used to log into Microsoft Stream (enabling this will fill in the email field for you).',
demandOption: false
},
bmeCode: {
alias: 'b',
type: 'string',
describe: 'BME címtár azonosító',
demandOption: false
},
password: {
alias: 'p',
type: 'string',
describe: 'BME címtár jelszó',
demandOption: false
},
videoUrls: {
alias: 'i',
describe: 'List of urls to videos or Microsoft Stream groups.',

View file

@ -37,6 +37,9 @@ async function init(): Promise<void> {
if (argv.username) {
logger.info(`Username: ${argv.username}`);
}
if(argv.bmeCode){
logger.info(`BME Címtár azonosító: ${argv.bmeCode}`);
}
if (argv.simulate) {
logger.warn('Simulate mode, there will be no video downloaded. \n');
@ -44,7 +47,7 @@ async function init(): Promise<void> {
}
async function DoInteractiveLogin(url: string, username?: string): Promise<Session> {
async function DoInteractiveLogin(url: string, username?: string,bmeCode?: string,password?: string): Promise<Session> {
logger.info('Launching headless Chrome to perform the OpenID Connect dance...');
@ -68,6 +71,16 @@ async function DoInteractiveLogin(url: string, username?: string): Promise<Sessi
await page.waitForSelector('input[type="email"]', {timeout: 3000});
await page.keyboard.type(username);
await page.click('input[type="submit"]');
if(bmeCode){
await page.waitForSelector('input[type="text"]', {timeout: 3000});
await page.type('input[type="text"]', bmeCode);
if(password){
await page.type('input[type="password"]', password);
await page.click('input[type="submit"]');
await page.waitForSelector('#idSIButton9');
await page.click("#idSIButton9");
}
}
}
else {
/* If a username was not provided we let the user take actions that
@ -273,7 +286,7 @@ async function main(): Promise<void> {
let session: Session;
// eslint-disable-next-line prefer-const
session = tokenCache.Read() ?? await DoInteractiveLogin('https://web.microsoftstream.com/', argv.username);
session = tokenCache.Read() ?? await DoInteractiveLogin('https://web.microsoftstream.com/', argv.username,argv.bmeCode,argv.password);
logger.verbose('Session and API info \n' +
'\t API Gateway URL: '.cyan + session.ApiGatewayUri + '\n' +