You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
YouTube Live Streaming API - minimal working example #202
@Jonathan-Woo could you work on creating a minimal working example for use of the YouTube Live Streaming API? This would be standalone from the Raspberry Pi devices and manifest as two files:
Create the new stream, add it to a specified playlist, and return the stream URL and stream key
Find the latest stream that matches the piece of equipment (open to thoughts on "how")
These can get added to a separate folder within src, called yt_livestream_api
I think everything you need to get started is covered at:
Cc @Neil-YL - once we get the livestreaming API figured out, I think we'll be able to expand to ~6+ livestreams going simultaneously, relevant for other demos such as pioreactor and mycobot.
Both streaming went down during the weekend, should I restart it?
Not sure where the logs were stored when running with auto-start and if a restart will overwrite the logs or not.
Hmm.. You can use instructions in the README (some kind of journal command) to check the logs. My guess is it still restarted (and has been trying to restart), but can't until it has a new stream available, since yt shuts it down so quickly if it stops receiving data. If I set it up correctly, it's meant to only retry up to 3 times per 8 hours.
Hmm.. You can use instructions in the README (some kind of journal command) to check the logs. My guess is it still restarted (and has been trying to restart), but can't until it has a new stream available, since yt shuts it down so quickly if it stops receiving data. If I set it up correctly, it's meant to only retry up to 3 times per 8 hours.
From previous experience, YT provides quite a bit of room for the streaming device to reconnect if it receives no data. I have turned off auto-stop, so it will not end immediately.
I think I could set up a new stream but don't touch the Pi to see if the new stream can receive data.
@Jonathan-Woo could you work on creating a minimal working example for use of the YouTube Live Streaming API? This would be standalone from the Raspberry Pi devices and manifest as two files:
Create the new stream, add it to a specified playlist, and return the stream URL and stream key
Find the latest stream that matches the piece of equipment (open to thoughts on "how")
These can get added to a separate folder within src, called yt_livestream_api
I think everything you need to get started is covered at:
Given @Jonathan-Woo's constraints, @Neil-YL do you mind taking a stab at this today? (Just a minimal working example as a Python script or notebook, and if you could share the API key over slack, if applicable)
Given @Jonathan-Woo's constraints, @Neil-YL do you mind taking a stab at this today? (Just a minimal working example as a Python script or notebook, and if you could share the API key over slack, if applicable)
OAuth 2.0 is required to access all features of the YouTube Data API.
Below is a step-by-step guide on how to enable YouTube Data API, obtain API Key, configure OAuth in the Google Cloud Console and generate a token.pickle file on your local machine.
You can complete this setup using your own Google account — it doesn't have to be the same account as the YouTube channel owner (but you do need to know the owner account email).
Click the project dropdown (top left) and select "New Project".
Give the project a name (e.g., YouTube Stream) and click Create.
Enable YouTube Data API v3
In your newly created project, go to APIs & Services then Library on the left.
Search for YouTube Data API v3.
Click on it, then click Enable.
Obtain API Key
Navigate to APIs & Services > Credentials.
Create an API Key
On the list of the API Keys, select your newly created API key and click three dots under Actions > Edit API Key
Give it a preferred name and turn on API restrictions, then select YouTube Data API v3.
Note: API key will be used for public data access on YouTube, for management level features like starting stream or add video to playlist, you will need OAuth for account authentication. Continue with following steps for OAuth set up.
Configure OAuth Consent Screen
Navigate to APIs & Services > OAuth consent screen.
Fill in the following required fields:
App name: (e.g., YouTube Stream API)
User support email: your email
Audience: select External.
Contact Information: your email.
Click Continue until you reach Finish, then click Create
Create OAuth 2.0 Client
Go to Clients on the left.
Click Create Clients > OAuth client ID.
Choose Desktop App as the application type.
Give it a name (e.g., Stream Auth) and click Create.
An OAuth Client page will pop up. Click “Download JSON” and save the file as client_secrets.json.
Add Test Users
Close the OAuth Client page, in the OAuth consent screen, go to Audience on the left , scroll down to Test users.
Add the mail address of the owner account of the YouTube channel. (YouTube API can only work with the main channel under OAuth)
Generate token.pickle from OAuth JSON
After creating your OAuth 2.0 credentials in Google Cloud and downloading the client_secrets.json file, follow these steps to generate a token.pickle file for future API access.
On your local IDE (e.g., VS Code), install google-auth-oauthlib via pip:
pip install google-auth-oauthlib
Place the downloaded client_secrets.json in your working directory.
After you run the script, a browser window will open to let you sign in and authorize access, please use the same account in the previous Audience > Test users set up, not the Google Cloud Project account (if they are different).
You will see a page says "Google hasn’t verified this app". If you're testing it yourself and everything is under your control, it's safe to click Continue and proceed.
After successful login, a token.pickle file will be saved locally. This token will be used in your application to authenticate YouTube API requests without needing to re-login.
Quota on using YouTube API
The YouTube Data API uses a quota system. Projects that enable the YouTube Data API have a default quota allocation of 10,000 units per day, an amount sufficient for the majority of our API users.
I’ve tested it under the same account, but if anyone would like to follow this documentation and share feedback (in case that I missed any previous setting), it would be greatly appreciated.
Nice! Do you have a link that served as a starting point for these instructions? Also, I'm realizing we can probably port this over to the README within picam/.
Any follow-up thoughts on how to retrieve the "latest stream" from a particular playlist? Not sure what kind of metadata we can extract related to the playlists.
Nice! Do you have a link that served as a starting point for these instructions? Also, I'm realizing we can probably port this over to the README within picam/.
Any follow-up thoughts on how to retrieve the "latest stream" from a particular playlist? Not sure what kind of metadata we can extract related to the playlists.
I will get into it tomorrow as well. I believe (hopefully) it would be something with a simpler API-KEY if we would like to use it on the Hugging Face. OAuth2.0 is required to start and manage stream/video.
Technically I think we could have a separate cloud service (i.e., virtual machine) running 24/7 that monitors for when streams go down and then reinstantiates them when they do. This could handle streams across all devices, and then the devices could just worry about retrieving stream keys rather than starting streams. More from an access/security/limiting scope point of view. Thoughts?
I'm ok with sticking with having the pickle file on each streaming device.
Aside: we chatted about unique naming, and likely that we'll add something related to serial number (probably RPi, could encrypt first if we want to) to both the hostname (since it's the same tailscale) and as a way to distinguish devices on the YouTube streaming side. On our end, we decide which camera faces which equipment (which could be multiple), and we can reconfigure at will, which puts that relationship on us to track and record. YouTube limits to 5000 videos per playlist (mostly due to constraints on RAM for Chrome, etc.), which gives us ~4.5 years assuming 8 hour chunks and minimal sub-divisions of the 8 hours (i.e., no 5a, 5b - type splits due to failures).
Current example of a hostname: rpi-zero2w-a1mini-stream, which also gets a bit problematic if we want to rearrange things. However, easy mid-term solution is to append some unique ID at the end.
September 21, 2020
The definition of the liveBroadcast resource's status.madeForKids property has been updated to clarify that the property is read-only. This does not reflect a change in API functionality.
Unrelated EDIT (to avoid triggering notification): #80 (comment) has some documentation about channel setup, which we might want to incorporate into docs
Activity
sgbaird commentedon Mar 23, 2025
Cc @Neil-YL - once we get the livestreaming API figured out, I think we'll be able to expand to ~6+ livestreams going simultaneously, relevant for other demos such as pioreactor and mycobot.
Neil-YL commentedon Mar 24, 2025
Both streaming went down during the weekend, should I restart it?
Not sure where the logs were stored when running with auto-start and if a restart will overwrite the logs or not.
sgbaird commentedon Mar 24, 2025
Hmm.. You can use instructions in the README (some kind of journal command) to check the logs. My guess is it still restarted (and has been trying to restart), but can't until it has a new stream available, since yt shuts it down so quickly if it stops receiving data. If I set it up correctly, it's meant to only retry up to 3 times per 8 hours.
Neil-YL commentedon Mar 24, 2025
From previous experience, YT provides quite a bit of room for the streaming device to reconnect if it receives no data. I have turned off auto-stop, so it will not end immediately.
I think I could set up a new stream but don't touch the Pi to see if the new stream can receive data.
Jonathan-Woo commentedon Mar 24, 2025
Yep I'm working on this this week.
Neil-YL commentedon Mar 24, 2025
The logs seems it did not retry after the Broken pipe error
and the service is inactive
Same for the A1mini
sgbaird commentedon Mar 24, 2025
xref: #72 (comment)
Jonathan-Woo commentedon Mar 28, 2025
Schematic of discussed approach:
sgbaird commentedon Mar 28, 2025
Lmk how it goes!
sgbaird commentedon Mar 31, 2025
@Jonathan-Woo do you have a status update on this / what you've tried?
sgbaird commentedon Apr 1, 2025
Given @Jonathan-Woo's constraints, @Neil-YL do you mind taking a stab at this today? (Just a minimal working example as a Python script or notebook, and if you could share the API key over slack, if applicable)
Neil-YL commentedon Apr 1, 2025
Sure. I will look into that.
Neil-YL commentedon Apr 1, 2025
Documentation on YouTube API Setup
YouTube Data API, API Key and OAuth 2.0 Setup
Official getting started documentation of YouTube Data API: https://developers.google.com/youtube/v3/live/getting-started
OAuth 2.0 is required to access all features of the YouTube Data API.
Below is a step-by-step guide on how to enable YouTube Data API, obtain API Key, configure OAuth in the Google Cloud Console and generate a
token.picklefile on your local machine.You can complete this setup using your own Google account — it doesn't have to be the same account as the YouTube channel owner (but you do need to know the owner account email).
Create a Google Cloud Project
YouTube Stream) and click Create.Enable YouTube Data API v3
Obtain API Key
Note: API key will be used for public data access on YouTube, for management level features like starting stream or add video to playlist, you will need OAuth for account authentication. Continue with following steps for OAuth set up.
Configure OAuth Consent Screen
YouTube Stream API)Create OAuth 2.0 Client
Stream Auth) and click Create.client_secrets.json.Add Test Users
Generate
token.picklefrom OAuth JSONAfter creating your OAuth 2.0 credentials in Google Cloud and downloading the
client_secrets.jsonfile, follow these steps to generate atoken.picklefile for future API access.google-auth-oauthlibvia pip:client_secrets.jsonin your working directory.get_token.py):After you run the script, a browser window will open to let you sign in and authorize access, please use the same account in the previous Audience > Test users set up, not the Google Cloud Project account (if they are different).
You will see a page says "Google hasn’t verified this app". If you're testing it yourself and everything is under your control, it's safe to click Continue and proceed.
After successful login, a
token.picklefile will be saved locally. This token will be used in your application to authenticate YouTube API requests without needing to re-login.Quota on using YouTube API
The YouTube Data API uses a quota system. Projects that enable the YouTube Data API have a default quota allocation of 10,000 units per day, an amount sufficient for the majority of our API users.
I’ve tested it under the same account, but if anyone would like to follow this documentation and share feedback (in case that I missed any previous setting), it would be greatly appreciated.
sgbaird commentedon Apr 1, 2025
Nice! Do you have a link that served as a starting point for these instructions? Also, I'm realizing we can probably port this over to the README within picam/.
sgbaird commentedon Apr 1, 2025
Any follow-up thoughts on how to retrieve the "latest stream" from a particular playlist? Not sure what kind of metadata we can extract related to the playlists.
Neil-YL commentedon Apr 1, 2025
starting point: https://developers.google.com/youtube/v3/live/getting-started
Most of the setup will be on Google Cloud Console. If everything is going to be under our account (AC Hardware Streams) , you won’t need to repeat this process—but it will be required for any other YouTube channels.
Neil-YL commentedon Apr 1, 2025
I will get into it tomorrow as well. I believe (hopefully) it would be something with a simpler API-KEY if we would like to use it on the Hugging Face. OAuth2.0 is required to start and manage stream/video.
sgbaird commentedon Apr 2, 2025
Technically I think we could have a separate cloud service (i.e., virtual machine) running 24/7 that monitors for when streams go down and then reinstantiates them when they do. This could handle streams across all devices, and then the devices could just worry about retrieving stream keys rather than starting streams. More from an access/security/limiting scope point of view. Thoughts?
I'm ok with sticking with having the pickle file on each streaming device.
Aside: the owner account was my AC Gmail.
Neil-YL commentedon Apr 2, 2025
Have a update on the API key setup on the documentation above
sgbaird commentedon Apr 2, 2025
Great! Were you able to verify that the API key is usable? (I would imagine it's fine)
Neil-YL commentedon Apr 3, 2025
I've tested it with a colab demo on getting latest video from a playlist. Very easy to implement.
Neil-YL commentedon Apr 3, 2025
Quota cost of using YouTube API:
https://developers.google.com/youtube/v3/determine_quota_cost
sgbaird commentedon Apr 3, 2025
Aside: we chatted about unique naming, and likely that we'll add something related to serial number (probably RPi, could encrypt first if we want to) to both the hostname (since it's the same tailscale) and as a way to distinguish devices on the YouTube streaming side. On our end, we decide which camera faces which equipment (which could be multiple), and we can reconfigure at will, which puts that relationship on us to track and record. YouTube limits to 5000 videos per playlist (mostly due to constraints on RAM for Chrome, etc.), which gives us ~4.5 years assuming 8 hour chunks and minimal sub-divisions of the 8 hours (i.e., no 5a, 5b - type splits due to failures).
Current example of a hostname:
rpi-zero2w-a1mini-stream, which also gets a bit problematic if we want to rearrange things. However, easy mid-term solution is to append some unique ID at the end.Neil-YL commentedon Apr 4, 2025
Stream started by API has this pop-up on YouTube Studio. Will look into it later.
Neil-YL commentedon Apr 4, 2025
Quote from https://stackoverflow.com/questions/59412711/how-to-set-made-for-children-in-youtube-api:
Added to start stream colab
sgbaird commentedon Apr 4, 2025
Could you include the colab links here? (Maybe I missed it from above) - ok if it's private to the two of us, just for convenience
sgbaird commentedon Apr 4, 2025
Just got it
sgbaird commentedon Apr 5, 2025
I added video lookup to OT-2 hugging face
Unrelated EDIT (to avoid triggering notification): #80 (comment) has some documentation about channel setup, which we might want to incorporate into docs