diff --git a/modules/attilasub/backend.py b/modules/attilasub/backend.py index bfe0446e..25ada04d 100644 --- a/modules/attilasub/backend.py +++ b/modules/attilasub/backend.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see . -from weboob.capabilities.subtitle import ICapSubtitle +from weboob.capabilities.subtitle import ICapSubtitle,LanguageNotSupported from weboob.tools.backend import BaseBackend from .browser import AttilasubBrowser @@ -52,5 +52,5 @@ class AttilasubBackend(BaseBackend, ICapSubtitle): def iter_subtitles(self, language, pattern): if language not in self.LANGUAGE_LIST: - return [] + raise LanguageNotSupported() return self.browser.iter_subtitles(language,quote_plus(pattern.encode('utf-8'))) diff --git a/modules/opensubtitles/backend.py b/modules/opensubtitles/backend.py index e1b8acac..96313f15 100644 --- a/modules/opensubtitles/backend.py +++ b/modules/opensubtitles/backend.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see . -from weboob.capabilities.subtitle import ICapSubtitle +from weboob.capabilities.subtitle import ICapSubtitle,LanguageNotSupported from weboob.tools.backend import BaseBackend from .browser import OpensubtitlesBrowser,LANGUAGE_CONV @@ -51,5 +51,5 @@ class OpensubtitlesBackend(BaseBackend, ICapSubtitle): def iter_subtitles(self, language, pattern): if language not in LANGUAGE_CONV.keys(): - return [] + raise LanguageNotSupported() return self.browser.iter_subtitles(language,quote_plus(pattern.encode('utf-8'))) diff --git a/modules/tvsubtitles/backend.py b/modules/tvsubtitles/backend.py index 5fb9508a..dbfb694b 100644 --- a/modules/tvsubtitles/backend.py +++ b/modules/tvsubtitles/backend.py @@ -17,10 +17,10 @@ # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see . -from weboob.capabilities.subtitle import ICapSubtitle +from weboob.capabilities.subtitle import ICapSubtitle,LanguageNotSupported from weboob.tools.backend import BaseBackend -from .browser import TvsubtitlesBrowser,LANGUAGE_CONV +from .browser import TvsubtitlesBrowser,LANGUAGE_LIST from urllib import quote_plus @@ -50,6 +50,6 @@ class TvsubtitlesBackend(BaseBackend, ICapSubtitle): return self.browser.openurl(subtitle.url.encode('utf-8')).read() def iter_subtitles(self, language, pattern): - if language not in LANGUAGE_CONV.keys(): - return [] + if language not in LANGUAGE_LIST: + raise LanguageNotSupported() return self.browser.iter_subtitles(language,quote_plus(pattern.encode('utf-8'))) diff --git a/modules/tvsubtitles/browser.py b/modules/tvsubtitles/browser.py index 4aad8b2a..fb7eefde 100644 --- a/modules/tvsubtitles/browser.py +++ b/modules/tvsubtitles/browser.py @@ -25,23 +25,9 @@ from .pages import SeriePage, SearchPage, SeasonPage,HomePage __all__ = ['OpensubtitlesBrowser'] -LANGUAGE_CONV = { -'ar':'ara', 'eo':'epo', 'ga':'', 'ru':'rus', -'af':'' , 'et':'est', 'it':'ita', 'sr':'scc', -'sq':'alb', 'tl':'' , 'ja':'jpn', 'sk':'slo', -'hy':'arm', 'fi':'fin', 'kn':'', 'sl':'slv', -'az':'' , 'fr':'fre', 'ko':'kor', 'es':'spa', -'eu':'baq', 'gl':'glg', 'la':'', 'sw':'swa', -'be':'' , 'ka':'geo', 'lv':'lav', 'sv':'swe', -'bn':'ben', 'de':'ger', 'lt':'lit', 'ta':'', -'bg':'bul', 'gr':'ell', 'mk':'mac', 'te':'tel', -'ca':'cat', 'gu':'' , 'ms':'may', 'th':'tha', -'zh':'chi', 'ht':'' , 'mt':'', 'tr':'tur', -'hr':'hrv', 'iw':'heb', 'no':'nor', 'uk':'ukr', -'cz':'cze', 'hi':'hin', 'fa':'per', 'ur':'urd', -'da':'dan', 'hu':'hun', 'pl':'pol', 'vi':'vie', -'nl':'dut', 'is':'ice', 'pt':'por', 'cy':'', -'en':'eng', 'id':'ind', 'ro':'rum', 'yi':''} +LANGUAGE_LIST = ['en','es','fr','de','br','ru','ua','it','gr', + 'ar','hu','pl','tr','nl','pt','sv','da','fi', + 'ko','cn','jp','bg','cz','ro'] class TvsubtitlesBrowser(BaseBrowser): DOMAIN = 'www.tvsubtitles.net' diff --git a/weboob/capabilities/subtitle.py b/weboob/capabilities/subtitle.py index db0b2c2e..87d0447d 100644 --- a/weboob/capabilities/subtitle.py +++ b/weboob/capabilities/subtitle.py @@ -25,6 +25,15 @@ from .base import IBaseCap, CapBaseObject, Field, StringField, FloatField, \ __all__ = ['Subtitle', 'ICapSubtitle'] +class LanguageNotSupported(UserError): + """ + Raised when the language is not supported + """ + + def __init__(self, msg='language is not supported'): + UserError.__init__(self, msg) + + class Subtitle(CapBaseObject): """ Subtitle object.