Automating Youtube views

Louis.Z
2 min readDec 5, 2020

Purpose

Youtube’s algorithm boosts videos that are in view. Therefore you may want to constantly keep your videos in watch to get even more views. Alternatively, automating youtube views is a pretty fun project.

Tech Stack

The technology used is quite simple. I will be using primarily Nodejs and PuppeteerJS as I would like to emulate a human viewer as close as possible. Using PuppeteerJS encapsulates most of the complexity.

Application Flow

  1. Create a new tab
  2. Load Youtube Website
  3. Start the video
  4. Listen to “On Video Ended” event
  5. Reload the page (or go to the next video)
  1. Create a new tab
const browser = await puppeteer.launch({   headless: headless,});const page = await this._browser.newPage();

2. Load Youtube Website

page.goto(url, {waitUntil: 'networkidle2'});

3. Start the video

page.click('#container');

4. Listen to “On Video Ended” event

By default, the page does not provide you with the on video ended event. While it is possible that Youtube’s existing javascript has such an events to tap into, here we are just going to do something simple.

Code Snipplet for checking of video play time

We setup a check every 5 seconds and inspect the text for the current duration and the total video timestamp. If the values are the same, we conclude that video has ended. Else we register for the next check.

You may have noticed the video ended code calling “window.videoEnded()”. To subscribe to that event, you will just need the code below:

await page.exposeFunction('videoEnded', () => {   this.fire('videoEnded');});

And here on, the application is complete. Code is rather simple. On video ended, you can either replay the video or go on to the next video. Perform an infinite loop and track statistics on the number of videos.

Youtube has its own algorithm to determine what is a view and you will be able to track how many views are from you and how many organic. Track your Youtube analytics for more accurate details.

Scaling through Proxy IPs

Ok, now that we accomplish with 1 viewer, let us try to scale it. Through proxy servers, we could potentially act as a viewer from anywhere in the world. You will also like to use that to emulate multiple viewers from different IPs. To do that, you would just need to add args and the proxy server as the parameter as below.

this._browser = await puppeteer.launch({   headless: headless,   args: [      `--proxy-server=socks5://123.123.123.123:1234`,   ]});

Overcoming reCAPTCHA

Encountering reCAPTCHA from Youtube

If you are using free proxy, you will definitely encounter reCAPTCHA from Google. It will be extremely challenging to overcome it. It becomes much easier if it is a real human performing the task but you will not be able to scale your views programmatically. Still, it is definitely an interesting challenge to be looked into in future articles.

--

--

Louis.Z

A passionate software engineer with strong background in web technology, product development and design architecture.