From c126d5b825a137e852ac2cec8cac8d3c1482cac0 Mon Sep 17 00:00:00 2001 From: taizan-hokuto <55448286+taizan-hokuto@users.noreply.github.com> Date: Sun, 26 Jan 2020 22:11:16 +0900 Subject: [PATCH] Cover all actions when checking id and type --- pytchat/tool/downloader.py | 18 +++++++++--------- pytchat/tool/parser.py | 5 ++--- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pytchat/tool/downloader.py b/pytchat/tool/downloader.py index def0a72..e79c36d 100644 --- a/pytchat/tool/downloader.py +++ b/pytchat/tool/downloader.py @@ -149,18 +149,18 @@ class Downloader: self.blocks = ret return self - def download_each_block(self): + def download_blocks(self): loop = asyncio.get_event_loop() - loop.run_until_complete(self._dl_block()) + loop.run_until_complete(self._dl_allocate()) return self - async def _dl_block(self): - futures = [] + async def _dl_allocate(self): + tasks = [] async with aiohttp.ClientSession() as session: - futures = [self._dl_chunk(session, block) for block in self.blocks] - return await asyncio.gather(*futures,return_exceptions=True) + tasks = [self._dl_task(session, block) for block in self.blocks] + return await asyncio.gather(*tasks,return_exceptions=True) - async def _dl_chunk(self, session, block:Block): + async def _dl_task(self, session, block:Block): if (block.temp_last != -1 and block.last > block.temp_last): return @@ -246,7 +246,7 @@ class Downloader: .remove_duplicate_head() .set_temporary_last() .remove_overwrap() - .download_each_block() + .download_blocks() .remove_duplicate_tail() .combine() - ) \ No newline at end of file + ) diff --git a/pytchat/tool/parser.py b/pytchat/tool/parser.py index 37bb6fd..8b046bd 100644 --- a/pytchat/tool/parser.py +++ b/pytchat/tool/parser.py @@ -49,10 +49,9 @@ def get_offset(item): return int(item['replayChatItemAction']["videoOffsetTimeMsec"]) def get_id(item): - #return list((list(item['replayChatItemAction']["actions"][0].values())[0])['item'].values())[0]['id'] - return list(item['replayChatItemAction']['actions'][0]['addChatItemAction']['item'].values())[0]['id'] + return list((list(item['replayChatItemAction']["actions"][0].values())[0])['item'].values())[0].get('id') def get_type(item): - return list(item['replayChatItemAction']["actions"][0]['addChatItemAction']['item'].keys())[0] + return list((list(item['replayChatItemAction']["actions"][0].values())[0])['item'].keys())[0]