https://github.com/taizan-hokuto/pytchat
library for youtube chat.
https://github.com/taizan-hokuto/pytchat
livechat youtube youtube-chat
Last synced: 4 months ago
JSON representation
library for youtube chat.
- Host: GitHub
- URL: https://github.com/taizan-hokuto/pytchat
- Owner: taizan-hokuto
- License: mit
- Archived: true
- Created: 2019-11-02T23:58:16.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-07-24T14:02:17.000Z (over 4 years ago)
- Last Synced: 2025-06-12T11:03:14.401Z (5 months ago)
- Topics: livechat, youtube, youtube-chat
- Language: Python
- Homepage:
- Size: 636 KB
- Stars: 354
- Watchers: 10
- Forks: 48
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-vtuber - pytchat - Python library for youtube chat. (Dev Tools)
README
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](https://github.com/taizan-hokuto/pytchat/wiki/ChatProcessor) 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](https://github.com/taizan-hokuto/pytchat/wiki).
[wiki (Japanese)](https://github.com/taizan-hokuto/pytchat/wiki/Home_jp)
## Install
```python
pip install pytchat
```
## Examples
### Fetch chat data (see [wiki](https://github.com/taizan-hokuto/pytchat/wiki/PytchatCore))
```python
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](https://github.com/taizan-hokuto/pytchat/wiki/DefaultProcessor))
```python
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
+ Fetch chat with a buffer ([LiveChat](https://github.com/taizan-hokuto/pytchat/wiki/LiveChat))
+ Use with asyncio ([LiveChatAsync](https://github.com/taizan-hokuto/pytchat/wiki/LiveChatAsync))
+ YT API compatible chat processor ([CompatibleProcessor](https://github.com/taizan-hokuto/pytchat/wiki/CompatibleProcessor))
## 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
[](LICENSE)