Skip to content

Commit 07bb7f2

Browse files
authored
Merge pull request #849 from EstrellaXD/3.1-dev
3.1.15
2 parents 7913061 + d5b84b9 commit 07bb7f2

38 files changed

Lines changed: 5386 additions & 6424 deletions

backend/src/module/api/program.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
@router.on_event("startup")
2121
async def startup():
22-
program.startup()
22+
await program.startup()
2323

2424

2525
@router.on_event("shutdown")

backend/src/module/core/program.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import asyncio
23

34
from module.conf import VERSION, settings
45
from module.models import ResponseModel
@@ -31,7 +32,7 @@ def __start_info():
3132
logger.info("GitHub: https://github.com/EstrellaXD/Auto_Bangumi/")
3233
logger.info("Starting AutoBangumi...")
3334

34-
def startup(self):
35+
async def startup(self):
3536
self.__start_info()
3637
if not self.database:
3738
first_run()
@@ -49,32 +50,27 @@ def startup(self):
4950
if not self.img_cache:
5051
logger.info("[Core] No image cache exists, create image cache.")
5152
cache_image()
52-
self.start()
53+
await self.start()
5354

54-
def start(self):
55+
async def start(self):
5556
self.stop_event.clear()
5657
settings.load()
57-
if self.downloader_status:
58-
if self.enable_renamer:
59-
self.rename_start()
60-
if self.enable_rss:
61-
self.rss_start()
62-
logger.info("Program running.")
63-
return ResponseModel(
64-
status=True,
65-
status_code=200,
66-
msg_en="Program started.",
67-
msg_zh="程序启动成功。",
68-
)
69-
else:
70-
self.stop_event.set()
71-
logger.warning("Program failed to start.")
72-
return ResponseModel(
73-
status=False,
74-
status_code=406,
75-
msg_en="Program failed to start.",
76-
msg_zh="程序启动失败。",
77-
)
58+
while not self.downloader_status:
59+
logger.warning("Downloader is not running.")
60+
logger.info("Waiting for downloader to start.")
61+
await asyncio.sleep(30)
62+
if self.enable_renamer:
63+
self.rename_start()
64+
if self.enable_rss:
65+
self.rss_start()
66+
logger.info("Program running.")
67+
return ResponseModel(
68+
status=True,
69+
status_code=200,
70+
msg_en="Program started.",
71+
msg_zh="程序启动成功。",
72+
)
73+
7874

7975
def stop(self):
8076
if self.is_running:

backend/src/module/models/torrent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class EpisodeFile(BaseModel):
2323
group: str | None = Field(None)
2424
title: str = Field(...)
2525
season: int = Field(...)
26-
episode: int = Field(None)
26+
episode: int | float = Field(None)
2727
suffix: str = Field(..., regex=r"\.(mkv|mp4|MKV|MP4)$")
2828

2929

@@ -32,6 +32,6 @@ class SubtitleFile(BaseModel):
3232
group: str | None = Field(None)
3333
title: str = Field(...)
3434
season: int = Field(...)
35-
episode: int = Field(None)
35+
episode: int | float = Field(None)
3636
language: str = Field(..., regex=r"(zh|zh-tw)")
3737
suffix: str = Field(..., regex=r"\.(ass|srt|ASS|SRT)$")

backend/src/module/network/request_contents.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ class RequestContent(RequestURL):
1515
def get_torrents(
1616
self,
1717
_url: str,
18-
_filter: str = "|".join(settings.rss_parser.filter),
18+
_filter: str = None,
1919
limit: int = None,
2020
retry: int = 3,
2121
) -> list[Torrent]:
2222
soup = self.get_xml(_url, retry)
2323
if soup:
2424
torrent_titles, torrent_urls, torrent_homepage = rss_parser(soup)
2525
torrents: list[Torrent] = []
26+
if _filter is None:
27+
_filter = "|".join(settings.rss_parser.filter)
2628
for _title, torrent_url, homepage in zip(
2729
torrent_titles, torrent_urls, torrent_homepage
2830
):

