From 2c598bc8f7a33b21caf66db0a189f17c7d4d2b9b Mon Sep 17 00:00:00 2001 From: taizan-hokuto <55448286+taizan-hokuto@users.noreply.github.com> Date: Sun, 9 Feb 2020 15:14:33 +0900 Subject: [PATCH] Change construct method of videoinfo --- pytchat/tool/__init__.py | 3 --- pytchat/tool/downloader.py | 4 ++-- pytchat/tool/duplcheck.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/pytchat/tool/__init__.py b/pytchat/tool/__init__.py index c00d315..e69de29 100644 --- a/pytchat/tool/__init__.py +++ b/pytchat/tool/__init__.py @@ -1,3 +0,0 @@ -from . videoinfo import VideoInfo -def videoinfo(video_id): - return VideoInfo(video_id) \ No newline at end of file diff --git a/pytchat/tool/downloader.py b/pytchat/tool/downloader.py index 4cd363e..d82f0d5 100644 --- a/pytchat/tool/downloader.py +++ b/pytchat/tool/downloader.py @@ -1,8 +1,8 @@ from . import asyncdl from . import parser -from . import videoinfo from . block import Block from . duplcheck import duplicate_head, duplicate_tail, overwrap +from . videoinfo import VideoInfo from .. import config from .. exceptions import InvalidVideoIdException @@ -65,7 +65,7 @@ class Downloader: def download(video_id, div = 20, callback=None, processor = None): duration = 0 try: - duration = videoinfo(video_id).get("duration") + duration = VideoInfo(video_id).get("duration") except InvalidVideoIdException: raise if duration == 0: diff --git a/pytchat/tool/duplcheck.py b/pytchat/tool/duplcheck.py index b1ceffd..637e617 100644 --- a/pytchat/tool/duplcheck.py +++ b/pytchat/tool/duplcheck.py @@ -37,6 +37,41 @@ def check_duplicate(chatdata): for i in range(max_range) for j in range(i+1,max_range) if is_duplicate(i,j)] + +def check_duplicate_offset(chatdata): + max_range = len(chatdata) + tbl_offset = [None] * max_range + tbl_id = [None] * max_range + tbl_type = [None] * max_range + + def create_table(chatdata, max_range): + for i in range(max_range): + tbl_offset[i] = parser.get_offset(chatdata[i]) + tbl_id[i] = parser.get_id(chatdata[i]) + tbl_type[i] = parser.get_type(chatdata[i]) + + def is_duplicate(i, j): + return ( + tbl_offset[i] == tbl_offset[j] + and + tbl_id[i] == tbl_id[j] + # and + # tbl_type[i] == tbl_type[j] + ) + + print("creating table...") + create_table(chatdata,max_range) + print("searching duplicate data...") + + return [{ + "index" : i, "id" : tbl_id[i], + "offsetTime" : tbl_offset[i], + "type:" : tbl_type[i] + + } + for i in range(max_range-1) + if is_duplicate(i,i+1)] + def duplicate_head(blocks): if len(blocks) == 1 : return blocks