Skip to content

Commit

Permalink
avoid subtitle duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
getzze committed Jul 9, 2024
1 parent cf06887 commit 600d68d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.d/1146.provider.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[OpenSubtitlesCom] Avoid duplicate subtitles
5 changes: 1 addition & 4 deletions subliminal/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,7 @@ def check(cls, video: Video) -> bool:
"""
if not cls.check_types(video):
return False
if cls.required_hash is not None and cls.required_hash not in video.hashes:
return False

return True
return cls.required_hash is None or cls.required_hash in video.hashes

@classmethod
def check_types(cls, video: Video) -> bool:
Expand Down
10 changes: 7 additions & 3 deletions subliminal/providers/opensubtitlescom.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def query(
# fill the search criteria
criteria = self._make_query(**kwargs)

subtitles = []
subtitles: list[OpenSubtitlesComSubtitle] = []

for criterion in criteria:
# add the language and query the server
Expand All @@ -695,8 +695,12 @@ def query(
imdb_match=imdb_match,
tmdb_match=tmdb_match,
)
logger.debug('Found subtitle %r', subtitle)
subtitles.append(subtitle)

# Some criteria are redundant, so skip duplicates
unique_ids = [s.id for s in subtitles]
if subtitle.id not in unique_ids:
logger.debug('Found subtitle %r', subtitle)
subtitles.append(subtitle)

# filter out the machine translated subtitles
if not allow_machine_translated:
Expand Down

0 comments on commit 600d68d

Please sign in to comment.