From 0910ae83f54332c270b8c358e16eab7565b6a199 Mon Sep 17 00:00:00 2001 From: eight04 Date: Mon, 25 Mar 2024 08:05:46 +0800 Subject: [PATCH] Fix --- comiccrawler/download_manager.py | 2 +- comiccrawler/mods/__init__.py | 17 +++++++++++------ comiccrawler/mods/sankaku.py | 1 - comiccrawler/module_grabber.py | 7 +++++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/comiccrawler/download_manager.py b/comiccrawler/download_manager.py index 9a65c43..be16c6c 100644 --- a/comiccrawler/download_manager.py +++ b/comiccrawler/download_manager.py @@ -13,7 +13,7 @@ from os.path import join as path_join from time import time -from worker import Worker, current, await_, create_worker, async_, sleep +from worker import Worker, current, await_, create_worker, async_ from .analyzer import Analyzer from .safeprint import print diff --git a/comiccrawler/mods/__init__.py b/comiccrawler/mods/__init__.py index 7d4e1b1..417ca13 100644 --- a/comiccrawler/mods/__init__.py +++ b/comiccrawler/mods/__init__.py @@ -16,10 +16,16 @@ from ..grabber import cooldown from ..session_manager import session_manager -def setup_curl(mod): - for key, value in mod.config.items(): - if key.startswith("curl") and value: - session_manager.update_by_curl(value) +def setup_session(mod): + if getattr(mod, "autocurl", False): + for key, value in mod.config.items(): + if key.startswith("curl") and value: + session_manager.update_by_curl(value) + + # if cookie := getattr(mod, "cookie", {}): + # for key, value in cookie.items(): + # if value: + # session_manager.update_cookie(key, value) def import_module_file(ns, file): # pylint: disable=import-outside-toplevel @@ -127,8 +133,7 @@ def load_config(self): if hasattr(mod, "load_config"): mod.load_config() - # if getattr(mod, "autocurl", False): - # setup_curl(mod) + setup_session(mod) mod_loader = ModLoader() list_domain = mod_loader.list_domain diff --git a/comiccrawler/mods/sankaku.py b/comiccrawler/mods/sankaku.py index 936822d..6e391a6 100644 --- a/comiccrawler/mods/sankaku.py +++ b/comiccrawler/mods/sankaku.py @@ -6,7 +6,6 @@ from ..core import Episode from ..error import PauseDownloadError, SkipEpisodeError -from ..grabber import grabhtml domain = ["chan.sankakucomplex.com"] name = "Sankaku" diff --git a/comiccrawler/module_grabber.py b/comiccrawler/module_grabber.py index e963855..a20f2f4 100644 --- a/comiccrawler/module_grabber.py +++ b/comiccrawler/module_grabber.py @@ -2,6 +2,10 @@ from .grabber import grabhtml, grabimg +def purify_cookie(cookie): + """Remove empty cookie value.""" + return {key: value for key, value in cookie.items() if value and "請" not in value} + class ModuleGrabber: """Bind grabber with module's header, cookie...""" def __init__(self, mod): @@ -16,7 +20,7 @@ def img(self, url, **kwargs): def grab(self, grab_method, url=None, **kwargs): new_kwargs = { "header": self.get_header(), - "cookie": self.get_cookie(), + "cookie": purify_cookie(self.get_cookie()), "done": self.handle_grab, "proxy": self.mod.config.get("proxy"), "verify": self.mod.config.getboolean("verify", True) @@ -35,7 +39,6 @@ def get_header(self): def get_cookie(self): """Return downloader cookie.""" - return {} cookie = getattr(self.mod, "cookie", {}) config = getattr(self.mod, "config", {})