-
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1067 from getzze/opensubtitles_com
Add Provider for opensubtitles.com
- Loading branch information
Showing
24 changed files
with
6,866 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.