Skip to content

Commit d3b8996

Browse files
committed
[80] Improve episode match algorithm
Only compare defined InterfaceID objects, to prevent blank ID comparisons causing a failure to match
1 parent 8874664 commit d3b8996

3 files changed

Lines changed: 33 additions & 14 deletions

File tree

backend/.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.16.0-webui79
1+
v2.16.0-webui80

backend/app/info/episode.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def __repr__(self) -> str:
155155
abs_string = (
156156
''
157157
if self.absolute_number is None
158-
else '_A' + str(self.absolute_number)
158+
else '-A' + str(self.absolute_number)
159159
)
160160

161161
return (
@@ -238,23 +238,41 @@ def __eq__(self, other: 'EpisodeInfo | PlexEpisode | object') -> bool:
238238
(self.tvdb_id, other.tvdb_id),
239239
(self.tvrage_id, other.tvrage_id),
240240
]:
241+
# Interface ID comparison
241242
if (isinstance(this_id, InterfaceID)
242-
and isinstance(other_id, InterfaceID)):
243+
and isinstance(other_id, InterfaceID)
244+
):
245+
# If neither ID is actually defined, skip this
246+
if not this_id or not other_id:
247+
continue
243248
if this_id.equals(other_id):
244249
id_matches += 1
250+
# Do not increment mismatch because interface IDs are
251+
# not strictly comparable
252+
continue
253+
254+
# Regular ID comparison - if this ID is defined and matches,
255+
# count it
245256
if this_id is not None and this_id == other_id:
246257
id_matches += 1
247-
elif (this_id is not None and other_id is not None
248-
and this_id != other_id):
258+
# Both IDs are defined but do not match, count as mismatch
259+
elif (this_id is not None
260+
and other_id is not None
261+
and this_id != other_id
262+
):
249263
id_mismatches += 1
250264

251-
# More than one ID match is equality, more than one mismatch is
252-
# an inequality
253-
if id_matches > 1:
254-
return True
255-
if (id_matches == 1
256-
and self.season_number == other.season_number
257-
and self.episode_number == other.episode_number):
265+
# More than one ID match is an equality, one match and index
266+
# match is equality, and more than one ID mismatch is not a
267+
# match
268+
if (
269+
(id_matches > 1 and id_matches > id_mismatches)
270+
or (
271+
id_matches == 1
272+
and self.season_number == other.season_number
273+
and self.episode_number == other.episode_number
274+
)
275+
):
258276
return True
259277
if id_mismatches > 1:
260278
return False

backend/app/info/util.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ def match_episode_infos(
155155

156156
ref_infos = [_to_episode_info(ref) for ref in references]
157157
match_lists: list[list[_SearchT]] = [[] for _ in references]
158-
# Parallel lists tracking the normalized EpisodeInfo for each match/unmatch
159-
# entry so they can be rendered in the summary table without re-normalizing.
158+
# Parallel lists tracking the normalized EpisodeInfo for each
159+
# match/unmatch entry so they can be rendered in the summary table
160+
# without re-normalizing
160161
match_infos: list[list[EpisodeInfo]] = [[] for _ in references]
161162
unmatched: list[_SearchT] = []
162163
unmatched_infos: list[EpisodeInfo] = []

0 commit comments

Comments
 (0)