Skip to content

Civon/twitch-stream-recorder

 
 

Repository files navigation

Twitch Stream Recorder

This script allows you to record twitch streams live to .mp4 files.

Prerequisite

  • client_id - you can grab this from here once you register your application
  • client_secret - you generate this here as well, for your registered application
  • (Optional)twitch_oauth_token - personal OAuth token from Twitch. Check this section for details.

Bulk run using helm

# helm repo TBD
helm install twitch-stream-recorder ./helm --namespace twitch-stream-recorder-namespace

Run on Docker

Docker Compose

  1. Clone the repo.
  2. Simply copy .env.example to .env file
  3. run Docker compose up

Single container(recommend)

Create .env file from .env.example and run

podman run --name twitch-stream-recorder \
    -v <your-vod-warehouse>:/app/rec:Z \
    --env-file .env
    ghcr.io/civon/twitch-stream-recorder \
    --username myFavStreamer # You can override env by args \
    -q worst \
    --log warn

Requirements

  1. python3.8 or higher
  2. streamlink
  3. ffmpeg

Setting up

  1. Check if you have latest version of streamlink:

    • streamlink --version shows current version
    • streamlink --version-check shows available upgrade
    • sudo pip install --upgrade streamlink do upgrade
  2. Install requests module if you don't have it

    • Windows: python -m pip install requests
    • Linux: python3.8 -m pip install requests
  3. Create config.py file in the same directory as twitch-recorder.py with:

root_path = "/home/abathur/Videos/twitch"
username = "forsen"
client_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
client_secret = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
twitch_oauth_token = "" # Optional

root_path - path to a folder where you want your VODs to be saved to
username - name of the streamer you want to record by default
client_id - you can grab this from here once you register your application
client_secret - you generate this here as well, for your registered application twitch_oauth_token - personal OAuth token from Twitch (Optional)

  1. (Optional) Modify .streamlinkrc base on https://streamlink.github.io/cli.html

How to get Twitch OAuth Token

Check this document for details.

After login Twitch on web browser, open Developer console. And paste Javascript code below to "Console" tab and press enter.

document.cookie.split("; ").find(item=>item.startsWith("auth-token="))?.split("=")[1]

Running script

The script will be logging to a console and to a file twitch-recorder.log

On linux

Run the script

python3.8 twitch-recorder.py

To record a specific streamer use -u or --username

python3.8 twitch-recorder.py --username forsen

To specify quality use -q or --quality

python3.8 twitch-recorder.py --quality 720p

To change default logging use -l, --log or --logging

python3.8 twitch-recorder.py --log warn

To disable ffmpeg processing (fixing errors in recorded file) use --disable-ffmpeg

python3.8 twitch-recorder.py --disable-ffmpeg

If you want to run the script as a job in the background and be able to close the terminal:

nohup python3.8 twitch-recorder.py >/dev/null 2>&1 &

In order to kill the job, you first list them all:

jobs

The output should show something like this:

[1]+  Running                 nohup python3.8 twitch-recorder > /dev/null 2>&1 &

And now you can just kill the job:

kill %1

On Windows

You can run the scipt from cmd or terminal, by simply going to the directory where the script is located at and using command:

python twitch-recorder.py

The optional parameters should work exactly the same as on Linux.

Credits

  • @junian
  • @Ancalentari
  • @AntonioMIN
  • @jim60105

About

Record twitch streams live!

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • Python 85.9%
  • Smarty 8.3%
  • Dockerfile 5.8%