Fix handling when specified video length is too long

This commit is contained in:
taizan-hokuto
2020-01-26 15:11:29 +09:00
parent 5ba61db4f3
commit dea98c33d7

View File

@@ -65,24 +65,28 @@ class Downloader:
async def _create_block(session, pos, seektime): async def _create_block(session, pos, seektime):
continuation = arcparam.getparam( continuation = arcparam.getparam(
self.video_id, seektime = seektime) self.video_id, seektime = seektime)
url = f"{REPLAY_URL}{quote(continuation)}&pbj=1" url = f"{REPLAY_URL}{quote(continuation)}&pbj=1"
async with session.get(url, headers = headers) as resp: async with session.get(url, headers = headers) as resp:
text = await resp.text() text = await resp.text()
next_continuation, actions = parser.parse(json.loads(text)) next_continuation, actions = parser.parse(json.loads(text))
first = parser.get_offset(actions[0]) if actions:
last = parser.get_offset(actions[-1]) first = parser.get_offset(actions[0])
if self.callback: last = parser.get_offset(actions[-1])
self.callback(actions,last-first) if self.callback:
return Block( self.callback(actions,last-first)
pos = pos, return Block(
continuation = next_continuation, pos = pos,
chat_data = actions, continuation = next_continuation,
first = first, chat_data = actions,
last = last first = first,
) last = last
)
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
self.blocks = loop.run_until_complete( result = loop.run_until_complete(
_get_blocks(self.duration, self.div)) _get_blocks(self.duration, self.div))
self.blocks = [block for block in result if block]
return self return self
def remove_duplicate_head(self): def remove_duplicate_head(self):