diff --git a/DrissionPage/chromium_page.py b/DrissionPage/chromium_page.py index 4901f64..8009d16 100644 --- a/DrissionPage/chromium_page.py +++ b/DrissionPage/chromium_page.py @@ -451,7 +451,7 @@ class BrowserDownloadManager(object): page.set.download_path(page.download_path) self._page.browser_driver.set_listener('Browser.downloadProgress', self._onDownloadProgress) self._page.browser_driver.set_listener('Browser.downloadWillBegin', self._onDownloadWillBegin) - self._missions = set() + self._missions = {} @property def missions(self): @@ -462,7 +462,7 @@ class BrowserDownloadManager(object): :param mission: DownloadMission对象 :return: None """ - self._missions.add(mission) + self._missions[mission.id] = mission def cancel(self, mission): """取消一个下载任务 @@ -470,7 +470,7 @@ class BrowserDownloadManager(object): :return: None """ self._page.browser_driver.call_method('Browser.cancelDownload', guid=mission.id) - self._missions.remove(mission) + self._missions.pop(mission.id) def _onDownloadWillBegin(self, **kwargs): """用于获取弹出新标签页触发的下载任务""" @@ -482,7 +482,6 @@ class BrowserDownloadManager(object): """下载状态变化时执行""" if kwargs['guid'] in self._missions: mission = self._missions[kwargs['guid']] - # print(mission) if kwargs['state'] == 'inProgress': mission.state = 'running' mission.received_bytes = kwargs['receivedBytes'] @@ -492,15 +491,12 @@ class BrowserDownloadManager(object): mission.received_bytes = kwargs['receivedBytes'] mission.total_bytes = kwargs['totalBytes'] form_path = f'{self._page.download_path}\\{mission.id}' - to_path = get_usable_path(f'{mission.path}\\{mission.name}') + to_path = str(get_usable_path(f'{mission.path}\\{mission.name}')) move(form_path, to_path) - mission.final_path = to_path - mission.state = 'completed' - self._missions.pop(mission.id) + mission._set_done('completed', final_path=to_path) else: - mission.state = 'canceled' - self._missions.pop(mission.id) + mission._set_done('canceled') class Alert(object): diff --git a/DrissionPage/chromium_page.pyi b/DrissionPage/chromium_page.pyi index 52b6110..be96790 100644 --- a/DrissionPage/chromium_page.pyi +++ b/DrissionPage/chromium_page.pyi @@ -3,7 +3,7 @@ @Author : g1879 @Contact : g1879@qq.com """ -from typing import Union, Tuple, List, Dict, Optional, Set +from typing import Union, Tuple, List, Dict from .chromium_base import ChromiumBase from .chromium_driver import ChromiumDriver @@ -127,12 +127,12 @@ class ChromiumTabRect(object): class BrowserDownloadManager(object): _page: ChromiumPage = ... - _missions: Set[DownloadMission] = ... + _missions: Dict[str, DownloadMission] = ... def __init__(self, page: ChromiumPage): ... @property - def missions(self) -> Set[DownloadMission]: ... + def missions(self) -> Dict[str, DownloadMission]: ... def add_mission(self, mission: DownloadMission) -> None: ... diff --git a/DrissionPage/waiter.py b/DrissionPage/waiter.py index 1eae5a1..c8f73a4 100644 --- a/DrissionPage/waiter.py +++ b/DrissionPage/waiter.py @@ -247,7 +247,7 @@ class ChromiumPageWaiter(ChromiumBaseWaiter): if self._driver._dl_mgr._missions: if cancel_if_timeout: - for m in self._driver._dl_mgr._missions: + for m in self._driver._dl_mgr._missions.values(): m.cancel() return False else: