Yohan Chalier Projects Portfolio Blog

Custom YouTube and Twitch Web Client


A Django Application called 'Notifpy'

Motivations

One goal of mine is to get rid of my Google account. I orginally developped a small Python program to get rid of the YouTube service. The program became a web application for easier use, and I added support for Twitch later on, when it became more reliable. Basically, this application allows for browsing and watching those platforms without the need of beeing logged in to an account, thus making user's habits tracking harder. The major drawback of using YouTube or Twitch without an account (or at least, without beeing logged in to it), is the loss of the subscription system, which allows for keeping track of recently published content, or in Twitch case, active users. This is what the application alleviates.

Software Solution

The application uses both YouTube and Twicth APIs to stand in for the natives subscriptions (or follows) systems of those platforms. For YouTube, a pool of channels is regularly checked for new videos, in which case it adds them to the database. For Twitch, a pool of users are checked for active livestreams whenever the user request it, to avoid missing out on recently started streams.

It is developped as a Django application. Backend API client in Python is really easy to write, the trickiest part being the implementation of the OAuth authentication flow, at least if you are doing it yourself. To regulary check for new YouTube videos, I use a simple cron task, triggering a manage.py command.

A YouTube account also provides a playlist feature. This is also implemented in Notifpy, thanks to a YouTube not so known URL, working for sets of maximum 50 videos:

/watch_videos?video_ids=id1,id2,id3,...

One major limit of the application is the API query limit. Above a given amount of queries, the application can be blocked and no longer fullfill its duties. Quotas are bound to the API keys currently used by the application. Fortunatly, those quotas are high enough for a small scale use (a couple hundred channels). Twitch offers much more than needed. YouTube, if queried correctly, is also usable. By "queried correctly", I mean using the "Uploads from" automated playlist to check for recent uploads, instead of the Search API. If UCobImwbck8ekvv63s0vxuGw is the channel id, then its uploads playlist has id UUobImwbck8ekvv63s0vxuGw, replacing the starting UC for UU (which stands for, I guess, "Channel" and "Uploads"?).

Having its own client also allows for some customization and addition of small features. One of them is the ability to use a whitelist of regular expressions on a YouTube channel to select only certain videos. For high productivity channels (such as media replay), this avoids flooding the subscription page.

Additionnal Help

Another thing not accessible without an account is maintaining account settings, such as setting the Dark theme for YouTube. This can be remembered by the cookies, but if you use the wipe everything on closure option of your browser, then darkness remains inaccessible (on a side note, wiping out cookies also deletes the local history and recommandation settings YouTube stores about you, which could be good to delete). One browser extension exists for that: Automatic Dark Theme For Youtube (I use it on Firefox).

Finally, one Android app recommandation: YouTube Vanced. It prevents ads from showing up, allows lockscreen play back, etc. You will need to clear the cache to prevent recommandations. Associate all YouTube links opened in the browser with this app, and enjoy!

Future Work

The gathered YouTube data is stored in a SQLite database. Little by little, it builds a dataset of YouTube videos and channels. Such dataset could be used for some forensics on published YouTube videos, maybe leading to the prediction of when a given channel is likely to publish its next video. Such smart targeting of the upload datetime could help reduce the charge on the API quotas.

Finally, the one big issue that remains, regarding the initial motivation, is that an API key belonging to an account, YouTube and Twitch can still sort of know what you are looking at (or at least, what are your areas of interest). One way to tackle this, which would also help for the quotas issue, is the collaborative use of a set of API keys, randomly swapped for each request. With a large enough group of keys, it becomes much harder to identify who is watching what and when.