Skip to content

Commit 56a143b

Browse files
committed
fix parser error
1 parent 71c7727 commit 56a143b

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def parser(self, title: str) -> Episode:
9292
if episode is None:
9393
episode = self.get_untrusted_episode()
9494

95-
if not self.episode_trusted:
95+
if not self.season_trusted:
9696
season, season_raw = self.get_untrusted_season()
9797

9898

@@ -104,6 +104,7 @@ def parser(self, title: str) -> Episode:
104104
# 暂时没有哪个组把集数放前面
105105
if len(parts) > 1:
106106
temp_title = "[]".join(parts[:-1])
107+
print(temp_title)
107108
self.token = re.split(r"[\[\]]", temp_title)
108109
(
109110
name_en,
@@ -116,7 +117,7 @@ def parser(self, title: str) -> Episode:
116117
source = source_info[0] if source_info else ""
117118
sub = sub_language
118119
resolution = resolution_info[0] if resolution_info else ""
119-
logger.debug(f"[meta parser] {self.raw_title} >> S{season}E{episode} {name_zh}/{name_en}/{name_jp} {sub} {sub_type} {group} {year} {resolution} {source} {audio_info} {video_info}")
120+
# logger.debug(f"[meta parser] {self.raw_title} >> S{season}E{episode} {name_zh}/{name_en}/{name_jp} {sub} {sub_type} {group} {year} {resolution} {source} {audio_info} {video_info}")
120121

121122
return Episode(
122123
title_en=name_en,
@@ -235,18 +236,21 @@ def get_untrusted_episode(self) -> int:
235236
def get_trusted_season(self) -> tuple[int, str]:
236237
"""获取可信的季度信息"""
237238
season_info = self.findall_sub_title(p.SEASON_PATTERN_TRUEST, sym="/[]")
239+
print(f"trusted season info: {season_info}")
238240
if not season_info:
239241
season_info = self.findall_sub_title(p.SEASON_PATTERN, sym="/[]")
240242

243+
241244
if season_info:
242245
self.season_trusted = True
243246
return self.parse_season(season_info, True)
244247
# return season_info[0][0], season
245-
return 0, ""
248+
return 1, ""
246249

247250
def get_untrusted_season(self) -> tuple[int, str]:
248251
"""获取不可信的季度信息"""
249252
season_info = re.findall(p.SEASON_PATTERN_UNTRUSTED, self.title)
253+
print(f"untrusted season info: {season_info}")
250254
if season_info:
251255
return self.parse_season(season_info, False)
252256
return 1, ""
@@ -290,6 +294,7 @@ def name_process(self) -> tuple[str, str, str]:
290294
self.token = [token.strip() for token in self.token[:max_len] if len(token.strip()) > 1]
291295

292296
self.token = self.token[:5]
297+
print(f"tokens: {self.token}")
293298
token_priority = [len(s) for s in self.token]
294299
if len(self.token) == 1:
295300
anime_title = self.token[0]
@@ -307,10 +312,11 @@ def name_process(self) -> tuple[str, str, str]:
307312
token_priority[idx] -= 90
308313
if re.search(r"[a-zA-Z]{3,}", token):
309314
token_priority[idx] += 2
310-
if re.search(r"[\u0800-\u4e00]{2,}", token):
311-
token_priority[idx] += 2
312-
if re.search(r"[\u4e00-\u9fa5]{2,}", token):
313-
token_priority[idx] += 2
315+
if l:=re.search(r"[\u0800-\u4e00]{2,}", token):
316+
token_priority[idx] += len(l.group(0))*2
317+
if l:=re.search(r"[\u4e00-\u9fa5]{2,}", token):
318+
token_priority[idx] += len(l.group(0))*2
319+
print(token_priority)
314320
idx = token_priority.index(max(token_priority))
315321
anime_title = self.token[idx]
316322
anime_title = anime_title.strip()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
(第(.{1,3})季 # 匹配"第...季"格式
6060
|第(.{1,3})期 # 匹配"第...期"格式
6161
|第.{1,3}部分 # 匹配"第...部分"格式
62-
|[Ss]eason\s?(\d{{1,2}}) # 匹配"Season X"格式
63-
|SEASON\s?(\d{{1,2}}) # 匹配"SEASON X"格式
62+
|[Ss]eason\s?(\d{1,2}) # 匹配"Season X"格式
63+
|SEASON\s?(\d{1,2}) # 匹配"SEASON X"格式
6464
)
6565
""",
6666
re.VERBOSE

backend/src/test/test_raw_parser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ def test_raw_parser():
66
info = TitleMetaParser().parser(content)
77
assert info is not None
88
assert info.group == "幻樱字幕组"
9-
assert info.title_en == "Komi-san wa, Komyushou Desu."
9+
assert info.title_zh == "古见同学有交流障碍症"
10+
# assert info.title_en == "Komi-san wa, Komyushou Desu."
1011
assert info.resolution == "1920X1080"
1112
assert info.episode == 22
1213
assert info.season == 2
@@ -145,6 +146,7 @@ def test_raw_parser():
145146
assert info.group == "桜都字幕组&7³ACG"
146147
assert info.title_jp == "ゆるキャン△"
147148
assert info.sub == "简繁"
149+
assert info.episode == -1
148150

149151
content = "[ANi] Grand Blue Dreaming / GRAND BLUE 碧蓝之海 2 - 04 [1080P][Baha][WEB-DL][AAC AVC][CHT][MP4]"
150152
info = TitleMetaParser().parser(content)

0 commit comments

Comments
 (0)