Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Subtitulamos provider integration #1170

Merged
merged 15 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1170.provider.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added Subtitulamos provider
6 changes: 6 additions & 0 deletions docs/api/providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ Podnapisi
:members:
:private-members:

Subtitulamos
------------
.. automodule:: subliminal.providers.subtitulamos
:members:
:private-members:

TVsubtitles
-----------
.. automodule:: subliminal.providers.tvsubtitles
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ opensubtitlesvip = "subliminal.providers.opensubtitles:OpenSubtitlesVipProvider"
opensubtitlescom = "subliminal.providers.opensubtitlescom:OpenSubtitlesComProvider"
opensubtitlescomvip = "subliminal.providers.opensubtitlescom:OpenSubtitlesComVipProvider"
podnapisi = "subliminal.providers.podnapisi:PodnapisiProvider"
subtitulamos = "subliminal.providers.subtitulamos:SubtitulamosProvider"
tvsubtitles = "subliminal.providers.tvsubtitles:TVsubtitlesProvider"

[project.entry-points."subliminal.refiners"]
Expand Down
69 changes: 69 additions & 0 deletions subliminal/converters/subtitulamos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""Language converter for Subtitulamos."""

from __future__ import annotations

from typing import TYPE_CHECKING

from babelfish import LanguageReverseConverter, language_converters # type: ignore[import-untyped]

if TYPE_CHECKING:
from . import LanguageTuple


class SubtitulamosConverter(LanguageReverseConverter):
"""Language converter for Subtitulamos."""

def __init__(self) -> None:
self.name_converter = language_converters['name']
self.from_subtitulamos: dict[str, tuple[str, str | None]] = {
'Español': ('spa', None),
'Español (España)': ('spa', None),
'Español (Latinoamérica)': ('spa', 'MX'),
'Català': ('cat', None),
'English': ('eng', None),
'Galego': ('glg', None),
'Portuguese': ('por', None),
'English (US)': ('eng', 'US'),
'English (UK)': ('eng', 'GB'),
'Brazilian': ('por', 'BR'),
}
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())

def convert(self, alpha3: str, country: str | None = None, script: str | None = None) -> str:
"""Convert an alpha3 language code with an alpha2 country code and a script code into a custom code."""
if (alpha3, country) in self.to_subtitulamos:
return self.to_subtitulamos[(alpha3, country)]

return self.name_converter.convert(alpha3, country, script) # type: ignore[no-any-return]

def reverse(self, code: str) -> LanguageTuple:
"""Reverse a custom code into alpha3, country and script code."""
if code in self.from_subtitulamos:
return (*self.from_subtitulamos[code], None)

return self.name_converter.reverse(code) # type: ignore[no-any-return]
1 change: 1 addition & 0 deletions subliminal/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def parse_entry_point(src: str, group: str) -> EntryPoint:
'opensubtitlescomvip = subliminal.providers.opensubtitlescom:OpenSubtitlesComVipProvider',
'opensubtitlesvip = subliminal.providers.opensubtitles:OpenSubtitlesVipProvider',
'podnapisi = subliminal.providers.podnapisi:PodnapisiProvider',
'subtitulamos = subliminal.providers.subtitulamos:SubtitulamosProvider',
'tvsubtitles = subliminal.providers.tvsubtitles:TVsubtitlesProvider',
],
)
Expand Down
Loading
Loading