Skip to content

Commit

Permalink
v2.1.15: 修复scramble_id的默认值,优化缓存标志、debug-topic (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
hect0x7 authored Aug 22, 2023
1 parent 277bc6d commit 18ba10e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/jmcomic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# 被依赖方 <--- 使用方
# config <--- entity <--- toolkit <--- client <--- option <--- downloader

__version__ = '2.1.14'
__version__ = '2.1.15'

from .api import *
11 changes: 10 additions & 1 deletion src/jmcomic/jm_client_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def request_with_retry(self,
api_path=url,
domain=self.domain_list[domain_index],
)
jm_debug('api', url)
jm_debug(self.debug_topic_request(), url)
else:
# 图片url
pass
Expand All @@ -82,6 +82,10 @@ def request_with_retry(self,
else:
return self.request_with_retry(request, url, domain_index + 1, 0, **kwargs)

# noinspection PyMethodMayBeStatic
def debug_topic_request(self):
return 'html'

# noinspection PyMethodMayBeStatic, PyUnusedLocal
def before_retry(self, e, kwargs, retry_count, url):
jm_debug('req.err', str(e))
Expand Down Expand Up @@ -124,6 +128,11 @@ def wrap_func_cache(func_name, cache_dict_name):
}:
wrap_func_cache(func, func + '.cache.dict')

setattr(self, '__enable_cache__', True)

def is_cache_enabled(self) -> bool:
return getattr(self, '__enable_cache__', False)

def get_jmcomic_url(self, postman=None):
return JmModuleConfig.get_jmcomic_url(postman or self.get_root_postman())

Expand Down
10 changes: 6 additions & 4 deletions src/jmcomic/jm_client_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ def of_api_url(self, api_path, domain):
def enable_cache(self, debug=False):
raise NotImplementedError

def is_cache_enabled(self) -> bool:
raise NotImplementedError

def check_photo(self, photo: JmPhotoDetail):
"""
photo来源有两种:
Expand Down Expand Up @@ -221,7 +224,7 @@ class JmImageClient:
def download_image(self,
img_url: str,
img_save_path: str,
scramble_id=None,
scramble_id: Optional[int] = None,
decode_image=True,
):
"""
Expand All @@ -232,8 +235,7 @@ def download_image(self,
@param decode_image: 要保存的是解密后的图还是原图
"""
if scramble_id is None:
# 大多数情况下,scramble_id = photo_id
scramble_id = JmcomicText.parse_to_photo_id(scramble_id)
scramble_id = JmModuleConfig.SCRAMBLE_0

# 请求图片
resp = self.get_jm_image(img_url)
Expand All @@ -258,7 +260,7 @@ def download_by_image_detail(self,
return self.download_image(
image.download_url,
img_save_path,
image.scramble_id,
int(image.scramble_id),
decode_image=decode_image,
)

Expand Down

0 comments on commit 18ba10e

Please sign in to comment.