Is there any way to get the live chat replay log/history for YouTube streaming video?

kkorona picture kkorona · Apr 22, 2019 · Viewed 11.9k times · Source

Recently I'm doing research for online chat message patterns. I chose YouTube and Twitch.tv for chat message sources.

So I found chat loggers for real-time livestream, but I also need log/history for already broadcasted livestream which allows live chat replay. (like https://www.youtube.com/watch?v=1JfohG5a8y8 )

There are tool for Twitch.tv (RechatTool from jdpurcell), but I couldn't find any similar one of them for YouTube.

So I checked YouTube API for livestream messages, but I couldn't find any instructions or tips for live chat replay. Is there any possible solutions for this?

Answer

Xenova picture Xenova · Jul 24, 2020

I know this is quite a late response, but it might help others. I developed a tool that retrieves YouTube/Twitch chat messages for past broadcasts/VODs. Here is a link to the source code:

https://github.com/xenova/chat-replay-downloader

The program can be accessed from the command line or from a module in python. I also included the ability to specify a start and/or an end time - which is useful if you don't want to download the whole chat replay.

For each message, the following data is retrieved: timestamp (unix microseconds, e.g. 1590865172190236), time_text (human readable text, e.g. 4:00:00), time_in_seconds (time in seconds, e.g. 14400), author (username of sender) and message (actual message).


Here are the usage examples I have:

From the command line:

(1) Output file of all chat messages, given a url

python chat_replay_downloader.py <video_url> -output <file_name>

If the file name ends in .json, the array will be written to the file in JSON format. Otherwise, the chat messages will be outputted to the file in the following format: [<time>] <author>: <message>

(2) Output file of chat messages, starting at a certain time (in seconds) until the end

python chat_replay_downloader.py <video_url> -start_time <time_in_seconds> -output <file_name>

(3) Output file of chat messages, starting from the beginning and ending at a certain time (in seconds)

python chat_replay_downloader.py <video_url> -end_time <time_in_seconds> -output <file_name>

(4) Output file of chat messages, starting and ending at certain times (in seconds)

python chat_replay_downloader.py <video_url> -start_time <time_in_seconds> -end_time <time_in_seconds> -output <file_name>

Example outputs:

JSON Example:

python chat_replay_downloader.py https://www.youtube.com/watch?v=pMsvr55cTZ0 -start_time 14400 -end_time 15000 -output example.json

CSV Example:

python chat_replay_downloader.py https://www.youtube.com/watch?v=pMsvr55cTZ0 -start_time 14400 -end_time 15000 -output example.csv

Text Example:

python chat_replay_downloader.py https://www.youtube.com/watch?v=pMsvr55cTZ0 -start_time 14400 -end_time 15000 -output example.txt

Python module

Importing the module:

import chat_replay_downloader

or

from chat_replay_downloader import get_chat_replay, get_youtube_messages, get_twitch_messages

The following examples will use the second form of importing.

Examples:

(1) Return list of all chat messages, given a video url:

youtube_messages = get_chat_replay('https://www.youtube.com/watch?v=xxxxxxxxxxx')
twitch_messages = get_chat_replay('https://www.twitch.tv/videos/xxxxxxxxx')

(2) Return list of all chat messages, given a video id

youtube_messages = get_youtube_messages('xxxxxxxxxxx')
twitch_messages = get_twitch_messages('xxxxxxxxx')

The following examples use parameters which all three methods (get_chat_replay, get_youtube_messages, get_twitch_messages) have. Both of the following parameters are optional:

  • start_time: start time in seconds (Default is 0, which is the start of the video)
  • end_time: end time in seconds (Default is None, which means it will continue until the video ends)

(3) Return list of chat messages, starting at a certain time (in seconds)

messages = get_chat_replay('video_url', start_time = 60) # Start at 60 seconds and continue until the end

(4) Return list of chat messages, ending at a certain time (in seconds)

messages = get_chat_replay('video_url', end_time = 60) # Start at 0 seconds (beginning) and end at 60 seconds

(5) Return list of chat messages, starting and ending at certain times (in seconds)

messages = get_chat_replay('video_url', start_time = 60, end_time = 120) # Start at 60 seconds and end at 120 seconds