Skip to content

Commit

Permalink
Add Subtitulamos provider integration (#1170)
Browse files Browse the repository at this point in the history
* feat: Add Subtitulamos provider integration

* chore: Add Subtitulamos provider integration - Add changelog

* chore: Add Subtitulamos provider integration - Improve 'Español (Latinoamérica)' support adding all countries

---------

Co-authored-by: getzze <getzze@gmail.com>
  • Loading branch information
Nyaran and getzze authored Nov 11, 2024
1 parent 3e1dc07 commit 3ad9fb4
Show file tree
Hide file tree
Showing 19 changed files with 14,657 additions and 2 deletions.
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

0 comments on commit 3ad9fb4

Please sign in to comment.