Twitch // SMM's Tutorial, by Davide Casano (X81000862)

twitch_logo.png

Introduction:

What is Twitch? Why should we analyze this platform?

Twitch.tv is a livestream platform where people have the chance to discover different types of topics. Founded in 2011 and now owned by Amazon.com, Inc. it is mainly used to entertain and divulge digital content that can be viewed either live or on demand. With an average of 26.5 million daily visitors (2020, Twitch), Twitch is a web service and a global community where users have the opportunity to learn new skills, discover new artists, spend free time and more.

Some stats:

API Access:

Registration, API Key, API Secret:

  1. Firstly, click on the specific link. Then, on the voice "Login with Twitch".

    link: https://dev.twitch.tv/login 1.png

  1. Secondly, log in.

    2.png

    NB: The 1st and 2nd step can be reversed. If you are already logged in, you can ignore this (2nd) step.

  1. Thirdly, read and agree the Twitch Developer Services Agreement. Then, click below on the voice "Autorize".

    3.png

  1. Now, this is what should come out:

    4.png

  1. To create the Application, click (below "Console") on "Applications". Then, on the right, on the voice "Register Your Application".

    5.png

  1. Fill the required information and click below on the voice "Create".

    6.png

  1. Now, the Application is created. In order to get the Application's Client ID and Client Secret, click on the voice "Manage".

    7.png

  1. Here there are the API Key and the API Secret:

    NB: this information must be kept and not shared with anyone.

API REST:

Usage, description and examples:

REpresentational State Transfer (REST) refers to a group of software architecture design constraints that bring about efficient, reliable, and scalable distributed systems. A system is called RESTful when it adheres to those constraints.
To access certain data about users’ accounts we have to choose one specific authentication method: OAuth. We use some parts of the OAuth 2.0 protocol.

Authentication involves:

  1. Registering your app to obtain a client ID and client secret.
  2. Getting a token. It includes permissions that your app requires.
  3. Sending the token in your API request to authenticate API requests.

Notes:

Considered that the 1st point is already completed, let's complete the 2nd and the 3rd points: getting the token and sending the token in your API request.

We got the access token. Let's make a couple of examples using Twitch's REST API:

Third-party API:

Usage, description and examples:

A wrapper function is a subroutine (another word for a function) in a software library whose main purpose is to call a second subroutine or a system call with little or no additional computation. Wrapper functions are used to make writing computer programs easier by abstracting away the details of a subroutine's underlying implementation.
TwitchAPI is a full implementation of the Twitch API, its Webhook and PubSub in Python 3.7.

twitchAPI.png

To see the full official documentation click here.

It is very simple to install that using pip:

To see how wrappers increase readability and clarity of the code, relook:

  1. Authentication and how to get the access token.
  2. The 2nd example made.

We can also display this ranking in a different way, with pandas library:

Having realized that libraries facilitate the development of the code, we are now ready to analyze some data.

Data Analysis:

Extracting data from the social media:

Using APIs to extract data from social media, as we know, is very efficient. As for the Twitch platform, for instance, an application could concern the prediction of which categories are mostly viewed, starting from a streamer. For this purpose, we are going to use two Python packages greatly useful for the web scraping's context: BeautifulSoup and Selenium. How can we do this? Let's take a look:

Let's get all the archive of a streamer, with his video IDs:

Now it is time to estimate and plot:

Create a simple Python function using regex to convert category durations in minutes, in order to compare the same measures:

Update our "total" dataframe calculating which is the main category of a stream:

Once extracted the main categories and filled every i-th row and column, let's print the "top 3 popular categories" of "Enkk" streamer:

Plotting the prediction using a pie chart:

Conclusion:

As we can see with this extraction, we have understood:

It is nice to see, with this simple prediction, how categories influence a streamer's stream. Indeed, it is also important to keep in mind that Twitch's audience is large and, with a great probability, a general user follows a stream because the category works with him.

With this data it is possible to carry out a multitude of operations: this data extraction has the aim of categorizing and answering in a pragmatic way the simple question "which is the most popular category of a streamer?".