Skip to content
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

功能需求:过滤重复图片 #245

Merged
merged 8 commits into from
May 27, 2024
Merged

功能需求:过滤重复图片 #245

merged 8 commits into from
May 27, 2024

Conversation

hect0x7
Copy link
Owner

@hect0x7 hect0x7 commented May 24, 2024

Summary by CodeRabbit

  • New Features

    • Introduced delete_duplicated_files plugin to automatically identify and delete duplicate files based on MD5 hashes after each download.
    • Added parameters for the plugin to specify the limit of duplicates and whether to delete the original file.
  • Documentation

    • Updated documentation to include details about the new delete_duplicated_files plugin and its parameters.
  • Enhancements

    • Improved image saving functionality to handle JmImageResp objects, ensuring better compatibility and performance.

Copy link

coderabbitai bot commented May 24, 2024

Walkthrough

The updates introduce a new plugin, DeleteDuplicatedFilesPlugin, to identify and delete duplicate files based on MD5 hashes in a specified folder. The changes include new methods for calculating MD5 hashes, finding duplicates, and deleting them. Additionally, the documentation and configuration files have been updated to include this plugin and its parameters, ensuring it integrates seamlessly into the existing workflow.

Changes

File(s) Change Summary
src/jmcomic/jm_plugin.py Added methods for calculating MD5 hashes, finding duplicates, and deleting duplicate files in DeleteDuplicatedFilesPlugin.
assets/docs/sources/option_file_syntax.md Documented the new delete_duplicated_files plugin with parameters limit and delete_original_file.
assets/option/option_workflow_download.yml Introduced the delete_duplicated_files plugin to the download workflow with specific parameters.
src/jmcomic/jm_toolkit.py Updated save_resp_img to accept JmImageResp objects and modified the decode_and_save function to use the save_image method.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant Plugin
    participant FileSystem

    User->>Plugin: invoke(limit, album, downloader, delete_original_file)
    Plugin->>FileSystem: find_duplicate_files(root_folder)
    FileSystem-->>Plugin: Duplicate file list
    Plugin->>FileSystem: delete_duplicate_files(duplicate_list, limit)
    FileSystem-->>Plugin: Deletion confirmation
    Plugin-->>User: Process completion notification
Loading

In the realm of bytes and code,
A rabbit hops, a tale is told.
Duplicates now meet their end,
With MD5, their fate we mend.
A cleaner world, a lighter load,
Thanks to the path this plugin showed. 🐇✨

Tip

New Features and Improvements

Review Settings

Introduced new personality profiles for code reviews. Users can now select between "Chill" and "Assertive" review tones to tailor feedback styles according to their preferences. The "Assertive" profile posts more comments and nitpicks the code more aggressively, while the "Chill" profile is more relaxed and posts fewer comments.

AST-based Instructions

CodeRabbit offers customizing reviews based on the Abstract Syntax Tree (AST) pattern matching. Read more about AST-based instructions in the documentation.

Community-driven AST-based Rules

We are kicking off a community-driven initiative to create and share AST-based rules. Users can now contribute their AST-based rules to detect security vulnerabilities, code smells, and anti-patterns. Please see the ast-grep-essentials repository for more information.

New Static Analysis Tools

We are continually expanding our support for static analysis tools. We have added support for biome, hadolint, and ast-grep. Update the settings in your .coderabbit.yaml file or head over to the settings page to enable or disable the tools you want to use.

Tone Settings

Users can now customize CodeRabbit to review code in the style of their favorite characters or personalities. Here are some of our favorite examples:

  • Mr. T: "You must talk like Mr. T in all your code reviews. I pity the fool who doesn't!"
  • Pirate: "Arr, matey! Ye must talk like a pirate in all yer code reviews. Yarrr!"
  • Snarky: "You must be snarky in all your code reviews. Snark, snark, snark!"

Revamped Settings Page

We have redesigned the settings page for a more intuitive layout, enabling users to find and adjust settings quickly. This change was long overdue; it not only improves the user experience but also allows our development team to add more settings in the future with ease. Going forward, the changes to .coderabbit.yaml will be reflected in the settings page, and vice versa.

Miscellaneous

  • Turn off free summarization: You can switch off free summarization of PRs opened by users not on a paid plan using the enable_free_tier setting.
  • Knowledge-base scope: You can now set the scope of the knowledge base to either the repository (local) or the organization (global) level using the knowledge_base setting. In addition, you can specify Jira project keys and Linear team keys to limit the knowledge base scope for those integrations.
  • High-level summary placement: You can now customize the location of the high-level summary in the PR description using the high_level_summary_placeholder setting (default @coderabbitai summary).
  • Revamped request changes workflow: You can now configure CodeRabbit to auto-approve or request changes on PRs based on the review feedback using the request_changes_workflow setting.

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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to full the review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hect0x7 hect0x7 linked an issue May 24, 2024 that may be closed by this pull request
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range and nitpick comments (2)
src/jmcomic/__init__.py (1)

Line range hint 14-28: Ensure all types and classes used are explicitly imported to avoid runtime errors.

+ from typing import Dict, Any
+ from .jm_module_config import JmModuleConfig
+ from .jmcomic_client import JmcomicClient
+ from .jm_option_plugin import JmOptionPlugin
src/jmcomic/jm_option.py (1)

Line range hint 1-655: Replace star imports with explicit imports to ensure all names are defined and improve maintainability.

- from .jm_client_impl import *
+ from .jm_client_impl import SpecificClass1, SpecificClass2

Ensure all types and classes used are explicitly imported to avoid runtime errors.

+ from typing import Union, Callable, Tuple, List, Dict, Optional
+ from .jm_album_detail import JmAlbumDetail
+ from .jm_photo_detail import JmPhotoDetail
+ from .jm_image_detail import JmImageDetail
+ from .jm_html_client import JmHtmlClient
+ from .jm_api_client import JmApiClient
+ from .jmcomic_client import JmcomicClient
+ from .exception_tool import ExceptionTool
+ from .jmcomic_text import JmcomicText
+ from .detail_entity import DetailEntity
+ from .jm_option_plugin import JmOptionPlugin
+ from .jmcomic_exception import JmcomicException
+ from .packer_util import PackerUtil
+ from .postmans import Postmans
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between e0652a9 and 5896d7a.
Files selected for processing (3)
  • src/jmcomic/init.py (1 hunks)
  • src/jmcomic/jm_config.py (1 hunks)
  • src/jmcomic/jm_option.py (5 hunks)
Additional Context Used
Ruff (113)
src/jmcomic/__init__.py (8)

7-7: from .api import * used; unable to detect undefined names


8-8: from .jm_plugin import * used; unable to detect undefined names


14-14: Dict may be undefined, or defined from star imports


14-14: Any may be undefined, or defined from star imports


22-22: JmModuleConfig may be undefined, or defined from star imports


23-23: JmcomicClient may be undefined, or defined from star imports


27-27: JmModuleConfig may be undefined, or defined from star imports


28-28: JmOptionPlugin may be undefined, or defined from star imports

src/jmcomic/jm_option.py (105)

1-1: from .jm_client_impl import * used; unable to detect undefined names


22-22: JmcomicClient may be undefined, or defined from star imports


23-23: Union may be undefined, or defined from star imports


23-23: Callable may be undefined, or defined from star imports


53-53: ExceptionTool may be undefined, or defined from star imports


56-56: Callable may be undefined, or defined from star imports


73-73: Union may be undefined, or defined from star imports


73-73: JmAlbumDetail may be undefined, or defined from star imports


73-73: JmPhotoDetail may be undefined, or defined from star imports


74-74: Callable may be undefined, or defined from star imports


75-75: Tuple may be undefined, or defined from star imports


76-76: List may be undefined, or defined from star imports


79-79: JmcomicText may be undefined, or defined from star imports


85-85: JmAlbumDetail may be undefined, or defined from star imports


86-86: JmPhotoDetail may be undefined, or defined from star imports


94-94: jm_log may be undefined, or defined from star imports


99-99: fix_filepath may be undefined, or defined from star imports


