Skip to content

Commit

Permalink
add Provider for OpenSubtitles.Com
Browse files Browse the repository at this point in the history
  • Loading branch information
getzze committed May 9, 2024
1 parent 2207bd5 commit c46cab3
Show file tree
Hide file tree
Showing 21 changed files with 6,852 additions and 2 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def find_version(*file_paths):
setup_requirements = ['pytest-runner'] if {'pytest', 'test', 'ptr'}.intersection(sys.argv) else []

install_requirements = ['guessit>=3.0.0', 'babelfish>=0.5.2', 'enzyme>=0.4.1', 'beautifulsoup4>=4.4.0',
'requests>=2.0', 'click>=4.0', 'dogpile.cache>=0.6.0', 'stevedore>=1.20.0',
'requests>=2.0', 'requests_cache', 'click>=4.0', 'dogpile.cache>=0.6.0',
'chardet>=2.3.0', 'srt>=3.5.0', 'six>=1.9.0', 'appdirs>=1.3', 'rarfile>=2.7',
'pytz>=2012c', 'setuptools']
'pytz>=2012c', 'stevedore>=1.20.0', 'setuptools']
if sys.version_info < (3, 2):
install_requirements.append('futures>=3.0')

Expand Down
32 changes: 32 additions & 0 deletions subliminal/converters/opensubtitlescom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
from babelfish import LanguageReverseConverter, language_converters


class OpenSubtitlesComConverter(LanguageReverseConverter):
def __init__(self):
self.alpha2_converter = language_converters['alpha2']
self.from_opensubtitlescom = {
'pt-br': ('por', 'BR'),
'pt-pt': ('por', 'PT'),
'zh-cn': ('zho', 'CN'),
'zh-tw': ('zho', 'TW'),
'ze': ('zho', 'US'),
'me': ('srp', 'ME'),
}
self.to_opensubtitlescom = {v: k for k, v in self.from_opensubtitlescom.items()}
self.codes = self.alpha2_converter.codes | set(self.from_opensubtitlescom.keys())

def convert(self, alpha3, country=None, script=None):
if (alpha3, country) in self.to_opensubtitlescom:
return self.to_opensubtitlescom[(alpha3, country)]
if (alpha3,) in self.to_opensubtitlescom:
return self.to_opensubtitlescom[(alpha3,)]

return self.alpha2_converter.convert(alpha3, country, script)

def reverse(self, opensubtitlescom):
opensubtitlescom_lower = opensubtitlescom.lower()
if opensubtitlescom_lower in self.from_opensubtitlescom:
return self.from_opensubtitlescom[opensubtitlescom_lower]

return self.alpha2_converter.reverse(opensubtitlescom)
2 changes: 2 additions & 0 deletions subliminal/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def unregister(self, entry_point):
'argenteam = subliminal.providers.argenteam:ArgenteamProvider',
'napiprojekt = subliminal.providers.napiprojekt:NapiProjektProvider',
'opensubtitles = subliminal.providers.opensubtitles:OpenSubtitlesProvider',
'opensubtitlescom = subliminal.providers.opensubtitlescom:OpenSubtitlesComProvider',
'opensubtitlescomvip = subliminal.providers.opensubtitlescom:OpenSubtitlesComVipProvider',
'opensubtitlesvip = subliminal.providers.opensubtitles:OpenSubtitlesVipProvider',
'podnapisi = subliminal.providers.podnapisi:PodnapisiProvider',
'shooter = subliminal.providers.shooter:ShooterProvider',
Expand Down
Loading

0 comments on commit c46cab3

Please sign in to comment.