subtitle language improvement

This commit is contained in:
Julien Veyssier 2013-02-27 14:12:15 +01:00
commit 02d61250cf
5 changed files with 20 additions and 25 deletions

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
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')))

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
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')))

View file

@ -17,10 +17,10 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
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')))

View file

@ -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'

View file

@ -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.