101-101: JmAlbumDetail may be undefined, or defined from star imports


113-113: jm_log may be undefined, or defined from star imports


118-118: fix_filepath may be undefined, or defined from star imports


126-126: List may be undefined, or defined from star imports


136-136: ExceptionTool may be undefined, or defined from star imports


143-143: List may be undefined, or defined from star imports


153-153: ExceptionTool may be undefined, or defined from star imports


156-156: Optional may be undefined, or defined from star imports


162-162: fix_windir_name may be undefined, or defined from star imports


162-162: DetailEntity may be undefined, or defined from star imports


197-197: Dict may be undefined, or defined from star imports


198-198: Dict may be undefined, or defined from star imports


199-199: Dict may be undefined, or defined from star imports


200-200: Dict may be undefined, or defined from star imports


207-207: AdvancedDict may be undefined, or defined from star imports


209-209: AdvancedDict may be undefined, or defined from star imports


211-211: AdvancedDict may be undefined, or defined from star imports


239-239: JmPhotoDetail may be undefined, or defined from star imports


243-243: JmAlbumDetail may be undefined, or defined from star imports


247-247: JmImageDetail may be undefined, or defined from star imports


254-254: JmImageDetail may be undefined, or defined from star imports


274-274: mkdir_if_not_exists may be undefined, or defined from star imports


278-278: JmModuleConfig may be undefined, or defined from star imports


279-279: jm_log may be undefined, or defined from star imports


281-281: mkdir_if_not_exists may be undefined, or defined from star imports


285-285: JmImageDetail may be undefined, or defined from star imports


289-289: os may be undefined, or defined from star imports


289-289: fix_windir_name may be undefined, or defined from star imports


291-291: JmImageDetail may be undefined, or defined from star imports


294-294: JmImageDetail may be undefined, or defined from star imports


306-306: Dict may be undefined, or defined from star imports


307-307: JmModuleConfig may be undefined, or defined from star imports


317-317: Dict may be undefined, or defined from star imports


323-323: disable_jm_log may be undefined, or defined from star imports


328-328: JmModuleConfig may be undefined, or defined from star imports


352-352: Dict may be undefined, or defined from star imports


354-354: JmModuleConfig may be undefined, or defined from star imports


355-355: JmModuleConfig may be undefined, or defined from star imports


371-371: PackerUtil may be undefined, or defined from star imports


379-379: ExceptionTool may be undefined, or defined from star imports


381-381: PackerUtil may be undefined, or defined from star imports


387-387: field_cache may be undefined, or defined from star imports


396-396: Union may be undefined, or defined from star imports


396-396: JmHtmlClient may be undefined, or defined from star imports


396-396: JmApiClient may be undefined, or defined from star imports


433-433: str_to_list may be undefined, or defined from star imports


446-446: Postmans may be undefined, or defined from star imports


449-449: JmModuleConfig may be undefined, or defined from star imports


450-450: AbstractJmClient may be undefined, or defined from star imports


450-450: AbstractJmClient may be undefined, or defined from star imports


453-453: AbstractJmClient may be undefined, or defined from star imports


467-467: Optional may be undefined, or defined from star imports


467-467: Dict may be undefined, or defined from star imports


475-475: List may be undefined, or defined from star imports


479-479: JmApiClient may be undefined, or defined from star imports


481-481: JmModuleConfig may be undefined, or defined from star imports


483-483: JmHtmlClient may be undefined, or defined from star imports


485-485: JmModuleConfig may be undefined, or defined from star imports


488-488: JmModuleConfig may be undefined, or defined from star imports


490-490: ExceptionTool may be undefined, or defined from star imports


493-493: Type may be undefined, or defined from star imports


493-493: JmcomicClient may be undefined, or defined from star imports


497-497: JmModuleConfig may be undefined, or defined from star imports


531-531: List may be undefined, or defined from star imports


538-538: JmModuleConfig may be undefined, or defined from star imports


541-541: Optional may be undefined, or defined from star imports


541-541: Type may be undefined, or defined from star imports


543-543: ExceptionTool may be undefined, or defined from star imports


549-549: traceback_print_exec may be undefined, or defined from star imports


553-553: Optional may be undefined, or defined from star imports


553-553: Dict may be undefined, or defined from star imports


563-563: Type may be undefined, or defined from star imports


564-564: Optional may be undefined, or defined from star imports


574-574: jm_log may be undefined, or defined from star imports


583-583: JmcomicException may be undefined, or defined from star imports


604-604: jm_log may be undefined, or defined from star imports


618-618: jm_log may be undefined, or defined from star imports


624-624: jm_log may be undefined, or defined from star imports


628-628: Optional may be undefined, or defined from star imports


628-628: Dict may be undefined, or defined from star imports


628-628: Dict may be undefined, or defined from star imports


628-628: Any may be undefined, or defined from star imports


636-636: ExceptionTool may be undefined, or defined from star imports


642-642: Dict may be undefined, or defined from star imports


642-642: Any may be undefined, or defined from star imports


646-646: JmcomicText may be undefined, or defined from star imports


655-655: jm_log may be undefined, or defined from star imports


659-659: ExceptionTool may be undefined, or defined from star imports

Additional comments not posted (4)
src/jmcomic/__init__.py (1)

5-5: Version update from '2.5.11' to '2.5.13' is correctly implemented.

src/jmcomic/jm_config.py (2)

112-122: Domain list updates are correctly implemented as per the PR objectives.


Line range hint 1-381: Other configurations in jm_config.py are correctly maintained.

src/jmcomic/jm_option.py (1)

Line range hint 1-655: Other modifications in option handling are correctly implemented.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Outside diff range and nitpick comments (28)
src/jmcomic/__init__.py (2)

Line range hint 14-14: Ensure that Dict, Any, and JmModuleConfig are explicitly imported to avoid runtime errors.

+ from typing import Dict, Any
+ from .jm_config import JmModuleConfig

Also applies to: 22-22, 27-27


Line range hint 23-23: Ensure that JmcomicClient and JmOptionPlugin are explicitly imported to avoid runtime errors.

+ from .jm_client_interface import JmcomicClient
+ from .jm_plugin import JmOptionPlugin

Also applies to: 28-28

src/jmcomic/jm_client_interface.py (18)

Line range hint 1-1: Replace star imports with explicit imports to improve code clarity and maintainability.

- from .jm_toolkit import *
+ from .jm_toolkit import SpecificFunction1, SpecificFunction2

Line range hint 13-13: Ensure that ExceptionTool is explicitly imported to avoid runtime errors.

+ from .jm_toolkit import ExceptionTool

Also applies to: 42-42, 89-89


Line range hint 55-55: Remove unnecessary f-string as it contains no placeholders.

- msg = f'禁漫图片获取失败: [{self.url}]'
+ msg = '禁漫图片获取失败: [{self.url}]'

Line range hint 68-68: Ensure that JmImageTool is explicitly imported to avoid runtime errors.

+ from .jm_toolkit import JmImageTool

Also applies to: 75-75, 76-76, 77-77


Line range hint 71-71: Ensure that suffix_not_equal is explicitly imported to avoid runtime errors.

+ from .jm_toolkit import suffix_not_equal

Line range hint 84-84: Ensure that field_cache is explicitly imported to avoid runtime errors.

+ from .jm_toolkit import field_cache

Line range hint 85-85: Ensure that Dict and Any are explicitly imported from the typing module to avoid runtime errors.

+ from typing import Dict, Any

Also applies to: 115-115, 461-461, 464-464


Line range hint 91-91: Ensure that AdvancedDict is explicitly imported to avoid runtime errors.

+ from .jm_toolkit import AdvancedDict

Also applies to: 92-92, 121-121, 123-123


Line range hint 108-108: Ensure that JmCryptoTool is explicitly imported to avoid runtime errors.

+ from .jm_toolkit import JmCryptoTool

Line range hint 142-142: Ensure that JmAlbumDetail and JmPhotoDetail are explicitly imported to avoid runtime errors.

+ from .jm_entities import JmAlbumDetail, JmPhotoDetail

Also applies to: 149-149, 152-152


