Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
version 6.1
Browse files Browse the repository at this point in the history
Historical commit version 6.1 (03.04.2015).
  • Loading branch information
hugbug committed Apr 3, 2015
1 parent cf50a24 commit edb3484
Show file tree
Hide file tree
Showing 32 changed files with 168 additions and 464 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
videosort-6.1:
- updated library babelfish used by guessit; this fixes a rare error regarding unicode characters.

videosort-6.0:
- added support for "part"s; they are now treated as episodes;
- fixed: certain words were stripped from titles;
Expand Down
2 changes: 1 addition & 1 deletion VideoSort.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# Author: Andrey Prygunkov ([email protected]).
# Web-site: http://nzbget.net/VideoSort.
# License: GPLv3 (http://www.gnu.org/licenses/gpl.html).
# PP-Script Version: 6.0.
# PP-Script Version: 6.1.
#
# NOTE: This script requires Python 2.x to be installed on your system.

Expand Down
18 changes: 12 additions & 6 deletions lib/babelfish/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014 the BabelFish authors. All rights reserved.
# Copyright (c) 2013 the BabelFish authors. All rights reserved.
# Use of this source code is governed by the 3-clause BSD license
# that can be found in the LICENSE file.
#
__title__ = 'babelfish'
__version__ = '0.5.1.memory0'
__version__ = '0.5.4'
__author__ = 'Antoine Bertin'
__license__ = 'BSD'
__copyright__ = 'Copyright 2013 the BabelFish authors'

import sys

if sys.version_info[0] >= 3:
basestr = str
else:
basestr = basestring

from .converters import (LanguageConverter, LanguageReverseConverter, LanguageEquivalenceConverter, CountryConverter,
CountryReverseConverter)
from .country import country_converters, COUNTRIES, Country
from .country import country_converters, COUNTRIES, COUNTRY_MATRIX, Country
from .exceptions import Error, LanguageConvertError, LanguageReverseError, CountryConvertError, CountryReverseError
from .language import language_converters, LANGUAGES, Language
from .script import SCRIPTS, Script
from .iso import get_countries_data, get_languages_data, get_scripts_data
from .language import language_converters, LANGUAGES, LANGUAGE_MATRIX, Language
from .script import SCRIPTS, SCRIPT_MATRIX, Script
Binary file added lib/babelfish/__init__.pyo
Binary file not shown.
25 changes: 0 additions & 25 deletions lib/babelfish/compat.py

This file was deleted.

17 changes: 11 additions & 6 deletions lib/babelfish/converters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2014 the BabelFish authors. All rights reserved.
# Copyright (c) 2013 the BabelFish authors. All rights reserved.
# Use of this source code is governed by the 3-clause BSD license
# that can be found in the LICENSE file.
#
Expand Down Expand Up @@ -140,6 +140,7 @@ class MyCodeConverter(babelfish.LanguageEquivalenceConverter):
CASE_SENSITIVE = False

def __init__(self):
self.codes = set()
self.to_symbol = {}
if self.CASE_SENSITIVE:
self.from_symbol = {}
Expand All @@ -149,10 +150,7 @@ def __init__(self):
for alpha3, symbol in self.SYMBOLS.items():
self.to_symbol[alpha3] = symbol
self.from_symbol[symbol] = (alpha3, None, None)

@property
def codes(self):
return frozenset(self.from_symbol.keys())
self.codes.add(symbol)

def convert(self, alpha3, country=None, script=None):
try:
Expand Down Expand Up @@ -243,7 +241,14 @@ def __getitem__(self, name):
return self.converters[ep.name]
for ep in (EntryPoint.parse(c) for c in self.registered_converters + self.internal_converters):
if ep.name == name:
self.converters[ep.name] = ep.load(require=False)()
# `require` argument of ep.load() is deprecated in newer versions of setuptools
if hasattr(ep, 'resolve'):
plugin = ep.resolve()
elif hasattr(ep, '_load'):
plugin = ep._load()
else:
plugin = ep.load(require=False)
self.converters[ep.name] = plugin()
return self.converters[ep.name]
raise KeyError(name)

Expand Down
Binary file added lib/babelfish/converters/__init__.pyo
Binary file not shown.
6 changes: 3 additions & 3 deletions lib/babelfish/converters/alpha2.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014 the BabelFish authors. All rights reserved.
# Copyright (c) 2013 the BabelFish authors. All rights reserved.
# Use of this source code is governed by the 3-clause BSD license
# that can be found in the LICENSE file.
#
from __future__ import unicode_literals
from . import LanguageEquivalenceConverter
from ..iso import get_languages_data
from ..language import LANGUAGE_MATRIX


