-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.js
51 lines (47 loc) · 1.75 KB
/
player.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const puppeteer = require('puppeteer-extra');
const prompt = require("prompt-sync")({ sigint: true });
const input = prompt("Input your song name: ");
const { DEFAULT_INTERCEPT_RESOLUTION_PRIORITY } = require('puppeteer')
const AdblockerPlugin = require('puppeteer-extra-plugin-adblocker')
puppeteer.use(AdblockerPlugin());
(async () => {
console.log('Starting puppeteer')
const browser = await puppeteer.launch({
headless: true,
ignoreDefaultArgs: ['--mute-audio'],
args: ["--autoplay-policy=no-user-gesture-required"]
});
const page = await browser.newPage();
await page.setViewport({
width: 1280,
height: 720
});
console.log('Scraping YouTube');
await page.goto('https://youtube.com');
await page.click('div#search-input.ytd-searchbox-spt');
await page.focus('div#search-input.ytd-searchbox-spt');
await page.type('div#search-input.ytd-searchbox-spt', input);
await page.keyboard.press('Enter');
await page.waitForTimeout('2000');
await page.click('a#video-title.yt-simple-endpoint.style-scope.ytd-video-renderer');
console.log('Playing music');
await page.waitForTimeout(99999999);
await browser.close();
})();
async function autoScroll(page){
await page.evaluate(async () => {
await new Promise((resolve, reject) => {
var totalHeight = 0;
var distance = 100;
var timer = setInterval(() => {
var scrollHeight = document.body.scrollHeight;
window.scrollBy(0, distance);
totalHeight += distance;
if(totalHeight >= scrollHeight){
clearInterval(timer);
resolve();
}
}, 100);
});
});
}