Line range hint 208-208: Ensure that JmMagicConstants is explicitly imported to avoid runtime errors.

+ from .jm_constants import JmMagicConstants

Also applies to: 249-249, 320-320, 321-321, 331-331, 332-332, 342-342, 343-343, 353-353, 354-354, 364-364, 365-365, 400-400, 406-406, 408-408, 413-413, 419-419, 421-421, 426-426, 432-432, 434-434, 504-504, 523-523, 524-524, 561-561, 562-562, 563-563


Line range hint 238-238: Ensure that Optional is explicitly imported from the typing module to avoid runtime errors.

+ from typing import Optional

Also applies to: 483-483


Line range hint 211-211: Ensure that JmFavoritePage, JmCategoryPage, and JmSearchPage are explicitly imported to avoid runtime errors.

+ from .jm_entities import JmFavoritePage, JmCategoryPage, JmSearchPage

Also applies to: 387-387, 507-507, 564-564


Line range hint 263-263: Ensure that JmImageDetail is explicitly imported to avoid runtime errors.

+ from .jm_entities import JmImageDetail

Line range hint 445-445: Ensure that Postman is explicitly imported to avoid runtime errors.

+ from .jm_toolkit import Postman

Line range hint 449-449: Ensure that List is explicitly imported from the typing module to avoid runtime errors.

+ from typing import List

Also applies to: 455-455


Line range hint 471-471: Ensure that JmModuleConfig is explicitly imported to avoid runtime errors.

+ from .jm_config import JmModuleConfig

Also applies to: 474-474, 477-477


Line range hint 576-576: Ensure that Type is explicitly imported from the typing module to avoid runtime errors.

+ from typing import Type
src/jmcomic/jm_toolkit.py (8)

Line range hint 3-3: Avoid using wildcard imports to prevent namespace pollution and improve code clarity.

- from .jm_exception import *
+ from .jm_exception import ExceptionTool

Line range hint 66-66: Ensure all referenced classes and modules are explicitly imported to avoid runtime errors.

+ from typing import List, Union, Pattern, Callable, Match
+ from .jm_config import JmModuleConfig
+ from .jm_data_types import JmPhotoDetail, JmAlbumDetail

Also applies to: 76-76, 83-83, 99-99, 102-102, 111-111, 115-115, 119-119, 123-123, 129-129


Line range hint 206-206: Explicitly import required types to ensure type checking and avoid runtime errors.

+ from typing import Dict, Pattern, Callable, Match

Also applies to: 213-213, 218-218


Line range hint 327-327: Explicitly import the Pattern type to ensure type checking and avoid runtime errors.

+ from typing import Pattern

Also applies to: 332-332, 344-344


Line range hint 399-399: Ensure all referenced classes and modules are explicitly imported to avoid runtime errors.

+ from .jm_data_types import JmSearchPage, JmFavoritePage, AdvancedDict

Also applies to: 431-431, 434-434, 449-449, 452-452, 472-472, 475-475, 501-501, 504-504, 545-545, 549-549


Line range hint 620-620: Ensure all referenced classes and modules are explicitly imported to avoid runtime errors.

+ from .jm_data_types import JmAlbumDetail, JmPhotoDetail

Also applies to: 632-632, 656-656


Line range hint 704-704: Explicitly import the Any type to ensure type checking and avoid runtime errors.

+ from typing import Any

Line range hint 805-805: Ensure all referenced constants and modules are explicitly imported to avoid runtime errors.

+ from .jm_constants import JmMagicConstants

Also applies to: 809-809, 858-858, 861-861, 886-886

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 5896d7a and cb9bb3a.
Files selected for processing (4)
  • src/jmcomic/init.py (1 hunks)
  • src/jmcomic/jm_client_interface.py (1 hunks)
  • src/jmcomic/jm_plugin.py (1 hunks)
  • src/jmcomic/jm_toolkit.py (2 hunks)
Additional Context Used
Ruff (243)
src/jmcomic/__init__.py (8)

7-7: from .api import * used; unable to detect undefined names


8-8: from .jm_plugin import * used; unable to detect undefined names


14-14: Dict may be undefined, or defined from star imports


14-14: Any may be undefined, or defined from star imports


22-22: JmModuleConfig may be undefined, or defined from star imports


23-23: JmcomicClient may be undefined, or defined from star imports


27-27: JmModuleConfig may be undefined, or defined from star imports


28-28: JmOptionPlugin may be undefined, or defined from star imports

src/jmcomic/jm_client_interface.py (79)

1-1: from .jm_toolkit import * used; unable to detect undefined names


13-13: ExceptionTool may be undefined, or defined from star imports


42-42: ExceptionTool may be undefined, or defined from star imports


55-55: f-string without any placeholders


68-68: JmImageTool may be undefined, or defined from star imports


71-71: suffix_not_equal may be undefined, or defined from star imports


75-75: JmImageTool may be undefined, or defined from star imports


76-76: JmImageTool may be undefined, or defined from star imports


77-77: JmImageTool may be undefined, or defined from star imports


84-84: field_cache may be undefined, or defined from star imports


85-85: Dict may be undefined, or defined from star imports


89-89: ExceptionTool may be undefined, or defined from star imports


89-89: JsonResolveFailException may be undefined, or defined from star imports


91-91: AdvancedDict may be undefined, or defined from star imports


92-92: AdvancedDict may be undefined, or defined from star imports


106-106: field_cache may be undefined, or defined from star imports


108-108: JmCryptoTool may be undefined, or defined from star imports


115-115: Any may be undefined, or defined from star imports


121-121: AdvancedDict may be undefined, or defined from star imports


123-123: AdvancedDict may be undefined, or defined from star imports


142-142: JmAlbumDetail may be undefined, or defined from star imports


149-149: JmPhotoDetail may be undefined, or defined from star imports


152-152: JmPhotoDetail may be undefined, or defined from star imports


208-208: JmMagicConstants may be undefined, or defined from star imports


211-211: JmFavoritePage may be undefined, or defined from star imports


238-238: Optional may be undefined, or defined from star imports


249-249: JmMagicConstants may be undefined, or defined from star imports


263-263: JmImageDetail may be undefined, or defined from star imports


311-311: JmSearchPage may be undefined, or defined from star imports


320-320: JmMagicConstants may be undefined, or defined from star imports


321-321: JmMagicConstants may be undefined, or defined from star imports


331-331: JmMagicConstants may be undefined, or defined from star imports


332-332: JmMagicConstants may be undefined, or defined from star imports


342-342: JmMagicConstants may be undefined, or defined from star imports


343-343: JmMagicConstants may be undefined, or defined from star imports


353-353: JmMagicConstants may be undefined, or defined from star imports


354-354: JmMagicConstants may be undefined, or defined from star imports


364-364: JmMagicConstants may be undefined, or defined from star imports


365-365: JmMagicConstants may be undefined, or defined from star imports


387-387: JmCategoryPage may be undefined, or defined from star imports


400-400: JmMagicConstants may be undefined, or defined from star imports


406-406: JmMagicConstants may be undefined, or defined from star imports


408-408: JmMagicConstants may be undefined, or defined from star imports


413-413: JmMagicConstants may be undefined, or defined from star imports


419-419: JmMagicConstants may be undefined, or defined from star imports


421-421: JmMagicConstants may be undefined, or defined from star imports


426-426: JmMagicConstants may be undefined, or defined from star imports


432-432: JmMagicConstants may be undefined, or defined from star imports


434-434: JmMagicConstants may be undefined, or defined from star imports


445-445: Postman may be undefined, or defined from star imports


449-449: List may be undefined, or defined from star imports


455-455: List may be undefined, or defined from star imports


461-461: Optional may be undefined, or defined from star imports


461-461: Dict may be undefined, or defined from star imports


464-464: Optional may be undefined, or defined from star imports


464-464: Dict may be undefined, or defined from star imports


471-471: JmModuleConfig may be undefined, or defined from star imports


474-474: JmModuleConfig may be undefined, or defined from star imports


477-477: JmModuleConfig may be undefined, or defined from star imports


483-483: Optional may be undefined, or defined from star imports


