mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-24 02:20:38 +08:00
Merge branch 'main' into 3.0-dev
This commit is contained in:
@@ -15,15 +15,6 @@ router = FastAPI()
|
||||
api_func = APIProcess(settings)
|
||||
|
||||
|
||||
@router.on_event("startup")
|
||||
async def startup_event():
|
||||
logger = logging.getLogger("uvicorn.access")
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.INFO)
|
||||
handler.setFormatter(logging.Formatter("[%(asctime)s] %(levelname)-8s %(message)s"))
|
||||
logger.addHandler(handler)
|
||||
|
||||
|
||||
@router.get("/api/v1/data", tags=["info"])
|
||||
async def get_data():
|
||||
try:
|
||||
|
||||
@@ -43,7 +43,7 @@ class Renamer:
|
||||
subtitle_list.append(file_name)
|
||||
return media_list, subtitle_list
|
||||
|
||||
def rename_file(self, info, media_path: str, rename_method: str, bangumi_name: str, season: int, remove_bad_torrents: bool):
|
||||
def rename_file(self, info, media_path: str, method: str, bangumi_name: str, season: int, remove_bad_torrents: bool):
|
||||
torrent_name = info.name
|
||||
suffix = os.path.splitext(media_path)[-1]
|
||||
compare_name = self.get_file_name(media_path)
|
||||
@@ -52,12 +52,12 @@ class Renamer:
|
||||
bangumi_name=bangumi_name,
|
||||
season=season,
|
||||
suffix=suffix,
|
||||
method=rename_method
|
||||
method=method
|
||||
)
|
||||
if compare_name != new_path:
|
||||
try:
|
||||
self._client.rename_torrent_file(_hash=info.hash, old_path=media_path, new_path=new_path)
|
||||
self._notification.send_msg(bangumi_name, "最新剧集已经更新,已自动重命名。")
|
||||
self._notification.send_msg(bangumi_name, f"{new_path}已经更新,已自动重命名。")
|
||||
except Exception as e:
|
||||
logger.warning(f"{torrent_name} rename failed")
|
||||
logger.warning(f"Season name: {bangumi_name}, Season: {season}, Suffix: {suffix}")
|
||||
@@ -65,7 +65,7 @@ class Renamer:
|
||||
# Delete bad torrent
|
||||
self.delete_bad_torrent(info, remove_bad_torrents)
|
||||
|
||||
def rename_collection(self, info, media_list: list[str],bangumi_name: str, season: int, remove_bad_torrents: bool):
|
||||
def rename_collection(self, info, media_list: list[str], bangumi_name: str, season: int, remove_bad_torrents: bool, method: str):
|
||||
_hash = info.hash
|
||||
for media_path in media_list:
|
||||
path_len = len(media_path.split(os.path.sep))
|
||||
@@ -77,7 +77,7 @@ class Renamer:
|
||||
bangumi_name=bangumi_name,
|
||||
season=season,
|
||||
suffix=suffix,
|
||||
method="pn"
|
||||
method=method
|
||||
)
|
||||
if torrent_name != new_name:
|
||||
try:
|
||||
@@ -167,7 +167,7 @@ class Renamer:
|
||||
self.rename_file(
|
||||
info=info,
|
||||
media_path=media_list[0],
|
||||
rename_method=rename_method,
|
||||
method=rename_method,
|
||||
bangumi_name=bangumi_name,
|
||||
season=season,
|
||||
remove_bad_torrents=remove_bad_torrents
|
||||
@@ -183,11 +183,12 @@ class Renamer:
|
||||
elif len(media_list) > 1:
|
||||
logger.info("Start rename collection")
|
||||
self.rename_collection(
|
||||
info,
|
||||
media_list,
|
||||
bangumi_name,
|
||||
season,
|
||||
remove_bad_torrents
|
||||
info=info,
|
||||
media_list=media_list,
|
||||
bangumi_name=bangumi_name,
|
||||
season=season,
|
||||
remove_bad_torrents=remove_bad_torrents,
|
||||
method=rename_method
|
||||
)
|
||||
if len(subtitle_list) > 0:
|
||||
self.rename_subtitles(
|
||||
|
||||
@@ -7,7 +7,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
EPISODE_RE = re.compile(r"\d+")
|
||||
TITLE_RE = re.compile(
|
||||
r"(.*|\[.*])( -? \d+|\[\d+]|\[\d+.?[vV]\d]|[ 第]?\d+[话話集]|\[\d+.?END]|[Ee][Pp]?\d+)(.*)"
|
||||
r"(.*|\[.*])( -? \d+|\[\d+]|\[\d+.?[vV]\d]|第\d+[话話集]|\[第?\d+[话話集]]|\[\d+.?END]|[Ee][Pp]?\d+)(.*)"
|
||||
)
|
||||
RESOLUTION_RE = re.compile(r"1080|720|2160|4K")
|
||||
SOURCE_RE = re.compile(r"B-Global|[Bb]aha|[Bb]ilibili|AT-X|Web")
|
||||
@@ -41,6 +41,10 @@ def prefix_process(raw: str, group: str) -> str:
|
||||
raw = re.sub(f".{group}.", "", raw)
|
||||
raw_process = PREFIX_RE.sub("/", raw)
|
||||
arg_group = raw_process.split("/")
|
||||
while "" in arg_group:
|
||||
arg_group.remove("")
|
||||
if len(arg_group) == 1:
|
||||
arg_group = arg_group[0].split(" ")
|
||||
for arg in arg_group:
|
||||
if re.search(r"新番|月?番", arg) and len(arg) <= 5:
|
||||
raw = re.sub(f".{arg}.", "", raw)
|
||||
@@ -123,6 +127,7 @@ def clean_sub(sub: str | None) -> str | None:
|
||||
return sub
|
||||
return re.sub(r"_MP4|_MKV", "", sub)
|
||||
|
||||
|
||||
def process(raw_title: str):
|
||||
raw_title = raw_title.strip()
|
||||
content_title = pre_process(raw_title)
|
||||
@@ -163,5 +168,9 @@ def raw_parser(raw: str) -> Episode | None:
|
||||
return Episode(name_en, name_zh, name_jp, season, sr, episode, sub, group, dpi, source)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
title = "【幻樱字幕组】【4月新番】【古见同学有交流障碍症 第二季 Komi-san wa, Komyushou Desu. S02】【22】【GB_MP4】【1920X1080】"
|
||||
ep = raw_parser(title)
|
||||
print(ep)
|
||||
|
||||
|
||||
|
||||
@@ -44,8 +44,9 @@ def rename_normal(info: DownloadInfo):
|
||||
for rule in RULES:
|
||||
match_obj = re.match(rule, info.name, re.I)
|
||||
if match_obj is not None:
|
||||
episode = match_obj.group(2)
|
||||
title = re.sub(r"([Ss]|Season )\d{1,3}", "", match_obj.group(1)).strip()
|
||||
new_name = f"{title} S{info.season}E{match_obj.group(2)}{match_obj.group(3)}"
|
||||
new_name = f"{title} S{info.season}E{episode}{match_obj.group(3)}"
|
||||
return new_name
|
||||
|
||||
|
||||
@@ -55,10 +56,11 @@ def rename_pn(info: DownloadInfo):
|
||||
if match_obj is not None:
|
||||
title = re.sub(r"([Ss]|Season )\d{1,3}", "", match_obj.group(1)).strip()
|
||||
title = title if title != "" else info.folder_name
|
||||
episode = match_obj.group(2)
|
||||
new_name = re.sub(
|
||||
r"[\[\]]",
|
||||
"",
|
||||
f"{title} S{info.season}E{match_obj.group(2)}{info.suffix}",
|
||||
f"{title} S{info.season}E{episode}{info.suffix}",
|
||||
)
|
||||
return new_name
|
||||
|
||||
@@ -67,10 +69,11 @@ def rename_advance(info: DownloadInfo):
|
||||
for rule in RULES:
|
||||
match_obj = re.match(rule, info.file_name, re.I)
|
||||
if match_obj is not None:
|
||||
episode = match_obj.group(2)
|
||||
new_name = re.sub(
|
||||
r"[\[\]]",
|
||||
"",
|
||||
f"{info.folder_name} S{info.season}E{match_obj.group(2)}{info.suffix}",
|
||||
f"{info.folder_name} S{info.season}E{episode}{info.suffix}",
|
||||
)
|
||||
return new_name
|
||||
|
||||
@@ -80,10 +83,11 @@ def rename_no_season_pn(info: DownloadInfo):
|
||||
match_obj = re.match(rule, info.file_name, re.I)
|
||||
if match_obj is not None:
|
||||
title = match_obj.group(1).strip()
|
||||
episode = match_obj.group(2)
|
||||
new_name = re.sub(
|
||||
r"[\[\]]",
|
||||
"",
|
||||
f"{title} E{match_obj.group(2)}{info.suffix}",
|
||||
f"{title} E{episode}{info.suffix}",
|
||||
)
|
||||
return new_name
|
||||
|
||||
|
||||
Reference in New Issue
Block a user