fix: support episode as int or float

This commit is contained in:
KotaHv
2024-07-24 14:03:20 +08:00
parent 6f43949585
commit ee36b05f95
2 changed files with 17 additions and 6 deletions

View File

@@ -23,7 +23,7 @@ class EpisodeFile(BaseModel):
group: str | None = Field(None)
title: str = Field(...)
season: int = Field(...)
episode: int = Field(None)
episode: int | float = Field(None)
suffix: str = Field(..., regex=r"\.(mkv|mp4|MKV|MP4)$")
@@ -32,6 +32,6 @@ class SubtitleFile(BaseModel):
group: str | None = Field(None)
title: str = Field(...)
season: int = Field(...)
episode: int = Field(None)
episode: int | float = Field(None)
language: str = Field(..., regex=r"(zh|zh-tw)")
suffix: str = Field(..., regex=r"\.(ass|srt|ASS|SRT)$")

View File

@@ -9,11 +9,11 @@ logger = logging.getLogger(__name__)
PLATFORM = "Unix"
RULES = [
r"(.*) - (\d{1,4}(?!\d|p)|\d{1,4}\.\d{1,2}(?!\d|p))(?:v\d{1,2})?(?: )?(?:END)?(.*)",
r"(.*)[\[\ E](\d{1,4}|\d{1,4}\.\d{1,2})(?:v\d{1,2})?(?: )?(?:END)?[\]\ ](.*)",
r"(.*) - (\d{1,4}(?:\.\d{1,2})?(?!\d|p))(?:v\d{1,2})?(?: )?(?:END)?(.*)",
r"(.*)[\[\ E](\d{1,4}(?:\.\d{1,2})?)(?:v\d{1,2})?(?: )?(?:END)?[\]\ ](.*)",
r"(.*)\[(?:第)?(\d{1,4}(?:\.\d{1,2})?)[话集話](?:END)?\](.*)",
r"(.*)第?(\d{1,4}(?:\.\d{1,2})?)[话話集](?:END)?(.*)",
r"(.*)(?:S\d{2})?EP?(\d+)(.*)",
r"(.*)(?:S\d{2})?EP?(\d{1,4}(?:\.\d{1,2})?)(.*)",
]
SUBTITLE_LANG = {
@@ -81,7 +81,7 @@ def torrent_parser(
title, season = get_season_and_title(title)
else:
title, _ = get_season_and_title(title)
episode = int(match_obj.group(2))
episode = match_obj.group(2)
suffix = Path(torrent_path).suffix
if file_type == "media":
return EpisodeFile(
@@ -110,3 +110,14 @@ if __name__ == "__main__":
"/不时用俄语小声说真心话的邻桌艾莉同学/Season 1/不时用俄语小声说真心话的邻桌艾莉同学 S01E02.mp4"
)
print(ep)
ep = torrent_parser(
"/downloads/Bangumi/关于我转生变成史莱姆这档事 (2018)/Season 3/[ANi] 關於我轉生變成史萊姆這檔事 第三季 - 48.5 [1080P][Baha][WEB-DL][AAC AVC][CHT].mp4"
)
print(ep)
ep = torrent_parser(
"/downloads/Bangumi/关于我转生变成史莱姆这档事 (2018)/Season 3/[ANi] 關於我轉生變成史萊姆這檔事 第三季 - 48.5 [1080P][Baha][WEB-DL][AAC AVC][CHT].srt",
file_type="subtitle",
)
print(ep)