Compare commits

..

11 Commits

Author SHA1 Message Date
taizan-hokouto
bb4113b53c Merge branch 'hotfix/emoji' 2020-11-06 19:58:44 +09:00
taizan-hokouto
07f4382ed4 Increment version 2020-11-06 19:57:16 +09:00
taizan-hokouto
d40720616b Fix emoji encoding 2020-11-06 19:56:54 +09:00
taizan-hokouto
6c9e327e36 Merge branch 'hotfix/fix_readme' 2020-11-05 22:19:11 +09:00
taizan-hokouto
e9161c0ddd Update README 2020-11-05 22:18:54 +09:00
taizan-hokouto
30cb7d7043 Merge branch 'hotfix/fix_readme' 2020-11-05 00:14:50 +09:00
taizan-hokouto
19d5b74beb Update README 2020-11-05 00:14:36 +09:00
taizan-hokouto
1d479fc15c Merge branch 'hotfix/fix_readme' 2020-11-03 20:21:52 +09:00
taizan-hokouto
20a20ddd08 Update README 2020-11-03 20:21:39 +09:00
taizan-hokouto
67b766b32c Merge branch 'hotfix/fix_readme' 2020-11-03 20:10:48 +09:00
taizan-hokouto
249aa0d147 Update README 2020-11-03 20:10:34 +09:00
3 changed files with 16 additions and 27 deletions

View File

@@ -24,12 +24,14 @@ pip install pytchat
### CLI ### CLI
One-liner command. + One-liner command.
+ Save chat data to html with embedded custom emojis.
+ Show chat stream (--echo option).
Save chat data to html with embedded custom emojis.
Show chat stream (--echo option).
```bash ```bash
$ pytchat -v https://www.youtube.com/watch?v=uIx8l2xlYVY -o "c:/temp/" $ pytchat -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,7 +40,7 @@ $ pytchat -v https://www.youtube.com/watch?v=uIx8l2xlYVY -o "c:/temp/"
``` ```
### On-demand mode with simple non-buffered object. ### Fetch chat data (see [wiki](https://github.com/taizan-hokuto/pytchat/wiki/PytchatCore))
```python ```python
import pytchat import pytchat
chat = pytchat.create(video_id="uIx8l2xlYVY") chat = pytchat.create(video_id="uIx8l2xlYVY")
@@ -47,7 +49,8 @@ while chat.is_alive():
print(f"{c.datetime} [{c.author.name}]- {c.message}") print(f"{c.datetime} [{c.author.name}]- {c.message}")
``` ```
### Output JSON format (feature of [DefaultProcessor](DefaultProcessor))
### Output JSON format string (feature of [DefaultProcessor](https://github.com/taizan-hokuto/pytchat/wiki/DefaultProcessor))
```python ```python
import pytchat import pytchat
import time import time
@@ -58,35 +61,21 @@ while chat.is_alive():
time.sleep(5) time.sleep(5)
''' '''
# Each chat item can also be output in JSON format. # Each chat item can also be output in JSON format.
for c in chat.get().sync_items(): for c in chat.get().items:
print(c.json()) print(c.json())
''' '''
``` ```
### other ### other
#### Fetch chat with buffer. + Fetch chat with a buffer ([LiveChat](https://github.com/taizan-hokuto/pytchat/wiki/LiveChat))
[LiveChat](https://github.com/taizan-hokuto/pytchat/wiki/LiveChat)
#### Asyncio Context + Use with asyncio ([LiveChatAsync](https://github.com/taizan-hokuto/pytchat/wiki/LiveChatAsync))
[LiveChatAsync](https://github.com/taizan-hokuto/pytchat/wiki/LiveChatAsync)
#### [YT API compatible chat processor]https://github.com/taizan-hokuto/pytchat/wiki/CompatibleProcessor) + YT API compatible chat processor ([CompatibleProcessor](https://github.com/taizan-hokuto/pytchat/wiki/CompatibleProcessor))
### [Extract archived chat data](https://github.com/taizan-hokuto/pytchat/wiki/Extractor) + Extract archived chat data ([Extractor](https://github.com/taizan-hokuto/pytchat/wiki/Extractor))
```python
from pytchat import HTMLArchiver, Extractor
video_id = "*******"
ex = Extractor(
video_id,
div=10,
processor=HTMLArchiver("c:/test.html")
)
ex.extract()
print("finished.")
```
## Structure of Default Processor ## Structure of Default Processor
Each item can be got with `sync_items()` function. Each item can be got with `sync_items()` function.

View File

@@ -2,7 +2,7 @@
pytchat is a lightweight python library to browse youtube livechat without Selenium or BeautifulSoup. pytchat is a lightweight python library to browse youtube livechat without Selenium or BeautifulSoup.
""" """
__copyright__ = 'Copyright (C) 2019 taizan-hokuto' __copyright__ = 'Copyright (C) 2019 taizan-hokuto'
__version__ = '0.4.0' __version__ = '0.4.1'
__license__ = 'MIT' __license__ = 'MIT'
__author__ = 'taizan-hokuto' __author__ = 'taizan-hokuto'
__author_email__ = '55448286+taizan-hokuto@users.noreply.github.com' __author_email__ = '55448286+taizan-hokuto@users.noreply.github.com'

View File

@@ -132,7 +132,7 @@ class HTMLArchiver(ChatProcessor):
return standard_b64encode(resp.content).decode() return standard_b64encode(resp.content).decode()
def _set_emoji_table(self, item: dict): def _set_emoji_table(self, item: dict):
emoji_id = item['id'] emoji_id = ''.join(('Z', item['id'])) if 48 <= ord(item['id'][0]) <= 57 else item['id']
if emoji_id not in self.emoji_table: if emoji_id not in self.emoji_table:
self.emoji_table.setdefault(emoji_id, self.executor.submit(self._encode_img, item['url'])) self.emoji_table.setdefault(emoji_id, self.executor.submit(self._encode_img, item['url']))
return emoji_id return emoji_id