Update README

This commit is contained in:
taizan-hokouto
2020-11-03 18:13:25 +09:00
parent 02827b174e
commit 0c0ba0dfe6

112
README.md
View File

@@ -14,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>
[JP wiki](https://github.com/taizan-hokuto/pytchat/wiki/Home_jp) [wiki (Japanese)](https://github.com/taizan-hokuto/pytchat/wiki/Home_jp)
## Install ## Install
```python ```python
@@ -27,9 +27,9 @@ pip install pytchat
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) . 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=uIx8l2xlYVY -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: './')
@@ -38,96 +38,42 @@ $ pytchat -v https://www.youtube.com/watch?v=ZJ6Q4U_Vg6s -o "c:/temp/"
``` ```
### on-demand mode with simple non-buffered. ### On-demand mode with simple non-buffered object.
```python ```python
import pytchat import pytchat
chat = pytchat.create(video_id="Zvp1pJpie4I") chat = pytchat.create(video_id="uIx8l2xlYVY")
while chat.is_alive(): while chat.is_alive():
chatdata = chat.get() for c in chat.get().sync_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}")
``` ```
### callback mode with bufferd. ### Output JSON format (feature of [DefaultProcessor](DefaultProcessor))
```python
from pytchat import LiveChat
import time
def main():
chat = LiveChat(video_id = "Zvp1pJpie4I", callback = disp)
while livechat.is_alive():
#other background operation.
time.sleep(1)
chat.terminate()
#callback function (automatically called)
def disp(chatdata):
for c in chatdata.sync_items():
print(f"{c.datetime} [{c.author.name}]- {c.message}")
if __name__ == '__main__':
main()
```
### asyncio context:
```python
from pytchat import LiveChatAsync
from concurrent.futures import CancelledError
import asyncio
async def main():
livechat = LiveChatAsync("Zvp1pJpie4I", callback = func)
while livechat.is_alive():
#other background operation.
await asyncio.sleep(3)
#callback function is automatically called.
async def func(chatdata):
async for c in chatdata.async_items():
print(f"{c.datetime} [{c.author.name}]-{c.message} {c.amountString}")
if __name__ == '__main__':
try:
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
except CancelledError:
pass
```
### youtube api compatible processor:
```python
from pytchat import LiveChat, CompatibleProcessor
import time
chat = LiveChat("Zvp1pJpie4I",
processor = CompatibleProcessor() )
while chat.is_alive():
try:
data = chat.get()
polling = data['pollingIntervalMillis']/1000
for c in data['items']:
if c.get('snippet'):
print(f"[{c['authorDetails']['displayName']}]"
f"-{c['snippet']['displayMessage']}")
time.sleep(polling/len(data['items']))
except KeyboardInterrupt:
chat.terminate()
```
### replay:
If specified video is not live,
automatically try to fetch archived chat data.
```python ```python
import pytchat import pytchat
chat = pytchat.get("ojes5ULOqhc", seektime = 60*30) import time
chat = pytchat.create(video_id="uIx8l2xlYVY")
while chat.is_alive(): while chat.is_alive():
chatdata = chat.get() print(chat.get().json())
for c in chatdata.sync_items(): time.sleep(5)
print(f"{c.datetime} [{c.author.name}]- {c.message}") '''
# Each chat item can also be output in JSON format.
for c in chat.get().sync_items():
print(c.json())
'''
``` ```
### 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).
### other
#### Fetch chat with buffer.
[LiveChat](https://github.com/taizan-hokuto/pytchat/wiki/LiveChat)
#### Asyncio Context
[LiveChatAsync](https://github.com/taizan-hokuto/pytchat/wiki/LiveChatAsync)
#### [YT API compatible chat processor]https://github.com/taizan-hokuto/pytchat/wiki/CompatibleProcessor)
### [Extract archived chat data](https://github.com/taizan-hokuto/pytchat/wiki/Extractor)
```python ```python
from pytchat import HTMLArchiver, Extractor from pytchat import HTMLArchiver, Extractor