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

v2.4.6: 实现对本子名称进行分词并提取原始名称;实现更便捷的自定义下载文件夹名机制、并跟进对应文档;内置一些更简洁的、可用作文件夹名… #172

Merged
merged 1 commit into from
Dec 1, 2023

Conversation

hect0x7
Copy link
Owner

@hect0x7 hect0x7 commented Dec 1, 2023

…的字段oname, idoname, authoroname.

Summary by CodeRabbit

  • New Features

    • Introduced the ability to customize download folder names using new directory rules.
    • Added properties to retrieve album information in various formats (author, original name, etc.).
  • Enhancements

    • Updated the app version to 2.4.6.
    • Improved folder name generation with support for custom functions.
  • Documentation

    • Provided a detailed tutorial on customizing download directory names.
  • Refactor

    • Changed how the solve_func accesses the get_dirname method for consistency and maintainability.
  • Bug Fixes

    • Adjusted image index assignment to start from 1 for better user understanding.
  • Chores

    • Removed unused parse_to_abspath method and added new utility methods for text processing.

Copy link

coderabbitai bot commented Dec 1, 2023

Walkthrough

The update introduces a customizable directory naming feature for album downloads, allowing users to define folder structures via a new DirRule. It adds custom field handling in the JmModuleConfig class and updates properties and methods in jm_entity.py to support this. The version bump to '2.4.6' reflects these enhancements, and changes in jm_option.py and jm_toolkit.py further support the new functionality.

Changes

File Path Change Summary
assets/docs/.../9_custom_download_dir_name.md Introduced DirRule for custom folder structures and examples of usage.
src/jmcomic/__init__.py Updated version number from '2.4.5' to '2.4.6'.
src/jmcomic/jm_config.py Added custom fields AFIELD_ADVICE and PFIELD_ADVICE to JmModuleConfig.
src/jmcomic/jm_entity.py Added properties for album naming and updated DetailEntity class for folder naming.
src/jmcomic/jm_option.py Modified solve_func to use DetailEntity.get_dirname method.
src/jmcomic/jm_toolkit.py Removed parse_to_abspath, added new methods and a bracket_map dictionary.

🐇✨
In the burrow of code, a new feature hops in,
Custom folders align, as the downloads begin.
With a version bump, and a toolkit refresh,
The rabbit's work shines, in the digital mesh. 🌟📁


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

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.

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7bcc28f and ebe49f9.
Files selected for processing (6)
  • assets/docs/sources/tutorial/9_custom_download_dir_name.md (1 hunks)
  • src/jmcomic/init.py (1 hunks)
  • src/jmcomic/jm_config.py (1 hunks)
  • src/jmcomic/jm_entity.py (5 hunks)
  • src/jmcomic/jm_option.py (1 hunks)
  • src/jmcomic/jm_toolkit.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/jmcomic/init.py
Additional comments: 12
assets/docs/sources/tutorial/9_custom_download_dir_name.md (1)
  • 1-112: The tutorial documentation provides a clear and comprehensive guide on how to customize download folder names using the new DirRule configuration. The examples are well-illustrated and demonstrate the usage of custom fields and the associated processing functions. It is important to ensure that the code snippets are tested and work as intended to prevent any confusion for the users.
src/jmcomic/jm_entity.py (8)
  • 65-66: The implementation of the author property correctly raises NotImplementedError, ensuring that subclasses must provide their own implementation.

  • 69-87: The oname property is implemented to extract the original name of an album using JmcomicText.parse_orig_album_name. Ensure that the parse_orig_album_name method is robust and handles edge cases as expected.

  • 90-106: The authoroname property concatenates the author and original name in a specific format. Verify that the author property is correctly implemented in all subclasses to avoid runtime errors.

  • 109-114: The idoname property concatenates the ID and original name in a specific format. This property assumes that the id property is correctly implemented in all subclasses.

  • 127-152: The get_dirname class method is implemented to support custom folder naming using advice functions from JmModuleConfig.XFIELD_ADVICE. Ensure that the advice functions are properly defined and tested for the expected behavior.

  • 179-179: The index in JmImageDetail is now starting from 1, which aligns with the summary. Ensure that all related code that depends on the index value is updated accordingly to prevent off-by-one errors.

  • 237-240: The tag property in JmImageDetail has been updated to include the index within the total number of photos. Verify that the from_photo property is always set and that its length is correctly calculated to avoid division by zero or other runtime errors.

  • 355-359: The create_image_detail method in JmPhotoDetail correctly increments the index by 1 to align with the new index assignment starting from 1. Ensure that this change is reflected in all places where create_image_detail is called.

src/jmcomic/jm_option.py (2)
  • 134-135: The lambda function solve_func now uses DetailEntity.get_dirname statically. Verify that DetailEntity.get_dirname is intended to be used as a static method and that it can handle the detail argument appropriately.

  • 135-135: The function fix_windir_name used in the lambda solve_func is not defined within the provided code. Ensure that it is defined elsewhere in the codebase or imported correctly.

src/jmcomic/jm_toolkit.py (1)
  • 238-242: The parse_orig_album_name method returns the first word not enclosed in brackets. However, if the intention is to extract the original album name, this logic might not be sufficient for all cases. Verify that this method's behavior aligns with the expected functionality.

Comment on lines +155 to +158
# 例如:
# Amyname -> JmModuleConfig.AFIELD_ADVICE['myname'] = lambda album: "自定义名称"
AFIELD_ADVICE = dict()
PFIELD_ADVICE = dict()
Copy link

Choose a reason for hiding this comment

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

The addition of AFIELD_ADVICE and PFIELD_ADVICE is consistent with the summary and seems to be implemented correctly. However, it would be beneficial to provide an example or documentation for PFIELD_ADVICE similar to the one provided for AFIELD_ADVICE to ensure clarity and ease of use for future developers.

Comment on lines 225 to 226
def parse_dsl_text(cls, dsl_text: str) -> str:
return cls.dsl_replacer.parse_dsl_text(dsl_text)
Copy link

Choose a reason for hiding this comment

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

The parse_dsl_text method seems to be a simple wrapper around dsl_replacer.parse_dsl_text. If there's no additional logic planned for this method, consider whether this extra layer of abstraction is necessary, as it could be called directly.

Comment on lines +277 to +278
j = title.find(bracket_map[c], i)
ExceptionTool.require_true(j != -1, f'未闭合的 {c}{bracket_map[c]}: {title[i:]}')
Copy link

Choose a reason for hiding this comment

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

The tokenize method throws an exception if a closing bracket is not found. While this is a valid way to handle unmatched brackets, consider if there's a need to handle this more gracefully, such as skipping the unmatched bracket or logging a warning, depending on the application's requirements.

Comment on lines +291 to +293
def to_zh_cn(cls, s):
import zhconv
return zhconv.convert(s, 'zh_cn')
Copy link

Choose a reason for hiding this comment

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

The to_zh_cn method correctly uses the zhconv library to convert text to simplified Chinese. However, consider handling potential exceptions that may arise from the zhconv.convert call, such as when the library is not installed or when it encounters an error during conversion.

@hect0x7 hect0x7 merged commit a7e8ea2 into master Dec 1, 2023
8 checks passed
@hect0x7 hect0x7 deleted the dev branch December 1, 2023 14: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