Implement cancell download

This commit is contained in:
taizan-hokuto
2020-02-13 21:15:39 +09:00
parent b1292b4329
commit 6fdb3bf8cf
2 changed files with 25 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ from . dlworker import DownloadWorker
from .. paramgen import arcparam from .. paramgen import arcparam
from .. import config from .. import config
from urllib.parse import quote from urllib.parse import quote
from concurrent.futures import CancelledError
headers = config.headers headers = config.headers
REPLAY_URL = "https://www.youtube.com/live_chat_replay/" \ REPLAY_URL = "https://www.youtube.com/live_chat_replay/" \
@@ -127,4 +128,24 @@ def download_chunk(callback, blocks, video_id):
return [], continuation, None, None return [], continuation, None, None
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
try:
loop.run_until_complete(_allocate_workers()) loop.run_until_complete(_allocate_workers())
except CancelledError:
pass
async def shutdown():
print("\nshutdown...")
tasks = [t for t in asyncio.all_tasks()
if t is not asyncio.current_task()]
for task in tasks:
task.cancel()
try:
await task
except asyncio.CancelledError:
pass
def cancel():
loop = asyncio.get_event_loop()
loop.create_task(shutdown())

View File

@@ -84,3 +84,6 @@ def download(video_id, div = 1, callback = None, processor = None):
[{'video_id':None,'timeout':1,'chatdata' : [action [{'video_id':None,'timeout':1,'chatdata' : [action
["replayChatItemAction"]["actions"][0] for action in data]}] ["replayChatItemAction"]["actions"][0] for action in data]}]
) )
def cancel():
asyncdl.cancel()