Skip to content

Commit

Permalink
chore: Add Subtitulamos provider integration - Improve 'Español (Lati…
Browse files Browse the repository at this point in the history
…noamérica)' support adding all countries
  • Loading branch information
Nyaran committed Nov 11, 2024
1 parent b9ee818 commit 9b9079a
Show file tree
Hide file tree
Showing 4 changed files with 1,646 additions and 11 deletions.
22 changes: 22 additions & 0 deletions subliminal/converters/subtitulamos.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ def __init__(self) -> None:
}
self.to_subtitulamos: dict[tuple[str, str | None], str] = {
item[1]: item[0] for item in self.from_subtitulamos.items()
} | {
('spa', country): 'Español (Latinoamérica)'
for country in [
'AR', # Argentina
'BO', # Bolivia
'CL', # Chile
'CO', # Colombia
'CR', # Costa Rica
'DO', # República Dominicana
'EC', # Ecuador
'GT', # Guatemala
'HN', # Honduras
'NI', # Nicaragua
'PA', # Panamá
'PE', # Perú
'PR', # Puerto Rico
'PY', # Paraguay
'SV', # El Salvador
'US', # United States
'UY', # Uruguay
'VE', # Venezuela
]
}
self.codes = set(self.from_subtitulamos.keys())

Expand Down
54 changes: 43 additions & 11 deletions subliminal/providers/subtitulamos.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,36 @@
language_converters.register('subtitulamos = subliminal.converters.subtitulamos:SubtitulamosConverter')


subtitulamos_languages = (
{Language('por', 'BR')}
| {
Language('spa', country)
for country in [
'AR', # Argentina
'BO', # Bolivia
'CL', # Chile
'CO', # Colombia
'CR', # Costa Rica
'DO', # República Dominicana
'EC', # Ecuador
'GT', # Guatemala
'HN', # Honduras
'MX', # México
'NI', # Nicaragua
'PA', # Panamá
'PE', # Perú
'PR', # Puerto Rico
'PY', # Paraguay
'SV', # El Salvador
'US', # United States
'UY', # Uruguay
'VE', # Venezuela
]
}
| {Language(lang) for lang in ['cat', 'eng', 'glg', 'por', 'spa']}
)


class SubtitulamosSubtitle(Subtitle):
"""Subtitulamos Subtitle."""

Expand Down Expand Up @@ -90,9 +120,7 @@ def get_matches(self, video: Video) -> set[str]:
class SubtitulamosProvider(Provider):
"""Subtitulamos Provider."""

languages: ClassVar[Set[Language]] = {Language('por', 'BR')} | {
Language(lang) for lang in ['cat', 'eng', 'glg', 'por', 'spa']
}
languages: ClassVar[Set[Language]] = subtitulamos_languages
video_types: ClassVar = (Episode,)

server_url = 'https://www.subtitulamos.tv'
Expand Down Expand Up @@ -230,13 +258,6 @@ def _query_provider(

hearing_impaired = False

# modify spanish latino subtitle language to only spanish and set hearing_impaired = True
# because if exists spanish and spanish latino subtitle for the same episode, the score will be
# higher with spanish subtitle. Spanish subtitle takes priority.
if language == Language('spa', 'MX'):
language = Language('spa')
hearing_impaired = True

# read the release subtitle
release_group = release_group_element[0].getText()

Expand Down Expand Up @@ -279,7 +300,18 @@ def list_subtitles(self, video: Video, languages: Set[Language]) -> list[Subtitu
if not isinstance(video, Episode):
return []

return [s for s in self.query(video.series, video.season, video.episode, video.year) if s.language in languages]
result = []
for subtitle in self.query(video.series, video.season, video.episode, video.year):
subtitle_lang = next(
(lang for lang in languages if lang.subtitulamos == subtitle.language.subtitulamos), None
)
if subtitle_lang:
result.append(subtitle)
# All spanish variations are labeled as "Español (Latinoamérica)",
# which is guessed as es-MX; this replaces it with the specified one.
subtitle.language = subtitle_lang

return result

def download_subtitle(self, subtitle: SubtitulamosSubtitle) -> None:
"""Download the content of the subtitle."""
Expand Down
Loading

0 comments on commit 9b9079a

Please sign in to comment.