Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function collectAuthorAndTypeFromVideo() {
- return new Promise((resolve, reject) => {
- try {
- var vidType = '';
- var maxWaitTime = 10000;
- var authorInit = document.evaluate(".//div[contains(@aria-label,'Dialog content')]//div//a[@data-hovercard and text()]", document, null, 9, null).singleNodeValue;
- //var currentTime = 0;
- var waitForAuthor = setInterval(() => {
- if (maxWaitTime <= 0) {
- console.log(`Did not found any author or vidType memories not supported. Continue...`);
- clearInterval(waitForAuthor);
- resolve({
- vidType: 'memories'
- });
- } else {
- console.log('IN PROFILE')
- authorInit = document.evaluate(".//div[contains(@aria-label,'Dialog content')]//div//a[@data-hovercard and text()]", document, null, 9, null).singleNodeValue;
- if (authorInit && authorInit.getAttribute('data-hovercard')) {
- vidType = 'profile';
- var authorIdProf = authorInit.getAttribute('data-hovercard').split('&')[0].split('php?id=');
- console.log(authorIdProf);
- var liveCheck = document.evaluate(".//ul/li/a//span[text()='Comments']", document, null, 9, null).singleNodeValue;
- if (liveCheck) {
- var authorInit = document.evaluate(".//div[contains(@class,'StreamStory')]//div//a[@data-hovercard and text()]", document, null, 9, null).singleNodeValue;
- authorIdProf = authorInit.getAttribute('data-hovercard').split('&')[0].split('php?id=');
- vidType = 'live';
- console.log(`set video type to ${vidType}`)
- } else if (authorIdProf[0].includes('page')) {
- vidType = 'page';
- console.log(`set vidType to ${vidType}`);
- } else if (authorIdProf[0].includes('user')) {
- vidType = 'profile';
- console.log(`set vidType to ${vidType}`);
- } else {
- vidType = 'memories';
- console.log(`set vidType to memories`);
- }
- var authorTitleProf = authorInit.textContent;
- console.log(authorTitleProf);
- clearInterval(waitForAuthor);
- var result = {
- authorId: authorIdProf[1],
- authorTitle: authorTitleProf,
- vidType: vidType
- }
- resolve(result);
- } else {
- maxWaitTime -= 500;
- console.log('adding time profile');
- }
- }
- }, 500)
- } catch (e) {
- console.log(`error in collectAuthorFromVideo ::: error => ${e.message}`);
- clearInterval(waitForAuthor);
- }
- })
- }
- async function prepareVideo() {
- return new Promise((resolve, reject) => {
- try {
- var maxTimeCheckVideo = 10000;
- var autoPlayClicked = false;
- var checkVideoInt = setInterval(() => {
- if (maxTimeCheckVideo <= 0) {
- console.log(`Did not found video. Continue...`);
- clearInterval(checkVideoInt);
- resolve('cannot find video');
- } else {
- if (document.URL.includes('/watch/?v')) {
- //vidType = 'profile';
- var autoPlayCheck = document.evaluate(".//div//input[contains(@aria-label, 'Play video')]", document, null, 9, null).singleNodeValue;
- var videoCheck = document.evaluate(".//video | .//canvas", document, null, 9, null).singleNodeValue;
- if (videoCheck) {
- if (autoPlayCheck && !autoPlayClicked) {
- autoPlayCheck.click();
- autoPlayClicked = true;
- console.log('auto play clicked');
- }
- if(autoPlayClicked || !autoPlayCheck) {
- videoCheck.click();
- console.log('video clicked - resolve first stage');
- clearInterval(checkVideoInt);
- resolve();
- } else {
- maxWaitTime -= 500;
- console.log('adding time after stopping auto play');
- }
- } else {
- maxWaitTime -= 500;
- console.log('adding time first stage');
- }
- } else if (document.URL.includes('/videos/')) {
- //vidType = 'profile'
- clearInterval(checkVideoInt);
- resolve();
- } else {
- clearInterval(checkVideoInt);
- resolve();
- }
- }
- }, 500);
- } catch (er) {
- console.log(`error in prepareVideo ::: er => ${e.message}`);
- clearInterval(checkVideoInt);
- }
- })
- }
- var obj = await prepareVideo().then(collectAuthorAndTypeFromVideo).then(res => res);
- console.log(obj);
Add Comment
Please, Sign In to add comment