Skip to content

Commit

Permalink
Kick.com support (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
jenslys committed Nov 2, 2023
1 parent 1d51cf7 commit b405f05
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 22 deletions.
16 changes: 8 additions & 8 deletions AutoVOD.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ while true; do
done

fetchMetadata() {
#? Fetching stream metadata
#? Fetching stream metadata (Only for twitch atm)
# Using my own API to wrap around twitch's API to fetch additional stream metadata.
# Src code for this: https://github.com/jenslys/twitch-api-wrapper

Expand Down Expand Up @@ -145,7 +145,7 @@ while true; do

STREAMLINK_OPTIONS="$STREAMLINK_QUALITY --hls-duration $VIDEO_DURATION -O --loglevel $STREAMLINK_LOGS" # https://streamlink.github.io/cli.html#twitch

echo "$($CC) Checking twitch.tv/""$STREAMER_NAME" "for a stream"
echo "$($CC) Checking $STREAM_SOURCE/""$STREAMER_NAME" "for a stream"

case "$UPLOAD_SERVICE" in
"youtube")
Expand All @@ -163,7 +163,7 @@ while true; do
echo '{"title":"'"$VIDEO_TITLE"'","privacyStatus":"'"$VIDEO_VISIBILITY"'","description":"'"$VIDEO_DESCRIPTION"'","playlistTitles":["'"${VIDEO_PLAYLIST}"'"]}' >/tmp/input.$STREAMER_NAME

# Pass the stream from streamlink to youtubeuploader and then send the file to the void (dev/null)
if ! streamlink twitch.tv/$STREAMER_NAME $STREAMLINK_OPTIONS "${STREAMLINK_FLAGS[@]}" | youtubeuploader -metaJSON /tmp/input.$STREAMER_NAME -filename - >/dev/null 2>&1; then
if ! streamlink $STREAM_SOURCE/$STREAMER_NAME $STREAMLINK_OPTIONS "${STREAMLINK_FLAGS[@]}" | youtubeuploader -metaJSON /tmp/input.$STREAMER_NAME -filename - >/dev/null 2>&1; then
echo "$($CC) youtubeuploader failed uploading the stream"
else # If the upload was successful
TIME_DATE_CHECK=$($TIME_DATE)
Expand All @@ -187,14 +187,14 @@ while true; do
# https://ffmpeg.org/ffmpeg.html

echo "$($CC) Re-encoding stream"
if ! streamlink twitch.tv/$STREAMER_NAME $STREAMLINK_OPTIONS "${STREAMLINK_FLAGS[@]}" --stdout | ffmpeg -i pipe:0 -c:v $RE_ENCODE_CODEC -crf $RE_ENCODE_CRF -preset $RE_ECODE_PRESET -hide_banner -loglevel $RE_ENCODE_LOG -f matroska $TEMP_FILE >/dev/null 2>&1; then
if ! streamlink $STREAM_SOURCE/$STREAMER_NAME $STREAMLINK_OPTIONS "${STREAMLINK_FLAGS[@]}" --stdout | ffmpeg -i pipe:0 -c:v $RE_ENCODE_CODEC -crf $RE_ENCODE_CRF -preset $RE_ECODE_PRESET -hide_banner -loglevel $RE_ENCODE_LOG -f matroska $TEMP_FILE >/dev/null 2>&1; then
echo "$($CC) ffmpeg failed re-encoding the stream"
else
echo "$($CC) Stream re-encoded as $TEMP_FILE"
fi
else
# Saves the file to disc to i can be later be uploaded by rclone
if ! streamlink twitch.tv/$STREAMER_NAME $STREAMLINK_OPTIONS "${STREAMLINK_FLAGS[@]}" -o - >$TEMP_FILE; then
if ! streamlink $STREAM_SOURCE/$STREAMER_NAME $STREAMLINK_OPTIONS "${STREAMLINK_FLAGS[@]}" -o - >$TEMP_FILE; then
echo "$($CC) streamlink failed saving the stream to disk"
else # If the stream was saved to disc
echo "$($CC) Stream saved to disk as $TEMP_FILE"
Expand Down Expand Up @@ -222,7 +222,7 @@ while true; do
# to a twitch.tv channel using RTMPS. The stream is re-muxed to a format
# that is compatible with RTMPS. The stream is also re-encoded to a
# format that is compatible with RTMPS.
if ! streamlink twitch.tv/$STREAMER_NAME $STREAMLINK_OPTIONS "${STREAMLINK_FLAGS[@]}" -O 2>/dev/null | ffmpeg -re -i - -ar $AUDIO_BITRATE -acodec $AUDIO_CODEC -vcodec copy -f $FILE_FORMAT "$RTMPS_URL""$RTMPS_STREAM_KEY" >/dev/null 2>&1; then
if ! streamlink $STREAM_SOURCE/$STREAMER_NAME $STREAMLINK_OPTIONS "${STREAMLINK_FLAGS[@]}" -O 2>/dev/null | ffmpeg -re -i - -ar $AUDIO_BITRATE -acodec $AUDIO_CODEC -vcodec copy -f $FILE_FORMAT "$RTMPS_URL""$RTMPS_STREAM_KEY" >/dev/null 2>&1; then
echo "$($CC) ffmpeg failed re-streaming the stream"
else # If the stream was re-streamed
echo "$($CC) Stream re-streamed to $RTMPS_CHANNEL"
Expand All @@ -233,14 +233,14 @@ while true; do
"local")
if [ "$RE_ENCODE" == "true" ]; then
echo "$($CC) Re-encoding stream"
if ! streamlink twitch.tv/$STREAMER_NAME $STREAMLINK_OPTIONS "${STREAMLINK_FLAGS[@]}" --stdout | ffmpeg -i pipe:0 -c:v $RE_ENCODE_CODEC -crf $RE_ENCODE_CRF -preset $RE_ECODE_PRESET -hide_banner -loglevel $RE_ENCODE_LOG -f matroska $LOCAL_FILENAME >/dev/null 2>&1; then
if ! streamlink $STREAM_SOURCE/$STREAMER_NAME $STREAMLINK_OPTIONS "${STREAMLINK_FLAGS[@]}" --stdout | ffmpeg -i pipe:0 -c:v $RE_ENCODE_CODEC -crf $RE_ENCODE_CRF -preset $RE_ECODE_PRESET -hide_banner -loglevel $RE_ENCODE_LOG -f matroska $LOCAL_FILENAME >/dev/null 2>&1; then
echo "$($CC) ffmpeg failed re-encoding the stream"
else # If the stream was re-encoded
echo "$($CC) Stream re-encoded as $LOCAL_FILENAME"
fi
else
# If you just want to save the stream locally to your machine
if ! streamlink twitch.tv/$STREAMER_NAME $STREAMLINK_OPTIONS "${STREAMLINK_FLAGS[@]}" -o - >"$LOCAL_FILENAME.$LOCAL_EXTENSION"; then
if ! streamlink $STREAM_SOURCE/$STREAMER_NAME $STREAMLINK_OPTIONS "${STREAMLINK_FLAGS[@]}" -o - >"$LOCAL_FILENAME.$LOCAL_EXTENSION"; then
echo "$($CC) streamlink failed saving the stream to disk"
if [ "$SAVE_ON_FAIL" == "true" ]; then
#? Save the temp file if rclone fails
Expand Down
18 changes: 12 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ FROM alpine:3.17
ARG TWITCH_USER