backend/src/module/parser/analyser/openai.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def _prepare_params(self, text: str, prompt: str) -> dict[str, Any]:
136136
dict(role="system", content=prompt),
137137
dict(role="user", content=text),
138138
],
139+
139140
# set temperature to 0 to make results be more stable and reproducible.
140141
temperature=0,
141142
)

backend/src/module/parser/analyser/raw_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def clean_sub(sub: str | None) -> str | None:
131131

132132

133133
def process(raw_title: str):
134-
raw_title = raw_title.strip().replace("\n", "")
134+
raw_title = raw_title.strip().replace("\n", " ")
135135
content_title = pre_process(raw_title)
136136
# 预处理标题
137137
group = get_group(content_title)

backend/src/module/parser/analyser/torrent_parser.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
PLATFORM = "Unix"
1010

1111
RULES = [
12-
r"(.*) - (\d{1,4}(?!\d|p)|\d{1,4}\.\d{1,2}(?!\d|p))(?:v\d{1,2})?(?: )?(?:END)?(.*)",
13-
r"(.*)[\[\ E](\d{1,4}|\d{1,4}\.\d{1,2})(?:v\d{1,2})?(?: )?(?:END)?[\]\ ](.*)",
14-
r"(.*)\[(?:第)?(\d*\.*\d*)[话集話](?:END)?\](.*)",
15-
r"(.*)第?(\d*\.*\d*)[话話集](?:END)?(.*)",
16-
r"(.*)(?:S\d{2})?EP?(\d+)(.*)",
12+
r"(.*) - (\d{1,4}(?:\.\d{1,2})?(?!\d|p))(?:v\d{1,2})?(?: )?(?:END)?(.*)",
13+
r"(.*)[\[\ E](\d{1,4}(?:\.\d{1,2})?)(?:v\d{1,2})?(?: )?(?:END)?[\]\ ](.*)",
14+
r"(.*)\[(?:第)?(\d{1,4}(?:\.\d{1,2})?)[话集話](?:END)?\](.*)",
15+
r"(.*)第?(\d{1,4}(?:\.\d{1,2})?)[话話集](?:END)?(.*)",
16+
r"(.*)(?:S\d{2})?EP?(\d{1,4}(?:\.\d{1,2})?)(.*)",
1717
]
1818

