Skip to content

Commit 5c1c5e2

Browse files
authored
Merge pull request #676 from KotaHv/fix-subtitles
fix: subtitle file rename failure in collection
2 parents 004b1ce + 3fb6cf6 commit 5c1c5e2

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

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

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -69,36 +69,37 @@ def torrent_parser(
6969
file_type: str = "media",
7070
) -> EpisodeFile | SubtitleFile:
7171
media_path = get_path_basename(torrent_path)
72-
for rule in RULES:
73-
if torrent_name:
74-
match_obj = re.match(rule, torrent_name, re.I)
75-
else:
76-
match_obj = re.match(rule, media_path, re.I)
77-
if match_obj:
78-
group, title = get_group(match_obj.group(1))
79-
if not season:
80-
title, season = get_season_and_title(title)
81-
else:
82-
title, _ = get_season_and_title(title)
83-
episode = int(match_obj.group(2))
84-
suffix = Path(torrent_path).suffix
85-
if file_type == "media":
86-
return EpisodeFile(
87-
media_path=torrent_path,
88-
group=group,
89-
title=title,
90-
season=season,
91-
episode=episode,
92-
suffix=suffix,
93-
)
94-
elif file_type == "subtitle":
95-
language = get_subtitle_lang(media_path)
96-
return SubtitleFile(
97-
media_path=torrent_path,
98-
group=group,
99-
title=title,
100-
season=season,
101-
language=language,
102-
episode=episode,
103-
suffix=suffix,
104-
)
72+
match_names = [torrent_name, media_path]
73+
if torrent_name is None:
74+
match_names = match_names[1:]
75+
for match_name in match_names:
76+
for rule in RULES:
77+
match_obj = re.match(rule, match_name, re.I)
78+
if match_obj:
79+
group, title = get_group(match_obj.group(1))
80+
if not season:
81+
title, season = get_season_and_title(title)
82+
else:
83+
title, _ = get_season_and_title(title)
84+
episode = int(match_obj.group(2))
85+
suffix = Path(torrent_path).suffix
86+
if file_type == "media":
87+
return EpisodeFile(
88+
media_path=torrent_path,
89+
group=group,
90+
title=title,
91+
season=season,
92+
episode=episode,
93+
suffix=suffix,
94+
)
95+
elif file_type == "subtitle":
96+
language = get_subtitle_lang(media_path)
97+
return SubtitleFile(
98+
media_path=torrent_path,
99+
group=group,
100+
title=title,
101+
season=season,
102+
language=language,
103+
episode=episode,
104+
suffix=suffix,
105+
)

0 commit comments

Comments
 (0)