#* Upgrade the system and install dependencies
RUN apk add --no-cache --upgrade python3 tar wget bash jq rclone curl
RUN python3 -m ensurepip
RUN pip3 install --upgrade streamlink
RUN wget --progress=dot:giga https://github.com/porjo/youtubeuploader/releases/download/23.03/youtubeuploader_23.03_Linux_x86_64.tar.gz
RUN tar -xvf youtubeuploader_23.03_Linux_x86_64.tar.gz && rm youtubeuploader_23.03_Linux_x86_64.tar.gz &&\
mv youtubeuploader /usr/local/bin/youtubeuploader
RUN apk add --no-cache --upgrade python3 tar wget bash jq rclone curl \
&& python3 -m ensurepip \
&& pip3 install --no-cache-dir --upgrade streamlink cloudscraper

#* Install streamlink plugins
RUN wget --progress=dot:giga -O "/usr/lib/python3.10/site-packages/streamlink/plugins/kick.py" "https://raw.githubusercontent.com/nonvegan/streamlink-plugin-kick/master/kick.py"

#* Install youtubeuploader
RUN wget --progress=dot:giga https://github.com/porjo/youtubeuploader/releases/download/23.03/youtubeuploader_23.03_Linux_x86_64.tar.gz \
&& tar -xvf youtubeuploader_23.03_Linux_x86_64.tar.gz \
&& rm youtubeuploader_23.03_Linux_x86_64.tar.gz \
&& mv youtubeuploader /usr/local/bin/youtubeuploader

