This commit is contained in:
taizan-hokuto
2020-02-02 22:36:26 +09:00
parent e8510f1116
commit 24f08ecbdb
15 changed files with 19553 additions and 26 deletions

View File

@@ -73,7 +73,6 @@ class LiveChatAsync:
'''
_setup_finished = False
_logger = config.logger(__name__)
def __init__(self, video_id,
seektime = 0,

View File

@@ -74,7 +74,6 @@ class LiveChat:
_setup_finished = False
#チャット監視中のListenerのリスト
_listeners = []
_logger = config.logger(__name__)
def __init__(self, video_id,
seektime = 0,

View File

@@ -13,12 +13,23 @@ headers = config.headers
REPLAY_URL = "https://www.youtube.com/live_chat_replay/" \
"get_live_chat_replay?continuation="
def _divide(start, end, count):
min_interval = 120
if (not isinstance(start,int) or
not isinstance(end,int) or
not isinstance(count,int)):
raise ValueError("start/end/count must be int")
def _split(start, end, count, min_interval = 120):
"""
Split section from `start` to `end` into `count` pieces,
and returns the beginning of each piece.
The `count` is adjusted so that the length of each piece
is no smaller than `min_interval`.
Returns:
--------
List of the beginning position of each piece.
"""
if not (isinstance(start,int) or isinstance(start,float)) or \
not (isinstance(end,int) or isinstance(end,float)):
raise ValueError("start/end must be int or float")
if not isinstance(count,int):
raise ValueError("count must be int")
if start>end:
raise ValueError("end must be equal to or greater than start.")
if count<1:
@@ -39,7 +50,7 @@ def ready_blocks(video_id, duration, div, callback):
async def _get_blocks( video_id, duration, div, callback):
async with aiohttp.ClientSession() as session:
futures = [_create_block(session, video_id, pos, seektime, callback)
for pos, seektime in enumerate(_divide(-1, duration, div))]
for pos, seektime in enumerate(_split(-1, duration, div))]
return await asyncio.gather(*futures,return_exceptions=True)
async def _create_block(session, video_id, pos, seektime, callback):

View File

@@ -3,27 +3,27 @@ class Block:
Parameter:
---------
pos : int
pos : int :
index of this block on block list.
first : int
first : int :
videoOffsetTimeMs of chat_data[0]
last : int
videoOffsetTimeMs of the last chat_data current read.
last : int :
videoOffsetTimeMs of the last chat_data.
(chat_data[-1])
this value increases as fetching chatdata progresses.
temp_last : int
temporary videoOffsetTimeMs of last chat data,
temp_last : int :
target videoOffsetTimeMs of last chat data for download,
equals to first videoOffsetTimeMs of next block.
when download worker reaches this offset, the download will stop.
when download worker reaches this offset, stop downloading.
continuation : str
continuation : str :
continuation param of last chat data.
chat_data : List
chat_data : List
"""
def __init__(self, pos=0, first=0, last=0,
continuation='', chat_data=[]):

View File

@@ -2,15 +2,15 @@ from . import parser
class DownloadWorker:
"""
DownloadWorker : associates a download session with a block.
DownloadWorker associates a download session with a block.
Parameter
----------
fetch : func
fetch :
download function of asyncdl
block : Block
chunk of chat_data
block :
Block object that includes chat_data
"""
def __init__(self, fetch, block):
self.block = block

View File

@@ -55,8 +55,9 @@ class Downloader:
return (
self.ready_blocks()
.remove_duplicate_head()
.set_temporary_last()
# .set_temporary_last()
.remove_overwrap()
.set_temporary_last()
.download_blocks()
.remove_duplicate_tail()
.combine()

View File

@@ -52,7 +52,6 @@ def duplicate_head(blocks):
and
type_0 == type_1
)
ret = [blocks[i] for i in range(len(blocks)-1)
if (len(blocks[i].chat_data)>0 and
not is_duplicate_head(i) )]
@@ -75,9 +74,9 @@ def duplicate_tail(blocks):
type_0 == type_1
)
ret = [blocks[i] for i in range(0,len(blocks)-1)
ret = [blocks[i] for i in range(0,len(blocks))
if i == 0 or not is_duplicate_tail(i) ]
ret.append(blocks[-1])
#ret.append(blocks[-1])
return ret
def overwrap(blocks):
@@ -103,3 +102,9 @@ def overwrap(blocks):
b = a+1
ret.append(blocks[-1])
return ret
def _dump(blocks):
print(__name__)
print(f"---------- first last temp_last {'':>3}---")
for i,block in enumerate(blocks):
print(f"block[{i:3}] {block.first:>10} {block.last:>10} {block.temp_last:>10}")