License - Apache License 2.0
- Tested on Ubuntu Server:
24.04. - Version:
1.1.0. - Blog post/Read more: https://ryanfitton.co.uk/blog/livestream-youtube-scheduler/
Docker: Used to run the go2rtc container. Tested onDocker version 27.5.1, build a187fa5.jq: Parses JSON output from curl responses.curl: For sending HTTP requests to the YouTube API.bash: Ensure the script runs in Bash (not sh or dash).crontab: For scheduling stream start via cron.date: GNU date with --iso-8601 support (already present on most Linux distros)- You must have your YouTube account API v3 Client ID, Client Secret and Refresh Token for use in
config.sh.
Note the files in this repo expects your current user to have their home folder at /home/user. If this is incorrect, do a find and replace on this value accross all of these files.
- Pull down the latest Go2RTC Docker image:
sudo docker pull alexxit/go2rtc
- Create a config folder in your user's home folder (assuming
/home/user):
mkdir ~/config
Alternatively you may be able to Git clone this repo: git clone git@github.com:ryanfitton/livestream-youtube-scheduler.git into your home folder.
- Now create a
config.shfile in this folder:
nano ~/config/config.sh
Upload the content's of config.sh from this repo into this file. This file will hold your config for YouTube API keys, and livestream feed schedules.
- Now create a config folder to hold the stream config details for Go2RTC:
mkdir ~/config/go2rtc
And a go2rtc.yaml file:
nano ~/config/go2rtc/go2rtc.yaml
Upload the content's of go2rtc.yaml from this repo into this file.
- Now create a
livestream-youtube-scheduler.shfile in the home folder:
nano ~/livestream-youtube-scheduler.sh
Upload the content's of livestream-youtube-scheduler.sh from this repo into this file.
And make this file executable: chmod +x livestream-youtube-scheduler.sh.
- Now create a
scheduler-wrapper.shfile in the home folder:
nano ~/scheduler-wrapper.sh
Upload the content's of scheduler-wrapper.sh from this repo into this file.
And make this file executable: chmod +x scheduler-wrapper.sh.
- Now schedule your cronjobs as Sudo:
sudo crontab -e
You can use this as an example:
0 1 * * * /bin/bash /home/user/scheduler-wrapper.sh
This will run the scheduler at 01:00am each day, and will schedule livestreams of those specified in config.sh.
- Firstly ensure your livestream sources are specified in
go2rtc.yaml. - Then setup your schedules in
config.sh:
Example:
stream1=(
"STREAM=birdcam"
"TIMEZONE=Europe/London"
"VISIBILITY=private"
"TODAY=$(date +"%Y-%m-%d")"
"TITLE='Bird camera live feed for $(date +"%A %d %B")'"
"DESC='Bird camera live feed for $(date +"%A %d %B"). Streamed 11:00 to 15:30'"
"THUMBNAIL='/home/user/config/youtube_thumbnail_1280x720.png'"
"START=$(date +%Y-%m-%d)T11:00:00"
"END=$(date +%Y-%m-%d)T15:30:00"
)
This example will:
"STREAM=birdcam": This is the stream name defined in thegot2rtc.yamlconfig."TIMEZONE=Europe/London": The timezone for the start/end date/time."VISIBILITY=private": The visibility for this livestream, use either:unlisted,publicorprivate."TITLE='Bird camera live feed for $(date +"%A %d %B")'": The name used in YouTube for this stream."DESC='Bird camera live feed for $(date +"%A %d %B"). Streamed 11:00 to 15:30'": The description used in YouTube for this stream."THUMBNAIL='/home/user/config/youtube_thumbnail_1280x720.png'": The thumbnail to be used for the stream. Ideally should be 1280×720px."START=$(date +%Y-%m-%d)T11:00:00": The start date/time in ISO format for the stream, todays's date at '11:00 am'"END=$(date +%Y-%m-%d)T15:30:00": The end date/time in ISO format for the stream, todays's date at '15:30 am'
-
Create a Google Cloud Project
- Go to Google Cloud Console.
- Click the project dropdown in the top menu and select "New Project".
- Give your project a name and click Create.
-
Enable the YouTube Data API v3
- In the Google Cloud Console, select your project.
- Navigate to APIs & Services > Library.
- Search for YouTube Data API v3.
- Click it and then click Enable.
-
Create OAuth 2.0 Credentials
- Go to APIs & Services > Credentials.
- Click Create Credentials > OAuth Client ID.
- Choose:
- Application Type:
Desktop App(orWeb Applicationif applicable).
- Application Type:
- Click Create.
- Copy your:
- Client ID
- Client Secret
-
Get a Refresh Token via OAuth 2.0 Playground
- Open OAuth 2.0 Playground
- Click the gear icon (⚙️) in the top right:
- Check "Use your own OAuth credentials"
- Paste your Client ID and Client Secret
- In Step 1:
- Scroll down to YouTube Data API v3
- Select:
https://www.googleapis.com/auth/youtubehttps://www.googleapis.com/auth/youtube.force-ssl
- Click Authorize APIs
- Sign in with your Google account.
- In Step 2:
- Click Exchange authorization code for tokens
- Copy the Refresh Token (note: this is only shown once)
-
Save Your Credentials
- Save your credentials in
config.sh
- Save your credentials in