Skip to content

Commit

Permalink
feat(Ani2Alist): RSS 订阅模式支持根据 URL 自动生成对应多级目录
Browse files Browse the repository at this point in the history
  • Loading branch information
Akimio521 committed Feb 3, 2025
1 parent 5e22136 commit 81892c0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
23 changes: 19 additions & 4 deletions app/modules/ani2alist/ani2alist.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,24 @@ async def update_rss_anime_dict(self, url_dict: dict):
更新 RSS 动画列表
"""

def handle_recursive(url_dict: dict, entry) -> None:
"""
处理 RSS 数据,解析 URL 多级目录
"""
parents = entry.link.split("/")[3:] # 拆分多级目录
current_dict = url_dict
for index in range(len(parents)):
name = URLUtils.decode(parents[index])
if index == len(parents) - 1:
current_dict[entry.title] = [
convert_size_to_bytes(entry.anime_size),
entry.link,
]
else:
if name not in current_dict:
current_dict[name] = {}
current_dict = current_dict[name]

def convert_size_to_bytes(size_str: str) -> int:
"""
将带单位的大小转换为字节
Expand Down Expand Up @@ -252,7 +270,4 @@ def convert_size_to_bytes(size_str: str) -> int:
"anime_size": "473.0 MB",
}
"""
url_dict["RSS"][entry.title] = [
convert_size_to_bytes(entry.anime_size),
entry.link,
]
handle_recursive(url_dict, entry)
9 changes: 8 additions & 1 deletion app/utils/url.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from urllib.parse import quote, urlparse
from urllib.parse import quote, unquote, urlparse


class URLUtils:
Expand All @@ -15,6 +15,13 @@ def encode(cls, url: str) -> str:
"""
return quote(url, safe=cls.SAFE_WORD)

@staticmethod
def decode(strings: str) -> str:
"""
URL 解码
"""
return unquote(strings)

@staticmethod
def get_resolve_url(url: str) -> tuple[str, str, int]:
"""
Expand Down

0 comments on commit 81892c0

Please sign in to comment.