From b405f054ee49c8e67399f8d69cd0aa4ebb8a69dd Mon Sep 17 00:00:00 2001 From: Jens <69081683+jenslys@users.noreply.github.com> Date: Thu, 2 Nov 2023 21:27:20 +0100 Subject: [PATCH] Kick.com support (#80) --- AutoVOD.sh | 16 ++++++++-------- Dockerfile | 18 ++++++++++++------ README.md | 34 ++++++++++++++++++++++++++-------- default.config | 3 +++ install.sh | 14 ++++++++++++++ 5 files changed, 63 insertions(+), 22 deletions(-) diff --git a/AutoVOD.sh b/AutoVOD.sh index 9d75ecb..a49afec 100644 --- a/AutoVOD.sh +++ b/AutoVOD.sh @@ -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 @@ -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") @@ -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) @@ -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" @@ -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" @@ -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 diff --git a/Dockerfile b/Dockerfile index 82bf8b0..2244c78 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index a1bb4cf..54ca67d 100644 --- a/README.md +++ b/README.md @@ -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.
+This script automates downloading and uploading [Twitch.TV](https://twitch.tv) or [Kick.com](https://kick.com) streams to a selected upload provider.
> **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: @@ -100,6 +98,23 @@ apt-get install ffmpeg +#### Kick Plugin + +If you want to use kick.com as your source + +
+Instructions +
+ +```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" +``` + +
+ + #### AutoVOD ```bash @@ -208,6 +223,8 @@ nano StreamerNameHere.config
Stream metadata +**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.
@@ -215,7 +232,8 @@ If you want to add stream metadata to your video, you will need to deploy an api
Disable ads -##### 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. @@ -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 pm2 save ``` @@ -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= -t autovod . +docker build --build-arg USERNAME= -t autovod . ``` You can now run this container ```bash -docker run -d autovod +docker run -d autovod ``` ## FAQ diff --git a/default.config b/default.config index a79884d..feb5989 100644 --- a/default.config +++ b/default.config @@ -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 diff --git a/install.sh b/install.sh index 7ddaeed..676267d 100755 --- a/install.sh +++ b/install.sh @@ -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