Fetch information about YouTube channels and their live streams.
The main motivation behind it was to have a small script to grab a list of livestream URLs in a online tournament setting. I am not sure how this would work with unlisted YouTube streams as I doubt the API will list those.
Once you cloned the repository, you can fetch the required Google libraries with requirements.txt:
pip install -r requirements.txt
You will need to create a Google Cloud Console project though the GCP Developer Console which has access to the YouTube Data API v3.
You will then need to create a OAuth 2.0 Client in the project and enter its Client ID
, Client Secret
and the Project ID
in the client_secret.json
file.
You can use the helper script, getRefreshToken.py
, by calling it as-is without parameters, after you filled the fields mentioned above to grab the refresh_token from the callback url. This is the last field you need to fill in the client_secret.json
file.
The scripts uses two methods from YouTube's Data API:
youtube.api.v3.V3DataChannelService.List
- To grab the livestream information (is the livestream on? If so, what is the
videoid
?)
- To grab the livestream information (is the livestream on? If so, what is the
youtube.api.v3.V3DataSearchService.List
- To grab the channel name for verbosity.
python youtube_stream_grabber.py -c CHANNELS [-o OUTPUT]
-c CHANNELS
: Required. A string or file containing a list of YouTube channel IDs.-o OUTPUT
: Optional. Output file for the live stream information. If this parameter is not provided, the live stream information will only be printed and not written to a file on disk.
python youtube_stream_grabber.py -c channels.txt -o livestreams.txt
# Checking if DrLupo is live, and getting the stream URL
python youtube_stream_grabber.py -c UCVeW9qkBjo3zosnqUbG7CFw
- Jeff Noel (https://github.com/JF10R)
- OpenAI ChatGPT