483-483: Dict may be undefined, or defined from star imports


483-483: JmPageContent may be undefined, or defined from star imports


487-487: ExceptionTool may be undefined, or defined from star imports


504-504: JmMagicConstants may be undefined, or defined from star imports


507-507: Generator may be undefined, or defined from star imports


507-507: JmFavoritePage may be undefined, or defined from star imports


507-507: Dict may be undefined, or defined from star imports


523-523: JmMagicConstants may be undefined, or defined from star imports


524-524: JmMagicConstants may be undefined, or defined from star imports


525-525: Generator may be undefined, or defined from star imports


525-525: JmSearchPage may be undefined, or defined from star imports


525-525: Dict may be undefined, or defined from star imports


561-561: JmMagicConstants may be undefined, or defined from star imports


562-562: JmMagicConstants may be undefined, or defined from star imports


563-563: JmMagicConstants may be undefined, or defined from star imports


564-564: Generator may be undefined, or defined from star imports


564-564: JmCategoryPage may be undefined, or defined from star imports


564-564: Dict may be undefined, or defined from star imports


576-576: Type may be undefined, or defined from star imports

src/jmcomic/jm_plugin.py (91)

5-5: from .jm_option import * used; unable to detect undefined names


18-18: JmOption may be undefined, or defined from star imports


31-31: JmOption may be undefined, or defined from star imports


42-42: jm_log may be undefined, or defined from star imports


47-47: Any may be undefined, or defined from star imports


65-65: List may be undefined, or defined from star imports


74-74: file_not_exists may be undefined, or defined from star imports


77-77: os may be undefined, or defined from star imports


78-78: os may be undefined, or defined from star imports


81-81: os may be undefined, or defined from star imports


90-90: os may be undefined, or defined from star imports


126-126: JmModuleConfig may be undefined, or defined from star imports


151-151: Optional may be undefined, or defined from star imports


237-237: Dict may be undefined, or defined from star imports


242-242: JmAlbumDetail may be undefined, or defined from star imports


264-264: JmAlbumDetail may be undefined, or defined from star imports


280-280: JmAlbumDetail may be undefined, or defined from star imports


296-296: JmcomicText may be undefined, or defined from star imports


297-297: mkdir_if_not_exists may be undefined, or defined from star imports


300-300: Dict may be undefined, or defined from star imports


300-300: Optional may be undefined, or defined from star imports


313-313: ExceptionTool may be undefined, or defined from star imports


317-317: Optional may be undefined, or defined from star imports


324-324: os may be undefined, or defined from star imports


336-336: os may be undefined, or defined from star imports


344-344: fix_filepath may be undefined, or defined from star imports


344-344: os may be undefined, or defined from star imports


346-346: Optional may be undefined, or defined from star imports


353-353: Set may be undefined, or defined from star imports


373-373: os may be undefined, or defined from star imports


374-374: os may be undefined, or defined from star imports


381-381: Dict may be undefined, or defined from star imports


381-381: Optional may be undefined, or defined from star imports


398-398: DirRule may be undefined, or defined from star imports


402-402: fix_suffix may be undefined, or defined from star imports


417-417: JmModuleConfig may be undefined, or defined from star imports


418-418: Callable may be undefined, or defined from star imports


440-440: fix_suffix may be undefined, or defined from star imports


444-444: JmImageDetail may be undefined, or defined from star imports


485-485: JmModuleConfig may be undefined, or defined from star imports


493-493: JmModuleConfig may be undefined, or defined from star imports


499-499: str_to_set may be undefined, or defined from star imports


533-533: get_browser_cookies may be undefined, or defined from star imports


560-560: os may be undefined, or defined from star imports


560-560: os may be undefined, or defined from star imports


562-562: os may be undefined, or defined from star imports


567-567: mkdir_if_not_exists may be undefined, or defined from star imports


568-568: mkdir_if_not_exists may be undefined, or defined from star imports


568-568: of_dir_path may be undefined, or defined from star imports


584-584: multi_thread_launcher may be undefined, or defined from star imports


623-623: List may be undefined, or defined from star imports


623-623: JmFavoritePage may be undefined, or defined from star imports


625-625: fix_windir_name may be undefined, or defined from star imports


631-631: JmMagicConstants may be undefined, or defined from star imports


656-656: of_file_name may be undefined, or defined from star imports


679-679: Optional may be undefined, or defined from star imports


681-681: ExceptionTool may be undefined, or defined from star imports


694-694: JmPhotoDetail may be undefined, or defined from star imports


711-711: DirRule may be undefined, or defined from star imports


718-718: fix_filepath may be undefined, or defined from star imports


719-719: mkdir_if_not_exists may be undefined, or defined from star imports


721-721: os may be undefined, or defined from star imports


739-739: ExceptionTool may be undefined, or defined from star imports


764-764: JmPhotoDetail may be undefined, or defined from star imports


780-780: DirRule may be undefined, or defined from star imports


787-787: fix_filepath may be undefined, or defined from star imports


788-788: mkdir_if_not_exists may be undefined, or defined from star imports


790-790: os may be undefined, or defined from star imports


793-793: files_of_dir may be undefined, or defined from star imports


815-815: JmOption may be undefined, or defined from star imports


817-817: Lock may be undefined, or defined from star imports


819-819: Optional may be undefined, or defined from star imports


819-819: Thread may be undefined, or defined from star imports


869-869: current_thread may be undefined, or defined from star imports


880-880: current_thread may be undefined, or defined from star imports


880-880: threading may be undefined, or defined from star imports


890-890: threading may be undefined, or defined from star imports


891-891: atexit_register may be undefined, or defined from star imports


907-907: current_thread may be undefined, or defined from star imports


930-930: JmOption may be undefined, or defined from star imports


961-961: Dict may be undefined, or defined from star imports


966-966: JmcomicException may be undefined, or defined from star imports


1014-1014: Optional may be undefined, or defined from star imports


1014-1014: JmPhotoDetail may be undefined, or defined from star imports


1015-1015: Optional may be undefined, or defined from star imports


1015-1015: JmImageDetail may be undefined, or defined from star imports


1016-1016: Optional may be undefined, or defined from star imports


1016-1016: JmAlbumDetail may be undefined, or defined from star imports


1023-1023: JmPhotoDetail may be undefined, or defined from star imports


1035-1035: field_cache may be undefined, or defined from star imports


1036-1036: JmOption may be undefined, or defined from star imports

src/jmcomic/jm_toolkit.py (65)

3-3: from .jm_exception import * used; unable to detect undefined names


66-66: JmModuleConfig may be undefined, or defined from star imports


76-76: ExceptionTool may be undefined, or defined from star imports


83-83: ExceptionTool may be undefined, or defined from star imports


99-99: ExceptionTool may be undefined, or defined from star imports


102-102: List may be undefined, or defined from star imports


111-111: JmPhotoDetail may be undefined, or defined from star imports


115-115: JmModuleConfig may be undefined, or defined from star imports


119-119: JmAlbumDetail may be undefined, or defined from star imports


123-123: JmModuleConfig may be undefined, or defined from star imports


129-129: Union may be undefined, or defined from star imports


129-129: Pattern may be undefined, or defined from star imports


129-129: List may be undefined, or defined from star imports


129-129: Pattern may be undefined, or defined from star imports


171-171: ExceptionTool may be undefined, or defined from star imports


189-189: ExceptionTool may be undefined, or defined from star imports


191-191: JmModuleConfig may be undefined, or defined from star imports


194-194: JmModuleConfig may be undefined, or defined from star imports


206-206: Dict may be undefined, or defined from star imports


206-206: Pattern may be undefined, or defined from star imports


206-206: Callable may be undefined, or defined from star imports


206-206: Match may be undefined, or defined from star imports


213-213: Callable may be undefined, or defined from star imports


213-213: Match may be undefined, or defined from star imports


218-218: Match may be undefined, or defined from star imports


220-220: os may be undefined, or defined from star imports


221-221: ExceptionTool may be undefined, or defined from star imports


228-228: os may be undefined, or defined from star imports


253-253: List may be undefined, or defined from star imports


