Dataspryva

Use YouTube Live Stream & Replay Chat Extractor with Python

Collect chat messages, Super Chats, Super Stickers, and membership events from an active YouTube livestream or an ended stream's saved chat replay, with author and timestamp detail.

1. Choose the data you need

Review the published README for supported collection modes, examples, and limits. The recipe below uses the current published input definition.

2. Prepare a source-based input

This JSON contains published prefills and required-field defaults. Review every value for your task before running it; it is not a promise of successful collection.

{
  "channelDiscoveryMode": "current_live",
  "endOffsetSecs": 0,
  "includeGiftEvents": true,
  "includeMembershipEvents": true,
  "includeMetadata": true,
  "includeNormalMessages": true,
  "includePlaceholders": false,
  "includeSummary": false,
  "includeSuperChats": true,
  "includeSystemEvents": true,
  "includeUpcomingLives": false,
  "language": "en",
  "liveCollectSecs": 10,
  "lookbackDays": 30,
  "maxMessagesPerVideo": 3,
  "maxTimePerVideoSecs": 120,
  "maxTotalItems": 3,
  "maxVideosPerChannel": 1,
  "mode": "auto",
  "pollIntervalMs": 2000,
  "regionCode": "US",
  "startOffsetSecs": 0,
  "videoRefs": [
    "https://www.youtube.com/watch?v=FQbNtLOVlwU"
  ]
}

Download input.example.json and save your reviewed copy as input.json.

FieldTypeRequiredDescription
videoRefsarrayoptionalYouTube watch, live, shorts or youtu.be links, 11-character video IDs, or a channel live link such as @handle/live.
channelRefsarrayoptionalChannel handles (@name), channel URLs or UC… channel IDs. The actor discovers current live streams and recent stream replays from each channel.
modestringoptionalAuto detects live versus replay. Active captures an ongoing live chat. Replay reads the saved chat of an ended stream.
channelDiscoveryModestringoptionalWhich streams to pick from each channel. Used with channel references.
maxVideosPerChannelintegeroptionalMaximum streams to process from each channel.
lookbackDaysintegeroptionalHow far back to include ended streams from a channel. Use 0 for no limit.
includeUpcomingLivesbooleanoptionalEmit an upcoming status row for scheduled channel streams instead of skipping them.
maxMessagesPerVideointegeroptionalMaximum unique chat events collected from each video. Use 0 to collect every available event.
maxTotalItemsintegeroptionalWhole-run cap across all videos and summary rows. Use 0 for no limit.
maxTimePerVideoSecsintegeroptionalSafety limit for replay pagination on one video, in seconds. A run that reaches it reports partial_capture.
includeNormalMessagesbooleanoptionalInclude standard text chat messages.
includeSuperChatsbooleanoptionalInclude paid Super Chat messages and paid Super Stickers.
includeMembershipEventsbooleanoptionalInclude new and renewed channel membership events.
includeGiftEventsbooleanoptionalInclude gift membership purchases, gift membership redemptions and paid gift messages.
includeSystemEventsbooleanoptionalInclude engagement notices, slow-mode changes, restricted participation and other system rows.
includePlaceholdersbooleanoptionalInclude raw placeholder rows that contain only an ID and timestamp.
includeSummarybooleanoptionalAdd one stream_summary row per video with event counts, per-currency totals, top supporters and completeness.
startOffsetSecsintegeroptionalReplay only. Skip events before this video offset. Use 0 to start at the beginning.
endOffsetSecsintegeroptionalReplay only. Stop after this video offset. Use 0 to read to the end.
liveCollectSecsintegeroptionalHow long to keep polling an active chat before stopping. Live captures are always partial.
pollIntervalMsintegeroptionalMinimum delay between live chat polls. YouTube's own timeout is honoured when it is longer.
languagestringoptionalInterface language used when requesting YouTube pages and chat.
regionCodestringoptionalRegion used for YouTube page and chat requests.
includeMetadatabooleanoptionalRepeat video and stream metadata on each chat row.

3. Start an Actor run

Set APIFY_TOKEN in your environment. Python 3.10 or newer is sufficient; this recipe uses no third-party packages.

Execution may incur charges. Review current pricing on Apify. The request asks for a 120-second timeout and a charge limit; these settings are subject to Apify’s pricing and do not guarantee an all-inclusive spending cap.

import json
import os
import urllib.request

# Save the schema-derived example as input.json; review and edit it first.
with open("input.json", encoding="utf-8") as stream:
    actor_input = json.load(stream)

token = os.environ["APIFY_TOKEN"]
request = urllib.request.Request(
    "https://api.apify.com/v2/acts/KuR4Wj8bAkeGAly61/runs?timeout=120&maxTotalChargeUsd=0.50",
    data=json.dumps(actor_input).encode("utf-8"),
    headers={"Authorization": "Bearer " + token, "Content-Type": "application/json"},
    method="POST",
)
# This starts a potentially billable run. Do not automatically retry this POST.
with urllib.request.urlopen(request, timeout=40) as response:
    run = json.load(response)["data"]
print("Run ID:", run["id"])
print("Status:", run["status"])
# Inspect and download results in Apify Console once the run succeeds.

4. Inspect the actual results

Open the run in Apify Console and wait for a successful completion. Use the published output schema to locate results and the dataset schema to understand declared views. Missing or optional record fields must not be treated as guaranteed values.

Chat events with authors, replay offsets, Super Chat and gift amounts, membership detail, badges, stream metadata and optional summaries.

Questions before you run

Which inputs are required?

No top-level fields are marked required in the published schema. Conditional requirements can still apply; check the README.

What does this guide verify?

The fields, prefills, and schema links are rendered from the published build. This is a usage recipe, not a paid live extraction test. Source availability and collection results can vary.

What if the run request times out?

Check Apify Console before retrying. The first request may already have created a run. Do not automatically repeat a run-creation POST.

Generated from source build RX1LgB29gltcaO0El and its README and schemas. Source changes regenerate this guide; no third-party editorial claims are inferred.