From f7ec14e166325cf4aee63587c6d9d4019da00a99 Mon Sep 17 00:00:00 2001 From: taizan-hokuto <55448286+taizan-hokuto@users.noreply.github.com> Date: Fri, 22 May 2020 02:27:52 +0900 Subject: [PATCH] Fix for #7 --- pytchat/tool/extract/duplcheck.py | 9 ++++++--- pytchat/tool/extract/extractor.py | 9 +++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pytchat/tool/extract/duplcheck.py b/pytchat/tool/extract/duplcheck.py index 2504e59..e94c011 100644 --- a/pytchat/tool/extract/duplcheck.py +++ b/pytchat/tool/extract/duplcheck.py @@ -70,7 +70,8 @@ def check_duplicate_offset(chatdata): if is_duplicate(i,i+1)] def remove_duplicate_head(blocks): - if len(blocks) == 1 : return blocks + if len(blocks) == 0 or len(blocks) == 1: + return blocks def is_duplicate_head(index): @@ -97,7 +98,8 @@ def remove_duplicate_head(blocks): return ret def remove_duplicate_tail(blocks): - if len(blocks) == 1 : return blocks + if len(blocks) == 0 or len(blocks) == 1: + return blocks def is_duplicate_tail(index): if len(blocks[index].chat_data) == 0: @@ -126,7 +128,8 @@ def remove_overlap(blocks): Align the last offset of each block to the first offset of next block (equals `end` offset of each block). """ - if len(blocks) == 1 : return blocks + if len(blocks) == 0 or len(blocks) == 1: + return blocks for block in blocks: if block.is_last: diff --git a/pytchat/tool/extract/extractor.py b/pytchat/tool/extract/extractor.py index 8052cd5..b3721b9 100644 --- a/pytchat/tool/extract/extractor.py +++ b/pytchat/tool/extract/extractor.py @@ -40,10 +40,11 @@ class Extractor: return self def _set_block_end(self): - for i in range(len(self.blocks)-1): - self.blocks[i].end = self.blocks[i+1].first - self.blocks[-1].end = self.duration*1000 - self.blocks[-1].is_last =True + if len(self.blocks) > 0: + for i in range(len(self.blocks)-1): + self.blocks[i].end = self.blocks[i+1].first + self.blocks[-1].end = self.duration*1000 + self.blocks[-1].is_last =True return self def _remove_overlap(self):