302-302: ExceptionTool may be undefined, or defined from star imports


327-327: Pattern may be undefined, or defined from star imports


332-332: Pattern may be undefined, or defined from star imports


337-337: ExceptionTool may be undefined, or defined from star imports


344-344: Pattern may be undefined, or defined from star imports


349-349: ExceptionTool may be undefined, or defined from star imports


399-399: JmSearchPage may be undefined, or defined from star imports


431-431: JmSearchPage may be undefined, or defined from star imports


434-434: JmSearchPage may be undefined, or defined from star imports


449-449: JmSearchPage may be undefined, or defined from star imports


452-452: JmFavoritePage may be undefined, or defined from star imports


472-472: JmFavoritePage may be undefined, or defined from star imports


475-475: AdvancedDict may be undefined, or defined from star imports


475-475: JmSearchPage may be undefined, or defined from star imports


501-501: JmSearchPage may be undefined, or defined from star imports


504-504: AdvancedDict may be undefined, or defined from star imports


504-504: JmFavoritePage may be undefined, or defined from star imports


545-545: JmFavoritePage may be undefined, or defined from star imports


549-549: AdvancedDict may be undefined, or defined from star imports


620-620: JmAlbumDetail may be undefined, or defined from star imports


632-632: JmPhotoDetail may be undefined, or defined from star imports


656-656: JmAlbumDetail may be undefined, or defined from star imports


669-669: ExceptionTool may be undefined, or defined from star imports


676-676: AdvancedDict may be undefined, or defined from star imports


691-691: AdvancedDict may be undefined, or defined from star imports


698-698: JmModuleConfig may be undefined, or defined from star imports


704-704: Any may be undefined, or defined from star imports


789-789: Union may be undefined, or defined from star imports


805-805: JmMagicConstants may be undefined, or defined from star imports


809-809: JmMagicConstants may be undefined, or defined from star imports


826-826: of_file_name may be undefined, or defined from star imports


830-830: JmImageDetail may be undefined, or defined from star imports


858-858: JmMagicConstants may be undefined, or defined from star imports


861-861: JmMagicConstants may be undefined, or defined from star imports


886-886: JmMagicConstants may be undefined, or defined from star imports


907-907: ExceptionTool may be undefined, or defined from star imports

Additional comments not posted (1)
src/jmcomic/__init__.py (1)

5-5: Update version number to '2.5.12' to reflect new features or fixes.

Comment on lines +1046 to +1055
@classmethod
def calculate_md5(cls, file_path):
import hashlib

