diff --git a/README.md b/README.md index 0f7bcea..694ad8a 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,10 @@ 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. -pytchatはAPIを使わずにYouTubeチャットを取得するための軽量pythonライブラリです。 +pytchatはAPIを使わずにYouTubeチャットを取得するためのpythonライブラリです。 Other features: -+ Customizable chat data processors including youtube api compatible one. ++ 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. diff --git a/pytchat/__init__.py b/pytchat/__init__.py index 390f047..099bf9f 100644 --- a/pytchat/__init__.py +++ b/pytchat/__init__.py @@ -2,7 +2,7 @@ pytchat is a python library for fetching youtube live chat without using yt api, Selenium, or BeautifulSoup. """ __copyright__ = 'Copyright (C) 2019 taizan-hokuto' -__version__ = '0.0.6.5' +__version__ = '0.0.6.6' __license__ = 'MIT' __author__ = 'taizan-hokuto' __author_email__ = '55448286+taizan-hokuto@users.noreply.github.com' diff --git a/pytchat/cli/__init__.py b/pytchat/cli/__init__.py index 0bd99b3..c3c16ac 100644 --- a/pytchat/cli/__init__.py +++ b/pytchat/cli/__init__.py @@ -22,9 +22,10 @@ def main(): # Arguments parser = argparse.ArgumentParser(description=f'pytchat v{__version__}') parser.add_argument('-v', f'--{Arguments.Name.VIDEO}', type=str, - help='Video IDs separated by commas without space') + help='Video IDs separated by commas without space.\n' + 'If ID starts with a hyphen (-), enclose the ID in square brackets.') parser.add_argument('-o', f'--{Arguments.Name.OUTPUT}', type=str, - help='Output directory (end with "/")', default='./') + help='Output directory (end with "/"). default="./"', default='./') parser.add_argument(f'--{Arguments.Name.VERSION}', action='store_true', help='Settings version') Arguments(parser.parse_args().__dict__) @@ -43,11 +44,17 @@ def main(): f" video_id: {video_id}\n" f" channel: {info.get_channel_name()}\n" f" title: {info.get_title()}") + path = Path(Arguments().output+video_id+'.html') + print(f"output path: {path.resolve()}") Extractor(video_id, - processor = HTMLArchiver(Arguments().output+video_id+'.html') + processor = HTMLArchiver(Arguments().output+video_id+'.html'), + callback = _disp_progress ).extract() - print("Extraction end.\n") + print("\nExtraction end.\n") except (InvalidVideoIdException, NoContentsException) as e: print(e) return parser.print_help() + +def _disp_progress(a,b): + print('.',end="",flush=True) diff --git a/pytchat/exceptions.py b/pytchat/exceptions.py index cffb955..11e5ba1 100644 --- a/pytchat/exceptions.py +++ b/pytchat/exceptions.py @@ -1,46 +1,52 @@ class ChatParseException(Exception): ''' - チャットデータをパースするライブラリが投げる例外の基底クラス + Base exception thrown by the parser ''' pass class NoYtinitialdataException(ChatParseException): ''' - 配信ページ内にチャットデータurlが見つからないときに投げる例外 + Thrown when the video is not found. ''' pass class ResponseContextError(ChatParseException): ''' - 配信ページでチャットデータ無効の時に投げる例外 + Thrown when chat data is invalid. ''' pass class NoLivechatRendererException(ChatParseException): ''' - チャットデータのJSON中にlivechatRendererがない時に投げる例外 + Thrown when livechatRenderer is missing in JSON. ''' pass class NoContentsException(ChatParseException): ''' - チャットデータのJSON中にContinuationContentsがない時に投げる例外 + Thrown when ContinuationContents is missing in JSON. ''' pass class NoContinuationsException(ChatParseException): ''' - チャットデータのContinuationContents中にcontinuationがない時に投げる例外 + Thrown when continuation is missing in ContinuationContents. ''' pass class IllegalFunctionCall(Exception): ''' - set_callback()を実行済みにもかかわらず - get()を呼び出した場合の例外 + Thrown when get () is called even though + set_callback () has been executed. ''' pass class InvalidVideoIdException(Exception): + ''' + Thrown when the video_id is not exist (VideoInfo). + ''' pass + +class UnknownConnectionError(Exception): + pass \ No newline at end of file diff --git a/pytchat/processors/html_archiver.py b/pytchat/processors/html_archiver.py index 45626ab..9249cf4 100644 --- a/pytchat/processors/html_archiver.py +++ b/pytchat/processors/html_archiver.py @@ -8,6 +8,11 @@ PATTERN = re.compile(r"(.*)\(([0-9]+)\)$") fmt_headers = ['datetime','elapsed','authorName','message','superchat' ,'type','authorChannel'] +HEADER_HTML = ''' + + +''' + class HTMLArchiver(ChatProcessor): ''' HtmlArchiver saves chat data as HTML table format. @@ -17,6 +22,7 @@ class HTMLArchiver(ChatProcessor): super().__init__() self.save_path = self._checkpath(save_path) with open(self.save_path, mode='a', encoding = 'utf-8') as f: + f.write(HEADER_HTML) f.write('