Skip to content

Commit

Permalink
Add STREAM variables (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
jenslys authored Dec 23, 2022
1 parent 8d70afe commit 3f1be9e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
client_secrets.json
request.token
.DS_Store
.DS_Store
/tests/
39 changes: 34 additions & 5 deletions AutoVOD.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,48 @@ echo "Using Twitch user: $TWITCH_USER"
echo ""
echo ""

# Every minute, try to download the Twitch stream, and send it to YouTube.
# Everything through the pipe, no video file is created.
function getStreamInfo() {
# This uses my own API wrapper for twitch that i have hosted. (https://github.com/jenslys/twitch-api-wrapper).
# i would recommend self hosting yourself with your own API credentials. but you may use the one provided below.

echo "Fetching stream metadata..."
echo ""
url="https://twitch-api-wrapper.vercel.app/info/$1"
json=$(curl -s --retry 5 --retry-delay 2 --connect-timeout 30 $url)
if [ "$json" = "Too many requests, please try again later." ]; then
echo $json
echo ""
return
fi

STREAMER_TITLE=$(echo "$json" | jq -r '.stream_title')
STREAMER_GAME=$(echo "$json" | jq -r '.stream_game')

if [ "$json" = "[]" ]; then
echo "Stream is offline, can't fetch metadata."
echo ""
else
echo "Stream is online!"
echo "Current Title: $STREAMER_TITLE"
echo "Current Game: $STREAMER_GAME"
echo ""
fi
}

while true; do
STREAMER_NAME=$TWITCH_USER #! Dont change this.
API_CALLS="false" #? Enable if you want to fetch stream metadata like the Title or Game. You can use the folowing variables with this enabled: $STREAMER_TITLE and $STREAMER_GAME.
if [[ "$API_CALLS" == "true" ]]; then #
getStreamInfo $STREAMER_NAME STREAMER_TITLE STREAMER_GAME #
fi #
TIME_DATE=[$(date +"%m.%d.%y")] # Preview example: [08.10.21]
VIDEO_VISIBILITY="unlisted" #* Options: unlisted, private, public
VIDEO_DESCRIPTION="Uploaded using https://github.com/jenslys/AutoVOD" # YouTube video description.
VIDEO_TITLE="$STREAMER_NAME - $TIME_DATE" # Title of the Youtube video.
VIDEO_DURATION="12:00:00" # XX:XX:XX (YouTube has a upload limit of 12 hours per video).
VIDEO_PLAYLIST="$STREAMER_NAME VODs" # Playlist to upload to.
SPLIT_INTO_PARTS="false" # If you want to split the video into parts, set this to true. (if this is enabled VIDEO_DURATION is ignored).
SPLIT_VIDEO_DURATION="06:00:00"
SPLIT_INTO_PARTS="false" #? If you want to split the video into parts, set this to true. (if this is enabled VIDEO_DURATION is ignored).
SPLIT_VIDEO_DURATION="06:00:00" # Duration of each part. (XX:XX:XX)

# Splitting the stream into parts (If enabled)
if [[ "$SPLIT_INTO_PARTS" == "true" ]]; then
Expand All @@ -30,7 +59,7 @@ while true; do
fi
fi

STREAMLINK_OPTIONS="best --hls-duration $VIDEO_DURATION --twitch-disable-hosting --twitch-disable-reruns -O --loglevel error" # https://streamlink.github.io/cli.html#twitch
STREAMLINK_OPTIONS="best --hls-duration $VIDEO_DURATION --twitch-disable-hosting --twitch-disable-ads --twitch-disable-reruns -O --loglevel error" # https://streamlink.github.io/cli.html#twitch

echo "Checking twitch.tv/$STREAMER_NAME for a stream."

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM alpine:3.14

# Upgrade the system and install dependencies

RUN apk add --no-cache --upgrade python3 tar wget bash
RUN apk add --no-cache --upgrade python3 tar wget bash jq
RUN python3 -m ensurepip

RUN pip3 install --upgrade streamlink
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ apt-get install python3-pip tar
pip3 install --upgrade streamlink
```

#### JQ

```bash
apt-get install jq
```

#### YouTubeUploader

```bash
wget https://github.com/porjo/youtubeuploader/releases/download/22.03/youtubeuploader_22.03_Linux_x86_64.tar.gz
tar -xvf youtubeuploader_22.03_Linux_x86_64.tar.gz && rm youtubeuploader_22.03_Linux_x86_64.tar.gz
mv youtubeuploader_22.03_Linux_x86_64 /usr/local/bin/youtubeuploader
mv youtubeuploader /usr/local/bin/youtubeuploader
```

#### AutoVOD
Expand Down Expand Up @@ -86,10 +92,10 @@ Set up your credentials to allow YouTubeUploader to upload videos to YouTube.
youtubeuploader -filename sample.mp4
```

1. and then simply copy the token file along with `youtubeuploader` and `client_secrets.json` to the remote host.
1. and then simply copy the token file along with `youtubeuploader` and `client_secrets.json` to the remote host. Make sure these are placed inside the 'autovod' folder

**Note**
To be able to upload videos as either "Unlisted or Public", you will have to request an [API audit](https://support.google.com/youtube/contact/yt_api_form) from YouTube for your project. Without an audit your videos will be locked as private.
To be able to upload videos as either "Unlisted or Public" and upload multiple videos a day, you will have to request an [API audit](https://support.google.com/youtube/contact/yt_api_form) from YouTube. Without an audit your videos will be locked as private and you are limited to how many videos you can upload before you reach a quota.

## Usage

Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ printf "${g}[$now] Updating and upgrading packages...${c}\n"
apt-get -qq update && apt-get -qq upgrade

printf "${g}[$now] Installing Packages${c}\n"
sudo apt-get install npm python3-pip tar -y
sudo apt-get install npm python3-pip tar jq -y

printf "${g}[$now] Installing PM2${c}\n"
npm install pm2 -g && pm2 startup
Expand Down

0 comments on commit 3f1be9e

Please # to comment.