#* Copy the required files
COPY ${TWITCH_USER}.config /autoVOD/${TWITCH_USER}.config
Expand Down
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
![AutoVOD Icon](https://cdn.lystad.io/autovod_icon.png)

# AutoVOD

![Releases](https://img.shields.io/github/v/release/jenslys/AutoVOD.svg)

This script automates downloading and uploading [Twitch.TV](https://twitch.tv) streams to a selected upload provider. <br>
This script automates downloading and uploading [Twitch.TV](https://twitch.tv) or [Kick.com](https://kick.com) streams to a selected upload provider. <br>

> **Note**
> This does not download and upload the **official Twitch VOD** after the stream is finished, but rather uses [streamlink](https://streamlink.github.io/) to record and upload the stream in realtime. So features like [separating different audio track for the VOD](https://help.twitch.tv/s/article/soundtrack-audio-configuration?language=en_US) are not supported. If that is something you are looking for, you should check out [Twitch's manual export to YouTube feature](https://help.twitch.tv/s/article/video-on-demand?language=en_US#:~:text=your%20Video%20Producer.-,Export,-Your%20Twitch%20account).
> This does not download and upload the **official Twitch/Kick VOD** after the stream is finished, but rather uses [streamlink](https://streamlink.github.io/) to record and upload the stream in realtime. So features like [separating different audio track for the VOD](https://help.twitch.tv/s/article/soundtrack-audio-configuration?language=en_US) are not supported. If that is something you are looking for, you should check out [Twitch's manual export to YouTube feature](https://help.twitch.tv/s/article/video-on-demand?language=en_US#:~:text=your%20Video%20Producer.-,Export,-Your%20Twitch%20account).
Current available upload options:

Expand Down Expand Up @@ -100,6 +98,23 @@ apt-get install ffmpeg

</details>

#### Kick Plugin

If you want to use kick.com as your source

<details>
<summary>Instructions</summary>
<br>

```bash
STREAMLINK_LOCATION=$(pip3 show streamlink | grep -E '^Location:' | awk '{print $2}') &&
PLUGINS_DIR="${STREAMLINK_LOCATION}/streamlink/plugins" &&
wget --progress=dot:giga -O "${PLUGINS_DIR}/kick.py" "https://raw.githubusercontent.com/nonvegan/streamlink-plugin-kick/master/kick.py"
```

</details>


#### AutoVOD

```bash
Expand Down Expand Up @@ -208,14 +223,17 @@ nano StreamerNameHere.config
<details>
<summary>Stream metadata</summary>
**This currently only works if you are using Twitch.TV**
If you want to add stream metadata to your video, you will need to deploy an api wrapper for the Twitch API. You can find the instructions on how to do that [here](https://github.com/jenslys/twitch-api-wrapper). Once you have the wrapper deployed, you will need to add the url in the API_URL field in the config file and enable the API_CALLS field.
</details>
<details>
<summary>Disable ads</summary>
##### Fetching the OAuth token from Twitch
##### Fetching the OAuth token from
Follow the instructions [here](https://streamlink.github.io/cli/plugins/twitch.html#authentication) to get your OAuth token.
Then add the OAuth token: `--twitch-api-header=Authorization=OAuth YOURCODEHERE` to the `STREAMLINK_OPTIONS` field in the config file.
Expand All @@ -228,7 +246,7 @@ Other options can be found [here](https://streamlink.github.io/cli.html#twitch)
### Start AutoVOD
```bash
pm2 start AutoVOD.sh --name StreamerNameHere
pm2 start AutoVOD.sh --name <Streamer Name Here>
pm2 save
```
Expand All @@ -249,13 +267,13 @@ pm2 logs
This script can be used inside a docker container. To build a container, first execute all [Setup-Steps](#setup), then build the image:
```bash
docker build --build-arg TWITCH_USER=<your twitch username> -t autovod .
docker build --build-arg USERNAME=<Streamer Name Here> -t autovod .
```
You can now run this container
```bash
docker run -d autovod <your twitch username>
docker run -d autovod <Streamer Name Here>
```
## FAQ
Expand Down
3 changes: 3 additions & 0 deletions default.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#! Do not edit this file directly, instead create a new file with the name of the streamer you want to record. (e.g: asmongold.config)
set -a

#* Source
STREAM_SOURCE="twitch.tv" #* Options: twitch.tv, kick.com

#* Upload provider
UPLOAD_SERVICE="youtube" #* Options: youtube, rclone, restream, local

Expand Down
14 changes: 14 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ else
printf "${g}[$now] Skipping Rclone installation...${c}\n"
fi

printf "${g}[$now] Install Kick Plugin [Y/N]? ${c}\n"
read -r answer
if [ "$answer" = "Y" ]; then
if ! [ -x "$(command -v streamlink)" ]; then
printf "${g}[$now] Streamlink is missing. Skipping...${c}\n"
else
STREAMLINK_LOCATION=$(pip3 show streamlink | grep -E '^Location:' | awk '{print $2}') &&
PLUGINS_DIR="${STREAMLINK_LOCATION}/streamlink/plugins" &&
wget --progress=dot:giga -O "${PLUGINS_DIR}/kick.py" "https://raw.githubusercontent.com/nonvegan/streamlink-plugin-kick/master/kick.py"
fi
else
printf "${g}[$now] Skipping Kick Plugin installation...${c}\n"
fi

printf "${g}[$now] Installing AutoVOD${c}\n"
if [ ! -d "./autovod" ]; then
git clone https://github.com/jenslys/autovod.git && cd autovod || exit
Expand Down

0 comments on commit b405f05

Please sign in to comment.