"""计算文件的MD5哈希值"""
hash_md5 = hashlib.md5()
with open(file_path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper error handling in calculate_md5.

Consider adding error handling for file operations to prevent the application from crashing if the file is inaccessible or corrupt. Here's a suggested modification:

- with open(file_path, "rb") as f:
+ try:
+     with open(file_path, "rb") as f:
+         for chunk in iter(lambda: f.read(4096), b""):
+             hash_md5.update(chunk)
+ except IOError as e:
+     print(f"Error reading file {file_path}: {e}")
+     return None

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
@classmethod
def calculate_md5(cls, file_path):
import hashlib
"""计算文件的MD5哈希值"""
hash_md5 = hashlib.md5()
with open(file_path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
@classmethod
def calculate_md5(cls, file_path):
import hashlib
"""计算文件的MD5哈希值"""
hash_md5 = hashlib.md5()
try:
with open(file_path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
except IOError as e:
print(f"Error reading file {file_path}: {e}")
return None
return hash_md5.hexdigest()

Comment on lines +1057 to +1070
@classmethod
def find_duplicate_files(cls, root_folder):
"""递归读取文件夹下所有文件并计算MD5出现次数"""
import os
from collections import defaultdict
md5_dict = defaultdict(list)

for root, _, files in os.walk(root_folder):
for file in files:
file_path = os.path.join(root, file)
file_md5 = cls.calculate_md5(file_path)
md5_dict[file_md5].append(file_path)

return md5_dict
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize file handling in find_duplicate_files.

Consider using pathlib for more robust and readable file path operations. Here's a suggested refactor:

- import os
+ from pathlib import Path

- for root, _, files in os.walk(root_folder):
+ for file_path in Path(root_folder).rglob('*'):
-    file_path = os.path.join(root, file)
-    file_md5 = cls.calculate_md5(file_path)
+    file_md5 = cls.calculate_md5(str(file_path))

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
@classmethod
def find_duplicate_files(cls, root_folder):
"""递归读取文件夹下所有文件并计算MD5出现次数"""
import os
from collections import defaultdict
md5_dict = defaultdict(list)
for root, _, files in os.walk(root_folder):
for file in files:
file_path = os.path.join(root, file)
file_md5 = cls.calculate_md5(file_path)
md5_dict[file_md5].append(file_path)
return md5_dict
@classmethod
def find_duplicate_files(cls, root_folder):
"""递归读取文件夹下所有文件并计算MD5出现次数"""
from pathlib import Path
from collections import defaultdict
md5_dict = defaultdict(list)
for file_path in Path(root_folder).rglob('*'):
file_md5 = cls.calculate_md5(str(file_path))
md5_dict[file_md5].append(str(file_path))
return md5_dict

Comment on lines 1072 to 1095
def invoke(self,
album=None,
downloader=None,
limit=2,
delete_original_file=True,
**kwargs,
) -> None:
if album is None:
return

# 获取到下载本子所在根目录
root_folder = self.option.dir_rule.decide_album_root_dir(album)
self.find_duplicated_files_and_delete(limit, root_folder)

def find_duplicated_files_and_delete(self, limit: int, root_folder: str):
md5_dict = self.find_duplicate_files(root_folder)
# 打印MD5出现次数大于等于2的文件
for md5, paths in md5_dict.items():
if len(paths) >= limit:
print(f"MD5: {md5} 出现次数: {len(paths)}")
for path in paths:
print(f" {path}")

self.execute_deletion(paths)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarify the behavior when album is None in invoke.

The method returns immediately if album is None. It might be helpful to log a message or raise an exception to inform the user why the operation was not performed.

- if album is None:
+ if album is None:
+     self.log("No album provided, skipping duplicate file deletion.")
+     return

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
def invoke(self,
album=None,
downloader=None,
limit=2,
delete_original_file=True,
**kwargs,
) -> None:
if album is None:
return
# 获取到下载本子所在根目录
root_folder = self.option.dir_rule.decide_album_root_dir(album)
self.find_duplicated_files_and_delete(limit, root_folder)
def find_duplicated_files_and_delete(self, limit: int, root_folder: str):
md5_dict = self.find_duplicate_files(root_folder)
# 打印MD5出现次数大于等于2的文件
for md5, paths in md5_dict.items():
if len(paths) >= limit:
print(f"MD5: {md5} 出现次数: {len(paths)}")
for path in paths:
print(f" {path}")
self.execute_deletion(paths)
def invoke(self,
album=None,
downloader=None,
limit=2,
delete_original_file=True,
**kwargs,
) -> None:
if album is None:
self.log("No album provided, skipping duplicate file deletion.")
return
# 获取到下载本子所在根目录
root_folder = self.option.dir_rule.decide_album_root_dir(album)
self.find_duplicated_files_and_delete(limit, root_folder)
def find_duplicated_files_and_delete(self, limit: int, root_folder: str):
md5_dict = self.find_duplicate_files(root_folder)
# 打印MD5出现次数大于等于2的文件
for md5, paths in md5_dict.items():
if len(paths) >= limit:
print(f"MD5: {md5} 出现次数: {len(paths)}")
for path in paths:
print(f" {path}")
self.execute_deletion(paths)

Comment on lines 7 to 8
from .api import *
from .jm_plugin import *
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace star imports with explicit imports to improve code clarity and maintainability.

- from .api import *
- from .jm_plugin import *
+ from .api import SpecificClass1, SpecificClass2
+ from .jm_plugin import SpecificPlugin1, SpecificPlugin2

Committable suggestion was skipped due low confidence.

Copy link

@coderabbitai coderabbitai bot left a 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 (1)
src/jmcomic/jm_plugin.py (1)

Line range hint 5-5: Avoid using wildcard imports as they can lead to unclear code and potential namespace conflicts.

- from .jm_option import *
+ from .jm_option import JmOption, RuleFunc, JmAlbumDetail
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between cb9bb3a and 2482f3c.
Files selected for processing (2)
  • assets/option/option_workflow_download.yml (1 hunks)
  • src/jmcomic/jm_plugin.py (1 hunks)
Additional Context Used
Ruff (93)
src/jmcomic/jm_plugin.py (93)

5-5: from .jm_option import * used; unable to detect undefined names


18-18: JmOption may be undefined, or defined from star imports


31-31: JmOption may be undefined, or defined from star imports


42-42: jm_log may be undefined, or defined from star imports


47-47: Any may be undefined, or defined from star imports


65-65: List may be undefined, or defined from star imports


74-74: file_not_exists may be undefined, or defined from star imports


77-77: os may be undefined, or defined from star imports


78-78: os may be undefined, or defined from star imports


81-81: os may be undefined, or defined from star imports


90-90: os may be undefined, or defined from star imports


126-126: JmModuleConfig may be undefined, or defined from star imports


151-151: Optional may be undefined, or defined from star imports


237-237: Dict may be undefined, or defined from star imports


242-242: JmAlbumDetail may be undefined, or defined from star imports


264-264: JmAlbumDetail may be undefined, or defined from star imports


280-280: JmAlbumDetail may be undefined, or defined from star imports


296-296: JmcomicText may be undefined, or defined from star imports


297-297: mkdir_if_not_exists may be undefined, or defined from star imports


300-300: Dict may be undefined, or defined from star imports


300-300: Optional may be undefined, or defined from star imports


313-313: ExceptionTool may be undefined, or defined from star imports


317-317: Optional may be undefined, or defined from star imports


324-324: os may be undefined, or defined from star imports


336-336: os may be undefined, or defined from star imports


344-344: fix_filepath may be undefined, or defined from star imports


344-344: os may be undefined, or defined from star imports


346-346: Optional may be undefined, or defined from star imports


353-353: Set may be undefined, or defined from star imports


373-373: os may be undefined, or defined from star imports


374-374: os may be undefined, or defined from star imports


381-381: Dict may be undefined, or defined from star imports


381-381: Optional may be undefined, or defined from star imports


398-398: DirRule may be undefined, or defined from star imports


402-402: fix_suffix may be undefined, or defined from star imports


417-417: JmModuleConfig may be undefined, or defined from star imports


418-418: Callable may be undefined, or defined from star imports


440-440: fix_suffix may be undefined, or defined from star imports


444-444: JmImageDetail may be undefined, or defined from star imports


485-485: JmModuleConfig may be undefined, or defined from star imports


493-493: JmModuleConfig may be undefined, or defined from star imports


499-499: str_to_set may be undefined, or defined from star imports


533-533: get_browser_cookies may be undefined, or defined from star imports


560-560: os may be undefined, or defined from star imports


560-560: os may be undefined, or defined from star imports


562-562: os may be undefined, or defined from star imports


567-567: mkdir_if_not_exists may be undefined, or defined from star imports


568-568: mkdir_if_not_exists may be undefined, or defined from star imports


568-568: of_dir_path may be undefined, or defined from star imports


584-584: multi_thread_launcher may be undefined, or defined from star imports


623-623: List may be undefined, or defined from star imports


623-623: JmFavoritePage may be undefined, or defined from star imports


625-625: fix_windir_name may be undefined, or defined from star imports


631-631: JmMagicConstants may be undefined, or defined from star imports


656-656: of_file_name may be undefined, or defined from star imports


679-679: Optional may be undefined, or defined from star imports


681-681: ExceptionTool may be undefined, or defined from star imports


694-694: JmPhotoDetail may be undefined, or defined from star imports


711-711: DirRule may be undefined, or defined from star imports


718-718: fix_filepath may be undefined, or defined from star imports


719-719: mkdir_if_not_exists may be undefined, or defined from star imports


721-721: os may be undefined, or defined from star imports


739-739: ExceptionTool may be undefined, or defined from star imports


764-764: JmPhotoDetail may be undefined, or defined from star imports


780-780: DirRule may be undefined, or defined from star imports


787-787: fix_filepath may be undefined, or defined from star imports


788-788: mkdir_if_not_exists may be undefined, or defined from star imports


790-790: os may be undefined, or defined from star imports


793-793: files_of_dir may be undefined, or defined from star imports


815-815: JmOption may be undefined, or defined from star imports


817-817: Lock may be undefined, or defined from star imports


819-819: Optional may be undefined, or defined from star imports


819-819: Thread may be undefined, or defined from star imports


869-869: current_thread may be undefined, or defined from star imports


880-880: current_thread may be undefined, or defined from star imports


880-880: threading may be undefined, or defined from star imports


890-890: threading may be undefined, or defined from star imports


891-891: atexit_register may be undefined, or defined from star imports


907-907: current_thread may be undefined, or defined from star imports


930-930: JmOption may be undefined, or defined from star imports


961-961: Dict may be undefined, or defined from star imports


966-966: JmcomicException may be undefined, or defined from star imports


1014-1014: Optional may be undefined, or defined from star imports


1014-1014: JmPhotoDetail may be undefined, or defined from star imports


1015-1015: Optional may be undefined, or defined from star imports


1015-1015: JmImageDetail may be undefined, or defined from star imports


1016-1016: Optional may be undefined, or defined from star imports


1016-1016: JmAlbumDetail may be undefined, or defined from star imports


1023-1023: JmPhotoDetail may be undefined, or defined from star imports


1035-1035: field_cache may be undefined, or defined from star imports


1036-1036: JmOption may be undefined, or defined from star imports


1087-1087: Optional may be undefined, or defined from star imports


1087-1087: JmAlbumDetail may be undefined, or defined from star imports

Additional comments not posted (5)
assets/option/option_workflow_download.yml (2)

39-43: The plugin delete_duplicated_files is correctly configured to delete original files when duplicates are found. Ensure that this behavior is consistent with the user's expectations and documented clearly.


36-37: Ensure that the email content variable ${EMAIL_CONTENT} is properly defined and sanitized before use.

src/jmcomic/jm_plugin.py (3)

1046-1055: Ensure proper error handling in calculate_md5.
Consider adding error handling for file operations to prevent the application from crashing if the file is inaccessible or corrupt. Here's a suggested modification:

- with open(file_path, "rb") as f:
+ try:
+     with open(file_path, "rb") as f:
+         for chunk in iter(lambda: f.read(4096), b""):
+             hash_md5.update(chunk)
+ except IOError as e:
+     print(f"Error reading file {file_path}: {e}")
+     return None

1057-1070: Optimize file handling in find_duplicate_files.
Consider using pathlib for more robust and readable file path operations. Here's a suggested refactor:

- import os
+ from pathlib import Path

- for root, _, files in os.walk(root_folder):
+ for file_path in Path(root_folder).rglob('*'):
-    file_path = os.path.join(root, file)
-    file_md5 = cls.calculate_md5(file_path)
+    file_md5 = cls.calculate_md5(str(file_path))

1072-1096: The method invoke in DeleteDuplicatedFilesPlugin correctly handles the deletion of duplicate files based on the MD5 hash. Ensure that the deletion logic is consistent with the user's data retention policies.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range and nitpick comments (1)
src/jmcomic/jm_plugin.py (1)

Line range hint 5-5: Consider replacing from .jm_option import * with specific imports.

Using wildcard imports (from module import *) can lead to unclear code, as it's not clear which names are present in the namespace. This can lead to bugs and makes the code harder to understand and maintain. It's a good practice to explicitly list imported names.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 2482f3c and 11019c9.
Files selected for processing (1)
  • src/jmcomic/jm_plugin.py (1 hunks)
Additional Context Used
Ruff (93)
src/jmcomic/jm_plugin.py (93)

5-5: from .jm_option import * used; unable to detect undefined names


18-18: JmOption may be undefined, or defined from star imports


31-31: JmOption may be undefined, or defined from star imports


42-42: jm_log may be undefined, or defined from star imports


47-47: Any may be undefined, or defined from star imports


65-65: List may be undefined, or defined from star imports


74-74: file_not_exists may be undefined, or defined from star imports


77-77: os may be undefined, or defined from star imports


78-78: os may be undefined, or defined from star imports


81-81: os may be undefined, or defined from star imports


90-90: os may be undefined, or defined from star imports


126-126: JmModuleConfig may be undefined, or defined from star imports


151-151: Optional may be undefined, or defined from star imports


237-237: Dict may be undefined, or defined from star imports


242-242: JmAlbumDetail may be undefined, or defined from star imports


264-264: JmAlbumDetail may be undefined, or defined from star imports


280-280: JmAlbumDetail may be undefined, or defined from star imports


296-296: JmcomicText may be undefined, or defined from star imports


297-297: mkdir_if_not_exists may be undefined, or defined from star imports


300-300: Dict may be undefined, or defined from star imports


300-300: Optional may be undefined, or defined from star imports


313-313: ExceptionTool may be undefined, or defined from star imports


317-317: Optional may be undefined, or defined from star imports


324-324: os may be undefined, or defined from star imports


336-336: os may be undefined, or defined from star imports


344-344: fix_filepath may be undefined, or defined from star imports


344-344: os may be undefined, or defined from star imports


346-346: Optional may be undefined, or defined from star imports


353-353: Set may be undefined, or defined from star imports


373-373: os may be undefined, or defined from star imports


374-374: os may be undefined, or defined from star imports


381-381: Dict may be undefined, or defined from star imports


381-381: Optional may be undefined, or defined from star imports


398-398: DirRule may be undefined, or defined from star imports


402-402: fix_suffix may be undefined, or defined from star imports


417-417: JmModuleConfig may be undefined, or defined from star imports


418-418: Callable may be undefined, or defined from star imports


440-440: fix_suffix may be undefined, or defined from star imports


444-444: JmImageDetail may be undefined, or defined from star imports


485-485: JmModuleConfig may be undefined, or defined from star imports


493-493: JmModuleConfig may be undefined, or defined from star imports


499-499: str_to_set may be undefined, or defined from star imports


533-533: get_browser_cookies may be undefined, or defined from star imports


560-560: os may be undefined, or defined from star imports


560-560: os may be undefined, or defined from star imports


562-562: os may be undefined, or defined from star imports


567-567: mkdir_if_not_exists may be undefined, or defined from star imports


568-568: mkdir_if_not_exists may be undefined, or defined from star imports


568-568: of_dir_path may be undefined, or defined from star imports


584-584: multi_thread_launcher may be undefined, or defined from star imports


623-623: List may be undefined, or defined from star imports


623-623: JmFavoritePage may be undefined, or defined from star imports


625-625: fix_windir_name may be undefined, or defined from star imports


631-631: JmMagicConstants may be undefined, or defined from star imports


656-656: of_file_name may be undefined, or defined from star imports


679-679: Optional may be undefined, or defined from star imports


681-681: ExceptionTool may be undefined, or defined from star imports


694-694: JmPhotoDetail may be undefined, or defined from star imports


711-711: DirRule may be undefined, or defined from star imports


718-718: fix_filepath may be undefined, or defined from star imports


719-719: mkdir_if_not_exists may be undefined, or defined from star imports


721-721: os may be undefined, or defined from star imports


739-739: ExceptionTool may be undefined, or defined from star imports


764-764: JmPhotoDetail may be undefined, or defined from star imports


780-780: DirRule may be undefined, or defined from star imports


787-787: fix_filepath may be undefined, or defined from star imports


788-788: mkdir_if_not_exists may be undefined, or defined from star imports


790-790: os may be undefined, or defined from star imports


793-793: files_of_dir may be undefined, or defined from star imports


815-815: JmOption may be undefined, or defined from star imports


817-817: Lock may be undefined, or defined from star imports


819-819: Optional may be undefined, or defined from star imports


819-819: Thread may be undefined, or defined from star imports


869-869: current_thread may be undefined, or defined from star imports


880-880: current_thread may be undefined, or defined from star imports


880-880: threading may be undefined, or defined from star imports


890-890: threading may be undefined, or defined from star imports


891-891: atexit_register may be undefined, or defined from star imports


907-907: current_thread may be undefined, or defined from star imports


930-930: JmOption may be undefined, or defined from star imports


961-961: Dict may be undefined, or defined from star imports


966-966: JmcomicException may be undefined, or defined from star imports


1014-1014: Optional may be undefined, or defined from star imports


1014-1014: JmPhotoDetail may be undefined, or defined from star imports


1015-1015: Optional may be undefined, or defined from star imports


1015-1015: JmImageDetail may be undefined, or defined from star imports


1016-1016: Optional may be undefined, or defined from star imports


1016-1016: JmAlbumDetail may be undefined, or defined from star imports


1023-1023: JmPhotoDetail may be undefined, or defined from star imports


1035-1035: field_cache may be undefined, or defined from star imports


1036-1036: JmOption may be undefined, or defined from star imports


1087-1087: Optional may be undefined, or defined from star imports


1087-1087: JmAlbumDetail may be undefined, or defined from star imports

Additional comments not posted (4)
src/jmcomic/jm_plugin.py (4)

1046-1055: Ensure proper error handling in calculate_md5.

This comment is still valid as per the existing comments on lines 1046-1055.


1057-1070: Optimize file handling in find_duplicate_files.

This comment is still valid as per the existing comments on lines 1057-1070.


1072-1080: Clarify the behavior when album is None in invoke.

This comment is still valid as per the existing comments on lines 1072-1080.


1087-1096: Enhance logging and error handling in find_duplicated_files_and_delete.
[REFACTOR_SUGGESTion]
The method logs and deletes files based on the MD5 hash count. Consider adding more detailed logging about the deletion process and handling potential errors during file deletion.

+ try:
  self.execute_deletion(paths)
+ except Exception as e:
+     self.log(f"Failed to delete files: {e}")

Comment on lines 1072 to 1080
def invoke(self,
album=None,
downloader=None,
limit=2,
delete_original_file=True,
**kwargs,
) -> None:
if album is None:
return
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider handling the case when album is None more explicitly.

The method invoke returns immediately if album is None, which is a silent failure. It might be helpful to log a message or raise an exception to inform the user why the operation was not performed.

- if album is None:
+ if album is None:
+     self.log("No album provided, skipping duplicate file deletion.")
+     return

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
def invoke(self,
album=None,
downloader=None,
limit=2,
delete_original_file=True,
**kwargs,
) -> None:
if album is None:
return
def invoke(self,
album=None,
downloader=None,
limit=2,
delete_original_file=True,
**kwargs,
) -> None:
if album is None:
self.log("No album provided, skipping duplicate file deletion.")
return

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 11019c9 and 90cb0fb.
Files selected for processing (3)
  • assets/docs/sources/option_file_syntax.md (1 hunks)
  • assets/option/option_workflow_download.yml (1 hunks)
  • src/jmcomic/jm_plugin.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • assets/option/option_workflow_download.yml
Additional Context Used
Ruff (93)
src/jmcomic/jm_plugin.py (93)

5-5: from .jm_option import * used; unable to detect undefined names


18-18: JmOption may be undefined, or defined from star imports


31-31: JmOption may be undefined, or defined from star imports


42-42: jm_log may be undefined, or defined from star imports


47-47: Any may be undefined, or defined from star imports


65-65: List may be undefined, or defined from star imports


74-74: file_not_exists may be undefined, or defined from star imports


77-77: os may be undefined, or defined from star imports


78-78: os may be undefined, or defined from star imports


81-81: os may be undefined, or defined from star imports


90-90: os may be undefined, or defined from star imports


126-126: JmModuleConfig may be undefined, or defined from star imports


151-151: Optional may be undefined, or defined from star imports


237-237: Dict may be undefined, or defined from star imports


242-242: JmAlbumDetail may be undefined, or defined from star imports


264-264: JmAlbumDetail may be undefined, or defined from star imports


280-280: JmAlbumDetail may be undefined, or defined from star imports


296-296: JmcomicText may be undefined, or defined from star imports


297-297: mkdir_if_not_exists may be undefined, or defined from star imports


300-300: Dict may be undefined, or defined from star imports


300-300: Optional may be undefined, or defined from star imports


313-313: ExceptionTool may be undefined, or defined from star imports


317-317: Optional may be undefined, or defined from star imports


324-324: os may be undefined, or defined from star imports


336-336: os may be undefined, or defined from star imports


344-344: fix_filepath may be undefined, or defined from star imports


344-344: os may be undefined, or defined from star imports


346-346: Optional may be undefined, or defined from star imports


353-353: Set may be undefined, or defined from star imports


373-373: os may be undefined, or defined from star imports


374-374: os may be undefined, or defined from star imports


381-381: Dict may be undefined, or defined from star imports


381-381: Optional may be undefined, or defined from star imports


398-398: DirRule may be undefined, or defined from star imports


402-402: fix_suffix may be undefined, or defined from star imports


417-417: JmModuleConfig may be undefined, or defined from star imports


418-418: Callable may be undefined, or defined from star imports


440-440: fix_suffix may be undefined, or defined from star imports


444-444: JmImageDetail may be undefined, or defined from star imports


485-485: JmModuleConfig may be undefined, or defined from star imports


493-493: JmModuleConfig may be undefined, or defined from star imports


499-499: str_to_set may be undefined, or defined from star imports


533-533: get_browser_cookies may be undefined, or defined from star imports


560-560: os may be undefined, or defined from star imports


560-560: os may be undefined, or defined from star imports


562-562: os may be undefined, or defined from star imports


567-567: mkdir_if_not_exists may be undefined, or defined from star imports


568-568: mkdir_if_not_exists may be undefined, or defined from star imports


568-568: of_dir_path may be undefined, or defined from star imports


584-584: multi_thread_launcher may be undefined, or defined from star imports


623-623: List may be undefined, or defined from star imports


623-623: JmFavoritePage may be undefined, or defined from star imports


625-625: fix_windir_name may be undefined, or defined from star imports


631-631: JmMagicConstants may be undefined, or defined from star imports


656-656: of_file_name may be undefined, or defined from star imports


679-679: Optional may be undefined, or defined from star imports


681-681: ExceptionTool may be undefined, or defined from star imports


694-694: JmPhotoDetail may be undefined, or defined from star imports


711-711: DirRule may be undefined, or defined from star imports


718-718: fix_filepath may be undefined, or defined from star imports


719-719: mkdir_if_not_exists may be undefined, or defined from star imports


721-721: os may be undefined, or defined from star imports


739-739: ExceptionTool may be undefined, or defined from star imports


764-764: JmPhotoDetail may be undefined, or defined from star imports


780-780: DirRule may be undefined, or defined from star imports


787-787: fix_filepath may be undefined, or defined from star imports


788-788: mkdir_if_not_exists may be undefined, or defined from star imports


790-790: os may be undefined, or defined from star imports


793-793: files_of_dir may be undefined, or defined from star imports


815-815: JmOption may be undefined, or defined from star imports


817-817: Lock may be undefined, or defined from star imports


819-819: Optional may be undefined, or defined from star imports


819-819: Thread may be undefined, or defined from star imports


869-869: current_thread may be undefined, or defined from star imports


880-880: current_thread may be undefined, or defined from star imports


880-880: threading may be undefined, or defined from star imports


890-890: threading may be undefined, or defined from star imports


891-891: atexit_register may be undefined, or defined from star imports


907-907: current_thread may be undefined, or defined from star imports


930-930: JmOption may be undefined, or defined from star imports


961-961: Dict may be undefined, or defined from star imports


966-966: JmcomicException may be undefined, or defined from star imports


1014-1014: Optional may be undefined, or defined from star imports


1014-1014: JmPhotoDetail may be undefined, or defined from star imports


1015-1015: Optional may be undefined, or defined from star imports


1015-1015: JmImageDetail may be undefined, or defined from star imports


1016-1016: Optional may be undefined, or defined from star imports


1016-1016: JmAlbumDetail may be undefined, or defined from star imports


1023-1023: JmPhotoDetail may be undefined, or defined from star imports


1035-1035: field_cache may be undefined, or defined from star imports


1036-1036: JmOption may be undefined, or defined from star imports


1087-1087: Optional may be undefined, or defined from star imports


1087-1087: JmAlbumDetail may be undefined, or defined from star imports

Additional comments not posted (1)
assets/docs/sources/option_file_syntax.md (1)

196-204: Add documentation for the delete_duplicated_files plugin.

The documentation for the delete_duplicated_files plugin is clear and concise. It effectively explains the parameters and their effects, which will help users understand how to use this plugin correctly.

Comment on lines +1040 to +1096
class DeleteDuplicatedFilesPlugin(JmOptionPlugin):
"""
https://github.com/hect0x7/JMComic-Crawler-Python/issues/244
"""
plugin_key = 'delete_duplicated_files'

@classmethod
def calculate_md5(cls, file_path):
import hashlib

"""计算文件的MD5哈希值"""
hash_md5 = hashlib.md5()
with open(file_path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()

@classmethod
def find_duplicate_files(cls, root_folder):
"""递归读取文件夹下所有文件并计算MD5出现次数"""
import os
from collections import defaultdict
md5_dict = defaultdict(list)

for root, _, files in os.walk(root_folder):
for file in files:
file_path = os.path.join(root, file)
file_md5 = cls.calculate_md5(file_path)
md5_dict[file_md5].append(file_path)

return md5_dict

def invoke(self,
limit,
album=None,
downloader=None,
delete_original_file=True,
**kwargs,
) -> None:
if album is None:
return

self.delete_original_file = delete_original_file
# 获取到下载本子所在根目录
root_folder = self.option.dir_rule.decide_album_root_dir(album)
self.find_duplicated_files_and_delete(limit, root_folder, album)

def find_duplicated_files_and_delete(self, limit: int, root_folder: str, album: Optional[JmAlbumDetail] = None):
md5_dict = self.find_duplicate_files(root_folder)
# 打印MD5出现次数大于等于limit的文件
for md5, paths in md5_dict.items():
if len(paths) >= limit:
prefix = '' if album is None else f'({album.album_id}) '
message = [prefix + f'MD5: {md5} 出现次数: {len(paths)}'] + \
[f' {path}' for path in paths]
self.log('\n'.join(message))
self.execute_deletion(paths)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review the DeleteDuplicatedFilesPlugin class for potential improvements.

The DeleteDuplicatedFilesPlugin class has been well-implemented with methods to handle file duplication based on MD5 hashes. However, consider the following improvements for better error handling and performance:

  1. Error Handling in calculate_md5:
    Ensure that the method gracefully handles exceptions that may occur during file operations, such as a file being inaccessible.
- with open(file_path, "rb") as f:
+ try:
+     with open(file_path, "rb") as f:
+         for chunk in iter(lambda: f.read(4096), b""):
+             hash_md5.update(chunk)
+ except IOError as e:
+     print(f"Error reading file {file_path}: {e}")
+     return None
  1. Use of pathlib in find_duplicate_files:
    For better readability and robustness, consider using pathlib instead of os.path for file path manipulations.
- import os
+ from pathlib import Path

- for root, _, files in os.walk(root_folder):
+ for file_path in Path(root_folder).rglob('*'):
-    file_path = os.path.join(root, file)
-    file_md5 = cls.calculate_md5(file_path)
+    file_md5 = cls.calculate_md5(str(file_path))
  1. Clarification when album is None in invoke:
    The method returns immediately if album is None. It might be helpful to log a message or raise an exception to inform the user why the operation was not performed.
- if album is None:
+ if album is None:
+     self.log("No album provided, skipping duplicate file deletion.")
+     return

@hect0x7 hect0x7 merged commit 88ad684 into master May 27, 2024
5 of 9 checks passed
@hect0x7 hect0x7 deleted the dev branch May 27, 2024 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

功能需求:过滤重复图片
1 participant