Automating Content Creation with Python: A Guide to Building a Twitch Highlights Bot
Tags: python, api, showdev, tutorial
Published: 2023-01-25 18:51:17

## Introduction

### Motivation

A few months ago, I came across a [post](https://dev.to/joaomaranhao/how-i-used-python-to-automate-a-youtube-channel-ph0) by [@joaomaranhao](https://dev.to/joaomaranhao) here on dev.to. He described how he used Python to automate a Youtube channel. His project inspired me to start my project to automate a YouTube channel, focusing on different kinds of content and utilizing other methods to obtain and edit videos.

### The Project

You probably know what Twitch is, but in case you don't know, Twitch is a live streaming platform that is used for streaming games. Still, it includes various content, such as music, art, talk shows, and even [software development](https://www.twitch.tv/directory/game/Software%20and%20Game%20Development).

One of the features available on Twitch is the ability for viewers to make video clips from live streams. By clicking on a button on the bottom right corner of the video player, users can create a video clip by selecting a 5 to 60 seconds segment of the last couple minutes of a live stream. Then they can share it with other people. Video clips are often created so people can share funny and unique moments with others.

Many Youtube channels post compilations of clips from [Twitch](https://www.twitch.tv). You can watch the video below as an example.

{% youtube Wylg3qd2P4U %}

My project does that. It gets the most watched clips of the week for a particular game, combines them into a video compilation, and then uploads the final product to Youtube with auto-generated titles, descriptions, tags, and thumbnails.

### Technologies Used

* [Python](https://www.python.org/) - The primary programming language for the bot as it provides a lot of libraries that can be used to interact with different platforms and APIs, process data, and build efficient scripts. In this project, I used version 3.11, but some earlier versions should work.
* [Twitch API](https://dev.twitch.tv/docs/api/) - The Twitch API allows developers to access and interact with the Twitch platform. The bot uses the Twitch API to search for and retrieve the most watched clips from Twitch.
* [MoviePy](https://zulko.github.io/moviepy/) - A Python library used for video editing. The bot is using this library to create the video compilation by merging the clips obtained from Twitch.
* [Pillow](https://pillow.readthedocs.io/en/stable/) - A Python library that allows for image processing. It is being used to handle image processing tasks, such as creating thumbnails and title overlays.
* [Youtube API](https://developers.google.com/youtube)/ [Google Cloud](https://cloud.google.com/) - The YouTube API is a specific API that allows developers to interact with YouTube. Google Cloud refers to the broader suite of cloud computing services offered by Google. The bot is using the YouTube API to upload the final video compilation to YouTube. One must set up a Google Cloud project to use the Youtube API.

### Check the other parts

This article will be divided into several sections to provide a comprehensive guide to how I developed this bot. You can check the second part, which will delve into how to use the Twitch API to get information on the most popular clips and download them [here](https://dev.to/viniciusenari/automating-content-creation-with-python-a-guide-to-building-a-twitch-highlights-bot-part-2-2n1b).

### Github Repository and Youtube Channel
If you want to check the source code or look at the Youtube channel I created to test it, here are the links:
* GitHub Repository: [github.com/viniciusenari/twitch-highlights-bot](https://github.com/viniciusenari/twitch-highlights-bot)
* YouTube Channel: [youtube.com/@mostwatchedtwitchclips](https://www.youtube.com/@mostwatchedtwitchclips)