class Alpha2Converter(LanguageEquivalenceConverter):
CASE_SENSITIVE = True
SYMBOLS = {}
for iso_language in get_languages_data():
for iso_language in LANGUAGE_MATRIX:
if iso_language.alpha2:
SYMBOLS[iso_language.alpha3] = iso_language.alpha2
Binary file added lib/babelfish/converters/alpha2.pyo
Binary file not shown.
6 changes: 3 additions & 3 deletions lib/babelfish/converters/alpha3b.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014 the BabelFish authors. All rights reserved.
# Copyright (c) 2013 the BabelFish authors. All rights reserved.
# Use of this source code is governed by the 3-clause BSD license
# that can be found in the LICENSE file.
#
from __future__ import unicode_literals
from . import LanguageEquivalenceConverter
from ..iso import get_languages_data
from ..language import LANGUAGE_MATRIX


class Alpha3BConverter(LanguageEquivalenceConverter):
CASE_SENSITIVE = True
SYMBOLS = {}
for iso_language in get_languages_data():
for iso_language in LANGUAGE_MATRIX:
if iso_language.alpha3b:
SYMBOLS[iso_language.alpha3] = iso_language.alpha3b
Binary file added lib/babelfish/converters/alpha3b.pyo
Binary file not shown.
6 changes: 3 additions & 3 deletions lib/babelfish/converters/alpha3t.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014 the BabelFish authors. All rights reserved.
# Copyright (c) 2013 the BabelFish authors. All rights reserved.
# Use of this source code is governed by the 3-clause BSD license
# that can be found in the LICENSE file.
#
from __future__ import unicode_literals
from . import LanguageEquivalenceConverter
from ..iso import get_languages_data
from ..language import LANGUAGE_MATRIX


class Alpha3TConverter(LanguageEquivalenceConverter):
CASE_SENSITIVE = True
SYMBOLS = {}
for iso_language in get_languages_data():
for iso_language in LANGUAGE_MATRIX:
if iso_language.alpha3t:
SYMBOLS[iso_language.alpha3] = iso_language.alpha3t
12 changes: 5 additions & 7 deletions lib/babelfish/converters/countryname.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014 the BabelFish authors. All rights reserved.
# Copyright (c) 2013 the BabelFish authors. All rights reserved.
# Use of this source code is governed by the 3-clause BSD license
# that can be found in the LICENSE file.
#
from __future__ import unicode_literals
from . import CountryReverseConverter, CaseInsensitiveDict
from ..iso import get_countries_data
from ..country import COUNTRY_MATRIX
from ..exceptions import CountryConvertError, CountryReverseError


class CountryNameConverter(CountryReverseConverter):
def __init__(self):
self.codes = set()
self.to_name = {}
self.from_name = CaseInsensitiveDict()
for country in get_countries_data():
for country in COUNTRY_MATRIX:
self.codes.add(country.name)
self.to_name[country.alpha2] = country.name
self.from_name[country.name] = country.alpha2

@property
def codes(self):
return frozenset(self.from_name.keys())

def convert(self, alpha2):
if alpha2 not in self.to_name:
raise CountryConvertError(alpha2)
Expand Down
Binary file added lib/babelfish/converters/countryname.pyo
Binary file not shown.
6 changes: 3 additions & 3 deletions lib/babelfish/converters/name.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014 the BabelFish authors. All rights reserved.
# Copyright (c) 2013 the BabelFish authors. All rights reserved.
# Use of this source code is governed by the 3-clause BSD license
# that can be found in the LICENSE file.
#
from __future__ import unicode_literals
from . import LanguageEquivalenceConverter
from ..iso import get_languages_data
from ..language import LANGUAGE_MATRIX


class NameConverter(LanguageEquivalenceConverter):
CASE_SENSITIVE = False
SYMBOLS = {}
for iso_language in get_languages_data():
for iso_language in LANGUAGE_MATRIX:
if iso_language.name:
SYMBOLS[iso_language.alpha3] = iso_language.name
Binary file added lib/babelfish/converters/name.pyo
Binary file not shown.
7 changes: 2 additions & 5 deletions lib/babelfish/converters/opensubtitles.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014 the BabelFish authors. All rights reserved.
# Copyright (c) 2013 the BabelFish authors. All rights reserved.
# Use of this source code is governed by the 3-clause BSD license
# that can be found in the LICENSE file.
#
Expand All @@ -17,10 +17,7 @@ def __init__(self):
self.to_opensubtitles = {('por', 'BR'): 'pob', ('gre', None): 'ell', ('srp', None): 'scc', ('srp', 'ME'): 'mne'}
self.from_opensubtitles = CaseInsensitiveDict({'pob': ('por', 'BR'), 'pb': ('por', 'BR'), 'ell': ('ell', None),
'scc': ('srp', None), 'mne': ('srp', 'ME')})

@property
def codes(self):
return (self.alpha2_converter.codes | self.alpha3b_converter.codes | frozenset(['pob', 'pb', 'scc', 'mne']))
self.codes = (self.alpha2_converter.codes | self.alpha3b_converter.codes | set(['pob', 'pb', 'scc', 'mne']))

