-
Notifications
You must be signed in to change notification settings - Fork 10k
v2.5.25: 支持Client直接下载无混淆图片,添加docs示例 #312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe pull request introduces enhancements to the Changes
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (6)
assets/docs/sources/tutorial/0_common_usage.md (1)
63-67: Enhance the image download examples with more context and best practices.While the examples demonstrate the basic functionality, consider the following improvements to make the documentation more comprehensive:
- Add comments explaining when to use each download method (image_detail vs direct URL)
- Include error handling examples specific to image downloads
- Use more meaningful file paths in examples
- Document the file overwriting behavior
Consider updating the example like this:
# 下载单个图片 - client.download_by_image_detail(image, './a.jpg') + # 方法1:使用image_detail对象下载(支持自动解密混淆的图片) + output_path = f'./downloads/{image.photo_id}_{image.img_id}.jpg' + try: + client.download_by_image_detail(image, output_path) + except JmcomicException as e: + print(f'下载图片失败: {e}') + # 如果是已知未混淆的图片,也可以直接使用url来下载 random_image_domain = JmModuleConfig.DOMAIN_IMAGE_LIST - client.download_image(f'https://{random_image_domain}/media/albums/416130.jpg', './a.jpg') + # 方法2:直接使用URL下载(仅支持未混淆的图片) + direct_url = f'https://{random_image_domain}/media/albums/416130.jpg' + output_path = './downloads/direct_download.jpg' + try: + client.download_image(direct_url, output_path) + except JmcomicException as e: + print(f'直接下载图片失败: {e}')src/jmcomic/jm_client_interface.py (1)
Line range hint
279-286: Update method documentation to reflect new behaviorThe docstring should be updated to clarify that when
scramble_idis None, the image will not be decoded regardless of thedecode_imageparameter value. This helps users understand the new behavior.Apply this diff to update the documentation:
def download_image(self, img_url: str, img_save_path: str, scramble_id: Optional[int] = None, decode_image=True, ): """ 下载JM的图片 :param img_url: 图片url :param img_save_path: 图片保存位置 - :param scramble_id: 图片所在photo的scramble_id + :param scramble_id: 图片所在photo的scramble_id。当为None时,图片将不会被解密,无视decode_image参数 :param decode_image: 要保存的是解密后的图还是原图 """🧰 Tools
🪛 Ruff (0.8.0)
68-68:
JmImageToolmay be undefined, or defined from star imports(F405)
src/jmcomic/jm_toolkit.py (4)
Line range hint
789-799: Security: Consider using a more secure AES modeThe current implementation uses AES-ECB mode which is vulnerable to pattern analysis. Consider using AES-CBC or AES-GCM modes instead, as they provide better security guarantees.
Line range hint
752-761: Security: Avoid hardcoding secrets in the codeThe token generation logic uses hardcoded secrets. Consider:
- Moving secrets to environment variables or a secure configuration management system
- Implementing secret rotation mechanisms
Line range hint
573-636: Performance: Optimize image processing logicThe
decode_and_savemethod could be optimized:
- Consider using numpy for faster image manipulation
- Implement batch processing for multiple images
- Add memory management for large images
@classmethod def decode_and_save(cls, num: int, img_src: Image, decoded_save_path: str ) -> None: + import numpy as np if num == 0: cls.save_image(img_src, decoded_save_path) return - import math w, h = img_src.size + # Convert to numpy array for faster processing + img_array = np.array(img_src) - # Create new image - img_decode = Image.new("RGB", (w, h)) over = h % num - for i in range(num): - move = math.floor(h / num) - y_src = h - (move * (i + 1)) - over - y_dst = move * i + move = h // num + # Pre-allocate the output array + output = np.zeros_like(img_array)
Line range hint
466-471: Maintainability: Add type hints for better code clarityConsider adding type hints to improve code maintainability and IDE support:
@classmethod -def parse_to_jm_id(cls, text) -> str: +def parse_to_jm_id(cls, text: Union[int, str]) -> str: if isinstance(text, int): return str(text)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
assets/docs/sources/tutorial/0_common_usage.md(2 hunks)src/jmcomic/__init__.py(1 hunks)src/jmcomic/jm_client_interface.py(1 hunks)src/jmcomic/jm_toolkit.py(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- src/jmcomic/init.py
🔇 Additional comments (3)
assets/docs/sources/tutorial/0_common_usage.md (1)
41-41: LGTM! Clear and descriptive section heading.
The updated heading accurately reflects the section's expanded content to include image downloading functionality.
src/jmcomic/jm_client_interface.py (1)
66-66:
Breaking Change: Modified image decoding condition
The condition for skipping image decoding has been expanded to include cases where scramble_id is None. This change aligns with supporting direct downloads of unscrambled images but may affect existing code that relies on the previous behavior.
Let's verify the impact of this change:
src/jmcomic/jm_toolkit.py (1)
9-9: LGTM: Pattern update handles both singular and plural forms
The regex pattern modification correctly accommodates both singular and plural forms of 'photo' and 'album' paths.
Summary by CodeRabbit
scramble_id.