DustinWatts / YouTubeLiveChat

NodeJS app to get chat messages from a live stream on YouTube

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

YouTubeLiveChat

NodeJS app to get chat messages from a live stream on YouTube. To get the chat messages from a live stream on YouTube, two steps are required. The first step is to get the LiveChatId. The second step is to get the messages using that LiveChatId. Unfortunately these are two different API's. The --id argument calls the https://www.googleapis.com/youtube/v3/videos API with two parameters: &id calls for a specific video (in this case a live stream) and &part with the part name set to liveStreamingDetails returns some properties of that video. We are interested in the activeLiveChatId.

The next API call that needs to be made is to https://www.googleapis.com/youtube/v3/liveChat/messages. This is done with the --messages argument. Again two parameters are added: &part has two values: id and snippet. The value of &liveChatId is the previously obtained activeLiveChatId. The call to this API returns live chat messages for the specified live stream. The messages live in items[].snippet.displayMessage.

Both API calls also need &key. A (limited) free Google API key can be obtained from https://console.cloud.google.com, creating a Project, adding an API to that Project and then creating an API key for that Project. In this app you need to add your API key to sercet.json under "apiKey:".

Quick Use Guide

Use:

node livechat.js --id [livestreamid]

To get the LiveChatID from Youtube, where [livestreamid] is the ID that can be found in the YouTube video url: https://www.youtube.com/watch?v=[thisisthelivestreamid].

Use:

node livechat.js --messages [livechatid]

To print out all the chat messages. Where [livechatid] the previously obtained LiveChatID.

NodeJS + npm

Node.js is an open-source cross-platform JavaScript run-time environment. To install NodeJS:

sudo apt install nodejs -or- download from https://nodejs.org/en/

npm is a package manager used to add modules to NodeJS. To install npm:

sudo apt install npm

secret.json

This is where your GoogleAPI API-key lives.

node-fetch

node-fetch is a required module. After cloning, install using npm install node-fetch

Documentation the Google API's

About

NodeJS app to get chat messages from a live stream on YouTube

License:MIT License


Languages

Language:JavaScript 100.0%