def convert(self, alpha3, country=None, script=None):
alpha3b = self.alpha3b_converter.convert(alpha3, country, script)
Expand Down
Binary file added lib/babelfish/converters/opensubtitles.pyo
Binary file not shown.
11 changes: 4 additions & 7 deletions lib/babelfish/converters/scope.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014 the BabelFish authors. All rights reserved.
# Copyright (c) 2013 the BabelFish authors. All rights reserved.
# Use of this source code is governed by the 3-clause BSD license
# that can be found in the LICENSE file.
#
from __future__ import unicode_literals
from . import LanguageConverter
from ..exceptions import LanguageConvertError
from ..iso import get_languages_data
from ..language import LANGUAGE_MATRIX


class ScopeConverter(LanguageConverter):
FULLNAME = {'I': 'individual', 'M': 'macrolanguage', 'S': 'special'}
SYMBOLS = {}
for iso_language in get_languages_data():
for iso_language in LANGUAGE_MATRIX:
SYMBOLS[iso_language.alpha3] = iso_language.scope

@property
def codes(self):
return frozenset(self.SYMBOLS.values())
codes = set(SYMBOLS.values())

def convert(self, alpha3, country=None, script=None):
if self.SYMBOLS[alpha3] in self.FULLNAME:
Expand Down
11 changes: 4 additions & 7 deletions lib/babelfish/converters/type.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014 the BabelFish authors. All rights reserved.
# Copyright (c) 2013 the BabelFish authors. All rights reserved.
# Use of this source code is governed by the 3-clause BSD license
# that can be found in the LICENSE file.
#
from __future__ import unicode_literals
from . import LanguageConverter
from ..exceptions import LanguageConvertError
from ..iso import get_languages_data
from ..language import LANGUAGE_MATRIX


class LanguageTypeConverter(LanguageConverter):
FULLNAME = {'A': 'ancient', 'C': 'constructed', 'E': 'extinct', 'H': 'historical', 'L': 'living', 'S': 'special'}
SYMBOLS = {}
for iso_language in get_languages_data():
for iso_language in LANGUAGE_MATRIX:
SYMBOLS[iso_language.alpha3] = iso_language.type

@property
def codes(self):
return frozenset(self.SYMBOLS.values())
codes = set(SYMBOLS.values())

def convert(self, alpha3, country=None, script=None):
if self.SYMBOLS[alpha3] in self.FULLNAME:
Expand Down
38 changes: 30 additions & 8 deletions lib/babelfish/country.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,27 @@
# Use of this source code is governed by the 3-clause BSD license
# that can be found in the LICENSE file.
#


from __future__ import unicode_literals
from collections import namedtuple
from functools import partial
from pkg_resources import resource_stream # @UnresolvedImport
from .converters import ConverterManager
from .iso import get_countries_data
from . import basestr


COUNTRIES = {}
COUNTRY_MATRIX = []

#: The namedtuple used in the :data:`COUNTRY_MATRIX`
IsoCountry = namedtuple('IsoCountry', ['name', 'alpha2'])

COUNTRIES = frozenset(country.alpha2 for country in get_countries_data())
f = resource_stream('babelfish', 'data/iso-3166-1.txt')
f.readline()
for l in f:
iso_country = IsoCountry(*l.decode('utf-8').strip().split(';'))
COUNTRIES[iso_country.alpha2] = iso_country.name
COUNTRY_MATRIX.append(iso_country)
f.close()


class CountryConverterManager(ConverterManager):
Expand All @@ -27,10 +41,10 @@ class CountryMeta(type):
Dynamically redirect :meth:`Country.frommycode` to :meth:`Country.fromcode` with the ``mycode`` `converter`
"""
def __getattr__(self, name):
def __getattr__(cls, name):
if name.startswith('from'):
return partial(self.fromcode, converter=name[4:])
return getattr(self, name)
return partial(cls.fromcode, converter=name[4:])
return type.__getattribute__(cls, name)


class Country(CountryMeta(str('CountryBase'), (object,), {})):
Expand Down Expand Up @@ -61,14 +75,22 @@ def fromcode(cls, code, converter):
"""
return cls(country_converters[converter].reverse(code))

def __getstate__(self):
return self.alpha2

def __setstate__(self, state):
self.alpha2 = state

def __getattr__(self, name):
return country_converters[name].convert(self.alpha2)

def __hash__(self):
return hash(self.alpha2)

def __eq__(self, other):
if other is None:
if isinstance(other, basestr):
return str(self) == other
if not isinstance(other, Country):
return False
return self.alpha2 == other.alpha2

Expand Down
Binary file added lib/babelfish/country.pyo
Binary file not shown.
Loading

0 comments on commit edb3484

Please sign in to comment.