Building YouTube Trivia App

I had always wanted to build a python web-application, complete with backend and a pretty front-end. I have too many ideas that did not materialize because I did not have the time and patience to develop an interface using python libraries like tkinter or PyQt or PySimpleGUI.

But it all changed. Now, I could just imagine my front-end and prompt for a HTML+CSS code in ChatGPT or Claude (better for codes) and spend more time on back-end. It is an absolute bliss when you realize the amount of time you save, when you are building a project from scratch to live.

The Concept

I wanted to see basic stats of my favourite YouTube channel, but I couldn't get what I wanted from the hundreds of YouTube stats websites on the internet. Below are a few sites if you are interested:

Phase One: Imagining The Flow

The first thing to do was to decide on the framework and the hosting site. There were plenty of options to choose from and I decided to go with the ones that require minimal effort. I chose Flask for the web framework and pythonanywhere as my deployment destination.

Phase Two: The Coding Process

I prompted chatGPT to give me a python code that will leverage YouTube API to provide me statistics of a YouTube video. I used the code-output as my base to build around it. I could have prompted for each and every functionality that I needed, but my line of thoughts would go for a toss if I had to edit everything that ChatGPT threw at me and lose more time in that process. So, it was easier for me to quickly code what I wanted and then debug it and tune it to fit my requirements.

Since the input would be an URL of a YouTube video, I would have to fetch the video-id from the URL, then use it to get the channel-id and use the channel-id to fetch all video-ids and get statistics for both channel and videos separately. I wrote functions for each of the functionality and defined a main function that would call these functions in sequence and did some basic error-handling within the main function.

Identifying the metrics to display was also one of the steps of the coding process. The goal was to display the most popular videos in terms of views, likes and comments; but since these three values are correlated in most cases, the information would be redundant when the most viewed video is the same as most liked and commented. When I checked the likes-views ratio and comments-views ratio the results were apparently different. So, decided to show these instead.

The next step was to build a flask app that links the python analysis to the front-end html page. I used Claude to code me the entirety of HTML and CSS codes to present the statistics in a meaningful way. The idea changed each time, and the iterations were too much to keep track of. I arrived at a tolerable design to display statistics for the time being. I hope to enhance the information and final display over time.

Phase Three: The Deployment

I created an account on pythonanywhere and reviewed the documentation and tutorials on YouTube. Deploying on pythonanywhere was a breeze and much faster than I anticipated. I hope to try out other platforms for future passion projects.

Take Aways

Apart from minor hiccups during the deployment, everything else was smooth. However, the YouTube API allows only 10K requests per day and one request would fetch only 50 videos. So, running an analysis of a big YouTube channel like MKBHD who has over 1700 videos would easily exhaust half of the quota. Right now, I have coded to display a message if the application exceeds the daily quota. Will keep this post updated with new changes.