DEV Community

Danijel Vincijanović for COBE Tech

Posted on

Is this a €1.000,00 worth Node script?

So the story begins with one of my favourite Youtube channels. A few days ago, they've published a new video announcing that they will soon reach their 100k subscriber and on that occasion will give out a €1.000,00 voucher which the person can then spend on new equipment.
That's a lot of money! Especially if you're, like me, living in Croatia. We're talking about approximate 20% more than an average monthly salary here.

Plot

I must admit, after I heard the announcement I was immediately hooked. I paused the video and started thinking of ways to become that 100k subscriber and win the voucher. What I figured out next is that manually checking the number of subscribers and waiting for the right moment to hit the subscribe button won't bring me any luck. I needed a machine to do that work for me if I want to be faster than others.

Fast as machine

After a short brainstorming session I came up with an easy solution and the only thing I needed was Youtube API and a little bit of Node. Solution is pretty straightforward: we had to know how many subscribers the channel has so when it reaches its 99.999 subscriber we would need to subscribe.

Challenges

If you're already thinking about implementation then you know that we'll need setInterval or setTimeout so we can repeatedly check the number of subscribers.

The only limitation we have here is YouTube Data API quota usage. We get default quota allocation of 10.000 units per day which means that each request will cost us some units. 

In our case, if we want to get a number of channel subscribers we need to do a request to https://www.googleapis.com/youtube/v3/channels?part=statistics and that request will cost us 3 units. You can calculate your quota cost using Youtube Quota Calculator.

If we check the subscribers count every second we'll drain our quota by running our script for 55 minutes which is just not enough; we want our script to run longer so that we don't miss out on our chance. The only solution for this limitation is to use a different interval delay depending on the number of subscribers. That means that we'll perform requests more frequently as the number of subscribers approaches 100k. In the beginning we'll start with one request per hour and then we'll get all the way down to 300 milliseconds.

Solution

Check the solution in this repo below and try it out.

Youtube Subscriber

If you want to know why this repo was created read this story about €1.000,00 voucher.

Installation

Clone repository

$ git clone https://github.com/davinci2015/youtube-subscriber.git
Enter fullscreen mode Exit fullscreen mode

cd into directory

$ cd youtube-subscriber
Enter fullscreen mode Exit fullscreen mode

Install NPM dependencies

$ npm install
Enter fullscreen mode Exit fullscreen mode

Configuration

Before running the script you should update variables inside of config.js file.

Update following variables:

  • channelId
  • client_secret
  • client_id

Run the server

After updating config variables you can run server and let him do the magic.

$ node main.js
Enter fullscreen mode Exit fullscreen mode



Twist

After I've finished with the implementation, I continued watching the video where they announce their bounty. In that moment I knew I f***** up. It was never about being the 100Kth subscriber, it was about visiting their social profiles and participating in the prize game where the winner will be randomly chosen.

So here I am, with a published script and without a €1.000,00 voucher. But let's look at the bright side  - at least I've learned something new and maybe, in the future, this script helps someone actually win the voucher, who knows. 
Until then, happy coding!

Top comments (12)

Collapse
 
antontsvil profile image
Anton T

This is a tragic cautionary tale that's all too familiar. You THINK you know what the client wants, and then when you put all your heart and soul to build the perfect product you realize you completely misunderstood the requirements! The lesson is to remember to understand the problem completely before trying to solve it 😉

Collapse
 
davinc profile image
Danijel Vincijanović

Totally agree! It's easy to get excited when you're building something for fun 😀

Collapse
 
andrewbrown profile image
Andrew Brown 🇨🇦

$1 is very cheap of them.

Collapse
 
nektro profile image
Meghan (she/her)

The , and . are switched. They were offering 1,000 euros

Collapse
 
andrewbrown profile image
Andrew Brown 🇨🇦

I am having a bit of fun. I realize that in Europe countries denote thousands with a period instead of command.

Collapse
 
protium profile image
protium

Nice anecdote!
I remember long time ago, there was an online game to win a LG smart TV. I was really new in programming but really curious about it. So I found out that the game was made with Flash. I downloaded the .swf file and found a decompiler. Once I decompiled it I got all the answers. Then I made a small windows form app that simulated the keyboard. I started my app and then I started the game.

In the first run I was first with a score of 5 seconds (the rest of participants had at least 1 minute). Of course they removed the game. But I learned so many new things because of that 😀

Collapse
 
hexrcs profile image
Xiaoru Li

Hahaha 🤣 I've made the same mistake of not reading (watching) the requirements carefully many times myself. My latest one is that I studied for a course this semester so hard but in the end, I wasn't able to sign up for the exam, because I skipped the second slide of the first lecture where they clearly said I had to have passed another exam as a prerequisite 😂

Collapse
 
jimbolino profile image
Jimbolino

I once "participated" in a photo contest where you could vote for the winner. The voting url didn't have CSRF protection and you could place your vote with a GET request.

I changed my avatar on all my forum accounts to a php script that redirected to that url on the first hit. Second hit it would show my normal avatar.

I got second place. Probably someone else figured out the same trick haha

Collapse
 
cmelgarejo profile image
Christian Melgarejo • Edited

Hah! This one makes you think, and, listen to the client what they want first and always get feedback before starting to code. But yeah you got with something you can plug in to the YouTubers maybe? A chrome extension for them? 😁

Collapse
 
mdhesari profile image
Mohammad Fazel

Nice try buddy :))

Collapse
 
tonnoz profile image
tonnoz

kudos for the post title, got me reading it! Also the script is somewhat useful.

Collapse
 
asimdahall profile image
Asim Dahal

I laughed so hard at this. 😂