1919
SUBTITLE_LANG = {
@@ -81,7 +81,7 @@ def torrent_parser(
8181
title, season = get_season_and_title(title)
8282
else:
8383
title, _ = get_season_and_title(title)
84-
episode = int(match_obj.group(2))
84+
episode = match_obj.group(2)
8585
suffix = Path(torrent_path).suffix
8686
if file_type == "media":
8787
return EpisodeFile(
@@ -103,3 +103,21 @@ def torrent_parser(
103103
episode=episode,
104104
suffix=suffix,
105105
)
106+
107+
108+
if __name__ == "__main__":
109+
ep = torrent_parser(
110+
"/不时用俄语小声说真心话的邻桌艾莉同学/Season 1/不时用俄语小声说真心话的邻桌艾莉同学 S01E02.mp4"
111+
)
112+
print(ep)
113+
114+
ep = torrent_parser(
115+
"/downloads/Bangumi/关于我转生变成史莱姆这档事 (2018)/Season 3/[ANi] 關於我轉生變成史萊姆這檔事 第三季 - 48.5 [1080P][Baha][WEB-DL][AAC AVC][CHT].mp4"
116+
)
117+
print(ep)
118+
119+
ep = torrent_parser(
120+
"/downloads/Bangumi/关于我转生变成史莱姆这档事 (2018)/Season 3/[ANi] 關於我轉生變成史萊姆這檔事 第三季 - 48.5 [1080P][Baha][WEB-DL][AAC AVC][CHT].srt",
121+
file_type="subtitle",
122+
)
123+
print(ep)

backend/src/test/test_raw_parser.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33

44
def test_raw_parser():
5+
# Issue #794, RSS link: https://mikanani.me/RSS/Bangumi?bangumiId=3367&subgroupid=370
6+
content = "[喵萌奶茶屋&LoliHouse] 鹿乃子乃子乃子虎视眈眈 / Shikanoko Nokonoko Koshitantan\n- 01 [WebRip 1080p HEVC-10bit AAC][简繁内封字幕]"
7+
info = raw_parser(content)
8+
assert info.group == "喵萌奶茶屋&LoliHouse"
9+
assert info.title_zh == "鹿乃子乃子乃子虎视眈眈"
10+
assert info.title_en == "Shikanoko Nokonoko Koshitantan"
11+
assert info.resolution == "1080p"
12+
assert info.episode == 1
13+
assert info.season == 1
14+
15+
# Issue #679, RSS link: https://mikanani.me/RSS/Bangumi?bangumiId=3225&subgroupid=370
16+
content = "[LoliHouse] 轮回七次的反派大小姐,在前敌国享受随心所欲的新婚生活\n / 7th Time Loop - 12 [WebRip 1080p HEVC-10bit AAC][简繁内封字幕][END]"
17+
info = raw_parser(content)
18+
assert info.group == "LoliHouse"
19+
assert info.title_zh == "轮回七次的反派大小姐,在前敌国享受随心所欲的新婚生活"
20+
assert info.title_en == "7th Time Loop"
21+
assert info.resolution == "1080p"
22+
assert info.episode == 12
23+
assert info.season == 1
24+
525
content = "【幻樱字幕组】【4月新番】【古见同学有交流障碍症 第二季 Komi-san wa, Komyushou Desu. S02】【22】【GB_MP4】【1920X1080】"
626
info = raw_parser(content)
727
assert info.title_en == "Komi-san wa, Komyushou Desu."

backend/src/test/test_torrent_parser.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,25 @@ def test_torrent_parser():
7272
assert bf.season == 1
7373
assert bf.episode == 6
7474

75+
file_name = "不时用俄语小声说真心话的邻桌艾莉同学 S01E02.mp4"
76+
bf = torrent_parser(file_name)
77+
assert bf.title == "不时用俄语小声说真心话的邻桌艾莉同学"
78+
assert bf.season == 1
79+
assert bf.episode == 2
80+
81+
file_name = "[ANi] 關於我轉生變成史萊姆這檔事 第三季 - 48.5 [1080P][Baha][WEB-DL][AAC AVC][CHT].mp4"
82+
bf = torrent_parser(file_name, season=3)
83+
assert bf.title == "關於我轉生變成史萊姆這檔事 第三季"
84+
assert bf.season == 3
85+
assert bf.episode == 48.5
86+
87+
file_name = "[ANi] 關於我轉生變成史萊姆這檔事 第三季 - 48.5 [1080P][Baha][WEB-DL][AAC AVC][CHT].srt"
88+
sf = torrent_parser(file_name, season=3, file_type="subtitle")
89+
assert sf.title == "關於我轉生變成史萊姆這檔事 第三季"
90+
assert sf.episode == 48.5
91+
assert sf.season == 3
92+
assert sf.language == "zh-tw"
93+
7594

7695
class TestGetPathBasename:
7796
def test_regular_path(self):

webui/.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"i18n-ally.localesPaths": ["src/i18n"],
33
"commentTranslate.targetLanguage": "zh-CN",
4-
"i18n-ally.sourceLanguage": "en",
4+
"i18n-ally.sourceLanguage": "zh-CN",
55
"typescript.tsdk": "node_modules/typescript/lib",
66
"i18n-ally.keystyle": "nested"
77
}

0 commit comments

Comments
 (0)