Automatically make video compilations of the most viewed Twitch clips and upload them to YouTube using Python 3.
Download the repo as ZIP and unzip it somewhere accessible.
To install all the packages needed you need to run this command (has to be in the right directory).
pip install -r requirements.txt
Go to https://dev.twitch.tv/console and register a new application.
The name of the application does not matter. Set "OAuth Redirect URLs" to https://twitchapps.com/tokengen/
Set category to "Application Integration" or "Other".
You will now see your Client ID, copy this ID.
Go to config.py
, find CLIENT_ID and paste it inside apostrophes.
Now head over to https://twitchapps.com/tokengen/ and paste in your Client ID.
Scopes does not matter in our case. Click "Connect" and then authorize with Twitch.
Copy your OAuth Token, go to config.py
, find OAUTH_TOKEN
and paste it inside the apostrophes.
Go to https://console.cloud.google.com/ and create a new project. Name does not matter.
Click on the menu on the left side of your screen and navigate to "APIs & Services". Hover over this button and click "Library". Search for "YouTube Data API v3" and click the first result. Enable this API.
When you have clicked "Enable" you should now be under the "Overview" tab.
Click "Credentials" and then "+ Create Credentials".
You will now see 3 options, click "OAuth client ID".
Now you might need to configure consent screen.
If you need to configure this, click "External" and then "Create".
Write something in the application name field, might be wise to name it something you will remember like "twitchtube" or
"YouTube Twitch Bot".
Now you will see your application, go to "Credentials" again and click "+ Create Credentials" and then "OAuth client ID".
Set application type to Desktop app and name it whatever.
Click "Ok", and then click the download icon.
Open the JSON file that gets downloaded, select everything in this fiel and paste it into the client_secret.json
file.
If you want to add a game/category, you simply write the name of the game how it appears on Twitch inside the GAMES
list in config.py
.
If you want to add Rust for example, GAMES
should look like this:
GAMES = ['Rust', 'Just Chatting', 'Team Fortress 2']
Last entry in the list should not have a comma.
If you only want to have 1 game/category, GAMES
should look like this:
GAMES = ['Just Chatting']
Example:
GAMES = ['Just Chatting']
TAGS = {
'Just Chatting': 'just chatting, just chatting twitch, just chatting twitch highlights'
}
DESCRIPTIONS = {
'Just Chatting': 'The most viewed Just Chatting clips today.\n\n{}\n#Twitch #TwitchHighlights #Just Chatting'
}
Counter-Strike: Global Offensive is currently not supported since folders can't include colons in their folder name.
The script starts off by checking every game listed in the config. It will then create a folder with
the current date as folder name and inside this folder, it will create another folder for the
with the current game as folder name. It will send a request to Twitch's Kraken API
and ask for the top 100 clips. It will then save this data in a JSON
file called clips.json
. It will loop through the clip URLs and download each clip
till it reaches the limit specifed in the config. When the limit is reached, which means the video is
long enough it will take all the mp4 files in the game folder and doncatenete these clips into one
video (if specified). If time limit given is too big, it will just continue anyways. When the video is
done rendering, it will upload it to YouTube (if specified). When the video is uploaded it will delete
the clips (if specified) and create a new folder for the next game in the GAMES
list (if any) and
redo the process written above.
To run the script run this command (must be in the correct folder).
python main.py
Here is an example of how the videos look like on YouTube. Majority of these videos are made using this repo. Only a couple of titles and thumbnails have been changed.
I've only tested this script using Python 3.7.3, but should work with later versions.
MIT License
Copyright (c) 2020 offish
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.