Skip to main content

a python library for fetching youtube live chat.

Project description

pytchat

pytchat is a python library for fetching youtube live chat.

Description

pytchat is a python library for fetching youtube live chat without using Selenium or BeautifulSoup.

Other features:

  • Customizable chat data processors including youtube api compatible one.
  • Available on asyncio context.
  • Quick fetching of initial chat data by generating continuation params instead of web scraping.

For more detailed information, see wiki.
wiki (Japanese)

Install

pip install pytchat

Examples

CLI

  • One-liner command.

  • Save chat data to html with embedded custom emojis.

  • Show chat stream (--echo option).

$ pytchat -v uIx8l2xlYVY -o "c:/temp/"
# options:
#  -v : Video ID or URL that includes ID
#  -o : output directory (default path: './')
#  --echo : Show chats.
# saved filename is [video_id].html

Fetch chat data (see wiki)

import pytchat
chat = pytchat.create(video_id="uIx8l2xlYVY")
while chat.is_alive():
    for c in chat.get().sync_items():
        print(f"{c.datetime} [{c.author.name}]- {c.message}")

Output JSON format string (feature of DefaultProcessor)

import pytchat
import time

chat = pytchat.create(video_id="uIx8l2xlYVY")
while chat.is_alive():
    print(chat.get().json())
    time.sleep(5)
    '''
    # Each chat item can also be output in JSON format.
    for c in chat.get().items:
        print(c.json())
    '''     

other

Structure of Default Processor

Each item can be got with sync_items() function.

name type remarks
type str "superChat","textMessage","superSticker","newSponsor"
id str
message str emojis are represented by ":(shortcut text):"
messageEx str list of message texts and emoji dicts(id, txt, url).
timestamp int unixtime milliseconds
datetime str e.g. "2019-10-10 12:34:56"
elapsedTime str elapsed time. (e.g. "1:02:27") *Replay Only.
amountValue float e.g. 1,234.0
amountString str e.g. "$ 1,234"
currency str ISO 4217 currency codes (e.g. "USD")
bgColor int RGB Int
author object see below

Structure of author object.

name type remarks
name str
channelId str *chatter's channel ID.
channelUrl str
imageUrl str
badgeUrl str
isVerified bool
isChatOwner bool
isChatSponsor bool
isChatModerator bool

Licence

MIT License

Contributes

Great thanks:

Most of source code of CLI refer to:

PetterKraabol / Twitch-Chat-Downloader

Progress bar in CLI is based on:

vladignatyev/progress.py

Author

taizan-hokuto

twitter:@taizan205

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pytchat, version 0.4.7
Filename, size File type Python version Upload date Hashes
Filename, size pytchat-0.4.7-py3-none-any.whl (67.1 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page