Skip to content

Update __init__.py#42

Open
zhufree32 wants to merge 1 commit intoDzAvril:mainfrom
zhufree32:patch-1
Open

Update __init__.py#42
zhufree32 wants to merge 1 commit intoDzAvril:mainfrom
zhufree32:patch-1

Conversation

@zhufree32
Copy link

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @zhufree32, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求主要聚焦于提升STRM文件处理逻辑的准确性和可靠性。通过改进STRM文件路径到网盘存储路径的映射方式,并引入一套更严格的视频文件匹配算法,解决了可能存在的误匹配和不精确删除的问题。此外,还对STRM文件删除事件的处理流程进行了加固,确保操作的精准性和安全性。

Highlights

  • STRM文件路径解析优化: 优化了 _get_storage_path_from_strm 函数,确保在从STRM文件路径提取网盘存储路径时,能够完整保留文件名,仅安全地移除 .strm 后缀,避免截断错误。
  • 视频文件精准匹配逻辑: 重构了 _find_storage_media_file 函数的匹配逻辑,引入了明确的视频文件后缀列表,并实现了更精准的匹配机制。现在,视频文件必须在去除其视频后缀后,与STRM文件的主名完全一致,或以STRM主名加特定分隔符(如 .-_)开头,以避免误匹配。
  • STRM删除事件处理增强: 增强了 handle_strm_deleted 函数的健壮性,增加了对非 .strm 文件的校验,并确保在删除操作中仅处理和删除与STRM文件精准匹配的网盘视频文件,同时优化了日志输出和通知内容的描述。

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

本次PR改进了strm文件与媒体文件的匹配逻辑,使其更加精准和健壮。这些修改是有益的,但仍有一些可以改进的地方,尤其是在大小写不敏感匹配和代码结构方面。我提出了一些建议以进一步提高代码质量。

Comment on lines +1397 to +1398
# 获取strm文件的完整主名(仅去掉.strm后缀,保留所有字符)
strm_base_name = Path(base_path).name

Choose a reason for hiding this comment

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

high

为了实现大小写不敏感的文件名匹配,建议在获取 strm_base_name 时就将其转换为小写。这将与后续循环内对 video_base_name 的处理保持一致,避免因大小写问题导致匹配失败。

Suggested change
# 获取strm文件的完整主名(仅去掉.strm后缀,保留所有字符
strm_base_name = Path(base_path).name
# 获取strm文件的完整主名(仅去掉.strm后缀,并转为小写
strm_base_name = Path(base_path).name.lower()

Comment on lines +1425 to +1443
# 转换文件名和后缀为小写,避免大小写问题
file_name = file_item.name.lower()
file_ext = Path(file_item.name).suffix.lower()

# 1. 检查是否为视频文件
if file_ext not in VIDEO_EXTENSIONS:
continue

# 2. 提取视频文件的基础名(去掉最后一个视频后缀)
video_base_name = Path(file_item.name).stem

# 3. 精准匹配逻辑:
# - 场景1:视频基础名与strm主名完全一致(如 strm: test.strm → 视频: test.mkv)
# - 场景2:视频基础名以strm主名+分隔符开头(如 strm: test-1080p.strm → 视频: test-1080p.bluray.mkv)
if (video_base_name == strm_base_name) or (
video_base_name.startswith(f"{strm_base_name}.")
or video_base_name.startswith(f"{strm_base_name} - ")
or video_base_name.startswith(f"{strm_base_name}_")
):

Choose a reason for hiding this comment

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

high

当前的匹配逻辑存在几个可优化点:

  1. file_name 变量在第1426行已定义但未使用,应当移除。
  2. video_base_name 未转换为小写,导致与 strm_base_name 的比较是大小写敏感的。
  3. 多个 startswith 判断可以通过传入元组的方式简化,使代码更简洁。

建议修改以实现大小写不敏感的匹配并优化代码。

            # 转换后缀为小写,避免大小写问题
            file_ext = Path(file_item.name).suffix.lower()
            
            # 1. 检查是否为视频文件
            if file_ext not in VIDEO_EXTENSIONS:
                continue
            
            # 2. 提取视频文件的基础名(去掉最后一个视频后缀)并转为小写
            video_base_name = Path(file_item.name).stem.lower()
            
            # 3. 精准匹配逻辑(大小写不敏感):
            #    - 场景1:视频基础名与strm主名完全一致(如 strm: test.strm → 视频: test.mkv)
            #    - 场景2:视频基础名以strm主名+分隔符开头(如 strm: test-1080p.strm → 视频: test-1080p.bluray.mkv)
            if (video_base_name == strm_base_name) or video_base_name.startswith((
                f"{strm_base_name}.",
                f"{strm_base_name} - ",
                f"{strm_base_name}_",
            )):

Comment on lines +1394 to +1395
# 明确视频后缀列表(覆盖主流视频格式)
VIDEO_EXTENSIONS = [".mkv", ".mp4", ".ts", ".m2ts", ".avi", ".mov", ".flv", ".wmv", ".mpeg", ".mpg"]

Choose a reason for hiding this comment

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

medium

VIDEO_EXTENSIONS 列表在 _find_storage_media_file 方法内部定义,这意味着每次调用该方法时都会重新创建它。为了提高性能和可维护性,建议将其作为类级别常量(例如 RemoveLink.VIDEO_EXTENSIONS)在类顶层定义,并在方法中通过 self.VIDEO_EXTENSIONSRemoveLink.VIDEO_EXTENSIONS 引用。

@github-actions github-actions bot added the Stale label Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant