Subliminal update

This commit is contained in:
Ruud
2012-10-14 17:58:09 +02:00
parent 4dfd8b4cd5
commit 67c87444de
163 changed files with 22377 additions and 804 deletions
+17 -22
View File
@@ -19,9 +19,9 @@
#
from __future__ import unicode_literals
from guessit import fileutils
from guessit import UnicodeMixin, base_text_type, u, s
from guessit.fileutils import load_file_in_same_dir
from guessit.country import Country
from guessit.textutils import to_unicode
import re
import logging
@@ -39,8 +39,7 @@ log = logging.getLogger(__name__)
# "An alpha-3 (bibliographic) code, an alpha-3 (terminologic) code (when given),
# an alpha-2 code (when given), an English name, and a French name of a language
# are all separated by pipe (|) characters."
_iso639_contents = fileutils.load_file_in_same_dir(__file__,
'ISO-639-2_utf-8.txt').decode('utf-8')
_iso639_contents = load_file_in_same_dir(__file__, 'ISO-639-2_utf-8.txt')
# drop the BOM from the beginning of the file
_iso639_contents = _iso639_contents[1:]
@@ -116,7 +115,6 @@ lng_exceptions = { 'unknown': ('und', None),
'cn': ('chi', None),
'chs': ('chi', None),
'jp': ('jpn', None),
'scc': ('srp', None),
'scr': ('hrv', None)
}
@@ -137,7 +135,7 @@ def lang_set(languages, strict=False):
return set(Language(l, strict=strict) for l in languages)
class Language(object):
class Language(UnicodeMixin):
"""This class represents a human language.
You can initialize it with pretty much anything, as it knows conversion
@@ -154,30 +152,30 @@ class Language(object):
>>> Language('fr')
Language(French)
>>> Language('eng').french_name
u'anglais'
>>> s(Language('eng').french_name)
'anglais'
>>> Language('pt(br)').country.english_name
u'Brazil'
>>> s(Language('pt(br)').country.english_name)
'Brazil'
>>> Language('Español (Latinoamérica)').country.english_name
u'Latin America'
>>> s(Language('Español (Latinoamérica)').country.english_name)
'Latin America'
>>> Language('Spanish (Latin America)') == Language('Español (Latinoamérica)')
True
>>> Language('zz', strict=False).english_name
u'Undetermined'
>>> s(Language('zz', strict=False).english_name)
'Undetermined'
>>> Language('pt(br)').opensubtitles
u'pob'
>>> s(Language('pt(br)').opensubtitles)
'pob'
"""
_with_country_regexp = re.compile('(.*)\((.*)\)')
_with_country_regexp2 = re.compile('(.*)-(.*)')
def __init__(self, language, country=None, strict=False, scheme=None):
language = to_unicode(language.strip().lower())
language = u(language.strip().lower())
with_country = (Language._with_country_regexp.match(language) or
Language._with_country_regexp2.match(language))
if with_country:
@@ -249,7 +247,7 @@ class Language(object):
def opensubtitles(self):
if self.lang == 'por' and self.country and self.country.alpha2 == 'br':
return 'pob'
elif self.lang in ['gre', 'eus', 'ice', 'srp']:
elif self.lang in ['gre', 'srp']:
return self.alpha3term
return self.alpha3
@@ -266,7 +264,7 @@ class Language(object):
if isinstance(other, Language):
return self.lang == other.lang
if isinstance(other, basestring):
if isinstance(other, base_text_type):
try:
return self == Language(other)
except ValueError:
@@ -286,9 +284,6 @@ class Language(object):
else:
return self.english_name
def __str__(self):
return unicode(self).encode('utf-8')
def __repr__(self):
if self.country:
return 'Language(%s, country=%s)' % (self.english_name, self.country)