Skip to content

Commit

Permalink
sort by language type before sorting by score
Browse files Browse the repository at this point in the history
  • Loading branch information
getzze committed Oct 7, 2024
1 parent 06df560 commit afa239a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions subliminal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def list_subtitles_provider(self, provider: str, video: Video, languages: Set[La
try:
return self[provider].list_subtitles(video, provider_languages)
except Exception as e: # noqa: BLE001
handle_exception(e, 'Provider {provider}')
handle_exception(e, f'Provider {provider}')

return []

Expand Down Expand Up @@ -251,10 +251,14 @@ def download_best_subtitles(
# ignore subtitles
subtitles = [s for s in subtitles if s.id not in ignore_subtitles]

# filter by hearing impaired and foreign only
# sort by hearing impaired and foreign only
language_type = LanguageType.from_flags(hearing_impaired=hearing_impaired, foreign_only=foreign_only)
if language_type != LanguageType.UNKNOWN:
subtitles = [s for s in subtitles if s.language_type == language_type]
subtitles = sorted(
subtitles,
key=lambda s: s.language_type == language_type,
reverse=True,
)

# sort subtitles by score
scored_subtitles = sorted(
Expand Down

0 comments on commit afa239a

Please sign in to comment.