Update README
This commit is contained in:
70
README.md
70
README.md
@@ -5,9 +5,7 @@ pytchat is a python library for fetching youtube live chat.
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
pytchat is a python library for fetching youtube live chat
|
pytchat is a python library for fetching youtube live chat
|
||||||
without using youtube api, Selenium or BeautifulSoup.
|
without using Selenium or BeautifulSoup.
|
||||||
|
|
||||||
pytchatは、YouTubeチャットを閲覧するためのpythonライブラリです。
|
|
||||||
|
|
||||||
Other features:
|
Other features:
|
||||||
+ Customizable [chat data processors](https://github.com/taizan-hokuto/pytchat/wiki/ChatProcessor) including youtube api compatible one.
|
+ Customizable [chat data processors](https://github.com/taizan-hokuto/pytchat/wiki/ChatProcessor) including youtube api compatible one.
|
||||||
@@ -16,7 +14,7 @@ Other features:
|
|||||||
instead of web scraping.
|
instead of web scraping.
|
||||||
|
|
||||||
For more detailed information, see [wiki](https://github.com/taizan-hokuto/pytchat/wiki). <br>
|
For more detailed information, see [wiki](https://github.com/taizan-hokuto/pytchat/wiki). <br>
|
||||||
より詳細な解説は[wiki](https://github.com/taizan-hokuto/pytchat/wiki/Home_jp)を参照してください。
|
[JP wiki](https://github.com/taizan-hokuto/pytchat/wiki/Home_jp)
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
```python
|
```python
|
||||||
@@ -27,51 +25,45 @@ pip install pytchat
|
|||||||
### CLI
|
### CLI
|
||||||
|
|
||||||
One-liner command.
|
One-liner command.
|
||||||
Save chat data to html, with embedded custom emojis.
|
|
||||||
|
|
||||||
|
Save chat data to html with embedded custom emojis.
|
||||||
|
Show chat stream (--echo option) .
|
||||||
```bash
|
```bash
|
||||||
$ pytchat -v https://www.youtube.com/watch?v=ZJ6Q4U_Vg6s -o "c:/temp/"
|
$ pytchat -v https://www.youtube.com/watch?v=ZJ6Q4U_Vg6s -o "c:/temp/"
|
||||||
# options:
|
# options:
|
||||||
# -v : Video ID or URL that includes ID
|
# -v : Video ID or URL that includes ID
|
||||||
# -o : output directory (default path: './')
|
# -o : output directory (default path: './')
|
||||||
|
# --echo : Show chats.
|
||||||
# saved filename is [video_id].html
|
# saved filename is [video_id].html
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### on-demand mode
|
### on-demand mode with simple non-buffered.
|
||||||
```python
|
```python
|
||||||
from pytchat import LiveChat
|
import pytchat
|
||||||
livechat = LiveChat(video_id = "Zvp1pJpie4I")
|
chat = pytchat.create(video_id="Zvp1pJpie4I")
|
||||||
# It is also possible to specify a URL that includes the video ID:
|
while chat.is_alive():
|
||||||
# livechat = LiveChat("https://www.youtube.com/watch?v=Zvp1pJpie4I")
|
chatdata = chat.get()
|
||||||
while livechat.is_alive():
|
for c in chatdata.sync_items():
|
||||||
try:
|
|
||||||
chatdata = livechat.get()
|
|
||||||
for c in chatdata.items:
|
|
||||||
print(f"{c.datetime} [{c.author.name}]- {c.message}")
|
print(f"{c.datetime} [{c.author.name}]- {c.message}")
|
||||||
chatdata.tick()
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
livechat.terminate()
|
|
||||||
break
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### callback mode
|
### callback mode with bufferd.
|
||||||
```python
|
```python
|
||||||
from pytchat import LiveChat
|
from pytchat import LiveChat
|
||||||
import time
|
import time
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
livechat = LiveChat(video_id = "Zvp1pJpie4I", callback = disp)
|
chat = LiveChat(video_id = "Zvp1pJpie4I", callback = disp)
|
||||||
while livechat.is_alive():
|
while livechat.is_alive():
|
||||||
#other background operation.
|
#other background operation.
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
livechat.terminate()
|
chat.terminate()
|
||||||
|
|
||||||
#callback function (automatically called)
|
#callback function (automatically called)
|
||||||
def disp(chatdata):
|
def disp(chatdata):
|
||||||
for c in chatdata.items:
|
for c in chatdata.sync_items():
|
||||||
print(f"{c.datetime} [{c.author.name}]- {c.message}")
|
print(f"{c.datetime} [{c.author.name}]- {c.message}")
|
||||||
chatdata.tick()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
@@ -92,9 +84,8 @@ async def main():
|
|||||||
|
|
||||||
#callback function is automatically called.
|
#callback function is automatically called.
|
||||||
async def func(chatdata):
|
async def func(chatdata):
|
||||||
for c in chatdata.items:
|
async for c in chatdata.async_items():
|
||||||
print(f"{c.datetime} [{c.author.name}]-{c.message} {c.amountString}")
|
print(f"{c.datetime} [{c.author.name}]-{c.message} {c.amountString}")
|
||||||
await chatdata.tick_async()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
@@ -104,7 +95,6 @@ if __name__ == '__main__':
|
|||||||
pass
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### youtube api compatible processor:
|
### youtube api compatible processor:
|
||||||
```python
|
```python
|
||||||
from pytchat import LiveChat, CompatibleProcessor
|
from pytchat import LiveChat, CompatibleProcessor
|
||||||
@@ -130,23 +120,12 @@ If specified video is not live,
|
|||||||
automatically try to fetch archived chat data.
|
automatically try to fetch archived chat data.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from pytchat import LiveChat
|
import pytchat
|
||||||
|
chat = pytchat.get("ojes5ULOqhc", seektime = 60*30)
|
||||||
def main():
|
while chat.is_alive():
|
||||||
#seektime (seconds): start position of chat.
|
chatdata = chat.get()
|
||||||
chat = LiveChat("ojes5ULOqhc", seektime = 60*30)
|
for c in chatdata.sync_items():
|
||||||
print('Replay from 30:00')
|
print(f"{c.datetime} [{c.author.name}]- {c.message}")
|
||||||
try:
|
|
||||||
while chat.is_alive():
|
|
||||||
data = chat.get()
|
|
||||||
for c in data.items:
|
|
||||||
print(f"{c.elapsedTime} [{c.author.name}]-{c.message} {c.amountString}")
|
|
||||||
data.tick()
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
chat.terminate()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
```
|
```
|
||||||
### Extract archived chat data as [HTML](https://github.com/taizan-hokuto/pytchat/wiki/HTMLArchiver) or [tab separated values](https://github.com/taizan-hokuto/pytchat/wiki/TSVArchiver).
|
### Extract archived chat data as [HTML](https://github.com/taizan-hokuto/pytchat/wiki/HTMLArchiver) or [tab separated values](https://github.com/taizan-hokuto/pytchat/wiki/TSVArchiver).
|
||||||
```python
|
```python
|
||||||
@@ -164,7 +143,7 @@ print("finished.")
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Structure of Default Processor
|
## Structure of Default Processor
|
||||||
Each item can be got with `items` function.
|
Each item can be got with `sync_items()` function.
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>name</th>
|
<th>name</th>
|
||||||
@@ -298,6 +277,9 @@ Most of source code of CLI refer to:
|
|||||||
|
|
||||||
[PetterKraabol / Twitch-Chat-Downloader](https://github.com/PetterKraabol/Twitch-Chat-Downloader)
|
[PetterKraabol / Twitch-Chat-Downloader](https://github.com/PetterKraabol/Twitch-Chat-Downloader)
|
||||||
|
|
||||||
|
Progress bar in CLI is based on:
|
||||||
|
|
||||||
|
[vladignatyev/progress.py](https://gist.github.com/vladignatyev/06860ec2040cb497f0f3)
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user