Implement cancell download
This commit is contained in:
@@ -8,6 +8,7 @@ from . dlworker import DownloadWorker
|
||||
from .. paramgen import arcparam
|
||||
from .. import config
|
||||
from urllib.parse import quote
|
||||
from concurrent.futures import CancelledError
|
||||
|
||||
headers = config.headers
|
||||
REPLAY_URL = "https://www.youtube.com/live_chat_replay/" \
|
||||
@@ -127,4 +128,24 @@ def download_chunk(callback, blocks, video_id):
|
||||
return [], continuation, None, None
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
try:
|
||||
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())
|
||||
|
||||
@@ -84,3 +84,6 @@ def download(video_id, div = 1, callback = None, processor = None):
|
||||
[{'video_id':None,'timeout':1,'chatdata' : [action
|
||||
["replayChatItemAction"]["actions"][0] for action in data]}]
|
||||
)
|
||||
|
||||
def cancel():
|
||||
asyncdl.cancel()
|
||||
|
||||
Reference in New Issue
Block a user