Skip to content

Commit

Permalink
Merge pull request #842 from EstrellaXD/revert-841-3.1-dev
Browse files Browse the repository at this point in the history
Revert "3.1.15"
  • Loading branch information
EstrellaXD authored Sep 16, 2024
2 parents 4d2d619 + d8038ba commit 7ce6a10
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 90 deletions.
2 changes: 1 addition & 1 deletion backend/src/module/api/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@router.on_event("startup")
async def startup():
await program.startup()
program.startup()


@router.on_event("shutdown")
Expand Down
44 changes: 24 additions & 20 deletions backend/src/module/core/program.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import asyncio

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

async def startup(self):
def startup(self):
self.__start_info()
if not self.database:
first_run()
Expand All @@ -50,27 +49,32 @@ async def startup(self):
if not self.img_cache:
logger.info("[Core] No image cache exists, create image cache.")
cache_image()
await self.start()
self.start()

async def start(self):
def start(self):
self.stop_event.clear()
settings.load()
while not self.downloader_status:
logger.warning("Downloader is not running.")
logger.info("Waiting for downloader to start.")
await asyncio.sleep(30)
if self.enable_renamer:
self.rename_start()
if self.enable_rss:
self.rss_start()
logger.info("Program running.")
return ResponseModel(
status=True,
status_code=200,
msg_en="Program started.",
msg_zh="程序启动成功。",
)

if self.downloader_status:
if self.enable_renamer:
self.rename_start()
if self.enable_rss:
self.rss_start()
logger.info("Program running.")
return ResponseModel(
status=True,
status_code=200,
msg_en="Program started.",
msg_zh="程序启动成功。",
)
else:
self.stop_event.set()
logger.warning("Program failed to start.")
return ResponseModel(
status=False,
status_code=406,
msg_en="Program failed to start.",
msg_zh="程序启动失败。",
)

def stop(self):
if self.is_running:
Expand Down
4 changes: 2 additions & 2 deletions backend/src/module/models/torrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EpisodeFile(BaseModel):
group: str | None = Field(None)
title: str = Field(...)
season: int = Field(...)
episode: int | float = Field(None)
episode: int = Field(None)
suffix: str = Field(..., regex=r"\.(mkv|mp4|MKV|MP4)$")


Expand All @@ -32,6 +32,6 @@ class SubtitleFile(BaseModel):
group: str | None = Field(None)
title: str = Field(...)
season: int = Field(...)
episode: int | float = Field(None)
episode: int = Field(None)
language: str = Field(..., regex=r"(zh|zh-tw)")
suffix: str = Field(..., regex=r"\.(ass|srt|ASS|SRT)$")
4 changes: 1 addition & 3 deletions backend/src/module/network/request_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ class RequestContent(RequestURL):
def get_torrents(
self,
_url: str,
_filter: str = None,
_filter: str = "|".join(settings.rss_parser.filter),
limit: int = None,
retry: int = 3,
) -> list[Torrent]:
soup = self.get_xml(_url, retry)
if soup:
torrent_titles, torrent_urls, torrent_homepage = rss_parser(soup)
torrents: list[Torrent] = []
if _filter is None:
_filter = "|".join(settings.rss_parser.filter)
for _title, torrent_url, homepage in zip(
torrent_titles, torrent_urls, torrent_homepage
):
Expand Down
2 changes: 1 addition & 1 deletion backend/src/module/parser/analyser/raw_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def clean_sub(sub: str | None) -> str | None:


def process(raw_title: str):
raw_title = raw_title.strip().replace("\n", " ")
raw_title = raw_title.strip().replace("\n", "")
content_title = pre_process(raw_title)
# 预处理标题
group = get_group(content_title)
Expand Down
30 changes: 6 additions & 24 deletions backend/src/module/parser/analyser/torrent_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
PLATFORM = "Unix"

