-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
功能需求:过滤重复图片 #245
Conversation
WalkthroughThe updates introduce a new plugin, Changes
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
Tip New Features and ImprovementsReview SettingsIntroduced 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 InstructionsCodeRabbit 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 RulesWe 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 ToolsWe are continually expanding our support for static analysis tools. We have added support for Tone SettingsUsers can now customize CodeRabbit to review code in the style of their favorite characters or personalities. Here are some of our favorite examples:
Revamped Settings PageWe 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 Miscellaneous
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 as PR comments)
Additionally, you can add CodeRabbit Configration 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: 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 JmOptionPluginsrc/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, SpecificClass2Ensure 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
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 importssrc/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 injm_config.py
are correctly maintained.src/jmcomic/jm_option.py (1)
Line range hint
1-655
: Other modifications in option handling are correctly implemented.
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: 4
Outside diff range and nitpick comments (28)
src/jmcomic/__init__.py (2)
Line range hint
14-14
: Ensure thatDict
,Any
, andJmModuleConfig
are explicitly imported to avoid runtime errors.+ from typing import Dict, Any + from .jm_config import JmModuleConfigAlso applies to: 22-22, 27-27
Line range hint
23-23
: Ensure thatJmcomicClient
andJmOptionPlugin
are explicitly imported to avoid runtime errors.+ from .jm_client_interface import JmcomicClient + from .jm_plugin import JmOptionPluginAlso 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 thatExceptionTool
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 thatJmImageTool
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 thatsuffix_not_equal
is explicitly imported to avoid runtime errors.+ from .jm_toolkit import suffix_not_equal
Line range hint
84-84
: Ensure thatfield_cache
is explicitly imported to avoid runtime errors.+ from .jm_toolkit import field_cache
Line range hint
85-85
: Ensure thatDict
andAny
are explicitly imported from thetyping
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 thatAdvancedDict
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 thatJmCryptoTool
is explicitly imported to avoid runtime errors.+ from .jm_toolkit import JmCryptoTool
Line range hint
142-142
: Ensure thatJmAlbumDetail
andJmPhotoDetail
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 thatJmMagicConstants
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 thatOptional
is explicitly imported from thetyping
module to avoid runtime errors.+ from typing import Optional
Also applies to: 483-483
Line range hint
211-211
: Ensure thatJmFavoritePage
,JmCategoryPage
, andJmSearchPage
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 thatJmImageDetail
is explicitly imported to avoid runtime errors.+ from .jm_entities import JmImageDetail
Line range hint
445-445
: Ensure thatPostman
is explicitly imported to avoid runtime errors.+ from .jm_toolkit import Postman
Line range hint
449-449
: Ensure thatList
is explicitly imported from thetyping
module to avoid runtime errors.+ from typing import List
Also applies to: 455-455
Line range hint
471-471
: Ensure thatJmModuleConfig
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 thatType
is explicitly imported from thetyping
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, JmAlbumDetailAlso 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 thePattern
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 theAny
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
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 importssrc/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 importssrc/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 importssrc/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.
@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() |
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.
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.
@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() |
@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 |
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.
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.
@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 |
src/jmcomic/jm_plugin.py
Outdated
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) |
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.
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.
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) |
from .api import * | ||
from .jm_plugin import * |
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.
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.
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 (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
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 plugindelete_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 incalculate_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 infind_duplicate_files
.
Consider usingpathlib
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 methodinvoke
inDeleteDuplicatedFilesPlugin
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.
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: 1
Outside diff range and nitpick comments (1)
src/jmcomic/jm_plugin.py (1)
Line range hint
5-5
: Consider replacingfrom .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
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 incalculate_md5
.This comment is still valid as per the existing comments on lines 1046-1055.
1057-1070
: Optimize file handling infind_duplicate_files
.This comment is still valid as per the existing comments on lines 1057-1070.
1072-1080
: Clarify the behavior whenalbum
isNone
ininvoke
.This comment is still valid as per the existing comments on lines 1072-1080.
1087-1096
: Enhance logging and error handling infind_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}")
src/jmcomic/jm_plugin.py
Outdated
def invoke(self, | ||
album=None, | ||
downloader=None, | ||
limit=2, | ||
delete_original_file=True, | ||
**kwargs, | ||
) -> None: | ||
if album is None: | ||
return |
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.
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.
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 |
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: 1
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
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 thedelete_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.
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) |
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.
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:
- 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
- Use of
pathlib
infind_duplicate_files
:
For better readability and robustness, consider usingpathlib
instead ofos.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))
- Clarification when
album
isNone
ininvoke
:
The method returns immediately ifalbum
isNone
. 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
Summary by CodeRabbit
New Features
delete_duplicated_files
plugin to automatically identify and delete duplicate files based on MD5 hashes after each download.Documentation
delete_duplicated_files
plugin and its parameters.Enhancements
JmImageResp
objects, ensuring better compatibility and performance.