RULES = [
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{1,4}(?:\.\d{1,2})?)(.*)",
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*\.*\d*)[话集話](?:END)?\](.*)",
r"(.*)第?(\d*\.*\d*)[话話集](?:END)?(.*)",
r"(.*)(?:S\d{2})?EP?(\d+)(.*)",
]

SUBTITLE_LANG = {
Expand Down Expand Up @@ -81,7 +81,7 @@ def torrent_parser(
title, season = get_season_and_title(title)
else:
title, _ = get_season_and_title(title)
episode = match_obj.group(2)
episode = int(match_obj.group(2))
suffix = Path(torrent_path).suffix
if file_type == "media":
return EpisodeFile(
Expand All @@ -103,21 +103,3 @@ def torrent_parser(
episode=episode,
suffix=suffix,
)


if __name__ == "__main__":
ep = torrent_parser(
"/不时用俄语小声说真心话的邻桌艾莉同学/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)
20 changes: 0 additions & 20 deletions backend/src/test/test_raw_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,6 @@


def test_raw_parser():
# Issue #794, RSS link: https://mikanani.me/RSS/Bangumi?bangumiId=3367&subgroupid=370
content = "[喵萌奶茶屋&LoliHouse] 鹿乃子乃子乃子虎视眈眈 / Shikanoko Nokonoko Koshitantan\n- 01 [WebRip 1080p HEVC-10bit AAC][简繁内封字幕]"
info = raw_parser(content)
assert info.group == "喵萌奶茶屋&LoliHouse"
assert info.title_zh == "鹿乃子乃子乃子虎视眈眈"
assert info.title_en == "Shikanoko Nokonoko Koshitantan"
assert info.resolution == "1080p"
assert info.episode == 1
assert info.season == 1

# Issue #679, RSS link: https://mikanani.me/RSS/Bangumi?bangumiId=3225&subgroupid=370
content = "[LoliHouse] 轮回七次的反派大小姐,在前敌国享受随心所欲的新婚生活\n / 7th Time Loop - 12 [WebRip 1080p HEVC-10bit AAC][简繁内封字幕][END]"
info = raw_parser(content)
assert info.group == "LoliHouse"
assert info.title_zh == "轮回七次的反派大小姐,在前敌国享受随心所欲的新婚生活"
assert info.title_en == "7th Time Loop"
assert info.resolution == "1080p"
assert info.episode == 12
assert info.season == 1

content = "【幻樱字幕组】【4月新番】【古见同学有交流障碍症 第二季 Komi-san wa, Komyushou Desu. S02】【22】【GB_MP4】【1920X1080】"
info = raw_parser(content)
assert info.title_en == "Komi-san wa, Komyushou Desu."
Expand Down
19 changes: 0 additions & 19 deletions backend/src/test/test_torrent_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,6 @@ def test_torrent_parser():
assert bf.season == 1
assert bf.episode == 6

file_name = "不时用俄语小声说真心话的邻桌艾莉同学 S01E02.mp4"
bf = torrent_parser(file_name)
assert bf.title == "不时用俄语小声说真心话的邻桌艾莉同学"
assert bf.season == 1
assert bf.episode == 2

file_name = "[ANi] 關於我轉生變成史萊姆這檔事 第三季 - 48.5 [1080P][Baha][WEB-DL][AAC AVC][CHT].mp4"
bf = torrent_parser(file_name, season=3)
assert bf.title == "關於我轉生變成史萊姆這檔事 第三季"
assert bf.season == 3
assert bf.episode == 48.5

file_name = "[ANi] 關於我轉生變成史萊姆這檔事 第三季 - 48.5 [1080P][Baha][WEB-DL][AAC AVC][CHT].srt"
sf = torrent_parser(file_name, season=3, file_type="subtitle")
assert sf.title == "關於我轉生變成史萊姆這檔事 第三季"
assert sf.episode == 48.5
assert sf.season == 3
assert sf.language == "zh-tw"


class TestGetPathBasename:
def test_regular_path(self):
Expand Down

0 comments on commit 7ce6a10

Please sign in to comment.