Compare commits

..

17 Commits

Author SHA1 Message Date
Antoine Bertin a6abc268a5 Release 0.7.4 2014-01-27 22:21:49 +01:00
Antoine Bertin 2dea4fef44 Update requirements
Exclude newest releases of guessit and babelfish
2014-01-27 22:20:21 +01:00
Antoine Bertin fe76634d02 Release 0.7.3 2013-11-22 21:05:49 +01:00
Antoine Bertin b499540bed Sync README and documentation 2013-11-22 20:47:56 +01:00
Antoine Bertin 7b4a9c2060 Fix wrong error catched for babelfish 0.4.0 2013-11-21 23:52:06 +01:00
Antoine Bertin a84cc80a88 Ignore IDE error in cli 2013-11-21 23:51:25 +01:00
Antoine Bertin 241cea9729 Fix podnapisi tests 2013-11-21 23:31:43 +01:00
Antoine Bertin 4b83ddc63e Improve assertions in tests 2013-11-21 23:31:02 +01:00
Antoine Bertin 0b431fbb8d Add Podnapisi to the list of providers in documentation 2013-11-21 00:38:01 +01:00
Antoine Bertin 3736d921a1 Update dogpile.cache to 0.5.2 and use a MutexLock in cli 2013-11-21 00:12:53 +01:00
Antoine Bertin 380fb28d2e Update to babelfish 0.4.0 2013-11-20 22:40:06 +01:00
Antoine Bertin 64c0ee4ccf Add setuptools to dev-requirements.txt 2013-11-20 22:38:55 +01:00
Antoine Bertin 5977bf69fb Improve embedded subtitles language detection 2013-11-14 22:08:48 +01:00
CelestianX 179ae6a24e Updated README with proper information
Section relative to the library was invalid. Missing references and
arguments.
2013-11-14 21:55:24 +01:00
Antoine Bertin 16942ec4c7 Switch to 0.7.3 2013-11-14 21:53:36 +01:00
Antoine Bertin 6f5378ea40 Be more permissive in subtitle validation 2013-11-14 21:51:39 +01:00
Antoine Bertin 02ee2039f4 Skip empty language in addic7ed 2013-11-14 21:51:04 +01:00
23 changed files with 218 additions and 152 deletions
+17
View File
@@ -1,6 +1,23 @@
Changelog
=========
0.7.4
-----
**release date:** 2014-01-27
* Fix requirements for guessit and babelfish
0.7.3
-----
**release date:** 2013-11-22
* Fix windows compatibility
* Improve subtitle validation
* Improve embedded subtitle languages detection
* Improve unittests
0.7.2
-----
**release date:** 2013-11-10
+2 -1
View File
@@ -19,6 +19,7 @@ best matching subtitles. Providers are extensible through a dedicated entry poin
* Addic7ed
* BierDopje
* OpenSubtitles
* Podnapisi
* TheSubDB
* TvSubtitles
@@ -45,7 +46,7 @@ skipping videos that already have subtitles whether they are embedded or not::
subliminal.cache_region.configure('dogpile.cache.dbm', arguments={'filename': '/path/to/cachefile.dbm'})
# scan for videos in the folder and their subtitles
videos = scan_videos(['/path/to/video/folder'], subtitles=True, embedded_subtitles=True)
videos = subliminal.scan_videos(['/path/to/video/folder'], subtitles=True, embedded_subtitles=True, age=timedelta(weeks=1))
# download
subliminal.download_best_subtitles(videos, {Language('eng'), Language('fra')}, age=timedelta(week=1))
+1
View File
@@ -2,3 +2,4 @@ sympy>=0.7.3
sphinx>=1.1.3
sphinxcontrib-programoutput>=0.8
Sphinx-PyPI-upload>=0.2.1
setuptools>=1.4
+2 -1
View File
@@ -19,6 +19,7 @@ best matching subtitles. Providers are extensible through a dedicated entry poin
* Addic7ed
* BierDopje
* OpenSubtitles
* Podnapisi
* TheSubDB
* TvSubtitles
@@ -47,7 +48,7 @@ skipping videos that already have subtitles whether they are embedded or not::
subliminal.cache_region.configure('dogpile.cache.dbm', arguments={'filename': '/path/to/cachefile.dbm'})
# scan for videos in the folder and their subtitles
videos = scan_videos(['/path/to/video/folder'], subtitles=True, embedded_subtitles=True)
videos = subliminal.scan_videos(['/path/to/video/folder'], subtitles=True, embedded_subtitles=True, age=timedelta(weeks=1))
# download
subliminal.download_best_subtitles(videos, {Language('eng'), Language('fra')}, age=timedelta(week=1))
+3 -3
View File
@@ -1,9 +1,9 @@
beautifulsoup4>=4.3.2
guessit>=0.6.2
guessit>=0.6.2,<0.7
requests>=2.0.1
enzyme>=0.4.0
html5lib>=0.99
dogpile.cache>=0.5.1
babelfish>=0.3.0
dogpile.cache>=0.5.2
babelfish>=0.4.0,<0.5
charade>=1.0.3
pysrt>=0.5.0
+4 -4
View File
@@ -4,7 +4,7 @@ from setuptools import setup, find_packages
setup(name='subliminal',
version='0.7.2',
version='0.7.4',
license='MIT',
description='Subtitles, faster than your thoughts',
long_description=open('README.rst').read() + '\n\n' + open('HISTORY.rst').read(),
@@ -32,9 +32,9 @@ setup(name='subliminal',
'podnapisi = subliminal.providers.podnapisi:PodnapisiProvider',
'thesubdb = subliminal.providers.thesubdb:TheSubDBProvider',
'tvsubtitles = subliminal.providers.tvsubtitles:TVsubtitlesProvider'],
'babelfish.converters': ['addic7ed = subliminal.converters.addic7ed:Addic7edConverter',
'podnapisi = subliminal.converters.podnapisi:PodnapisiConverter',
'tvsubtitles = subliminal.converters.tvsubtitles:TVsubtitlesConverter']
'babelfish.language_converters': ['addic7ed = subliminal.converters.addic7ed:Addic7edConverter',
'podnapisi = subliminal.converters.podnapisi:PodnapisiConverter',
'tvsubtitles = subliminal.converters.tvsubtitles:TVsubtitlesConverter']
},
install_requires=open('requirements.txt').readlines(),
test_suite='subliminal.tests.suite')
+2 -2
View File
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
__title__ = 'subliminal'
__version__ = '0.7.2'
__version__ = '0.7.4'
__author__ = 'Antoine Bertin'
__license__ = 'MIT'
__copyright__ = 'Copyright 2013 Antoine Bertin'
import logging
from .api import PROVIDERS_ENTRY_POINT, list_subtitles, download_subtitles, download_best_subtitles
from .cache import region as cache_region
from .cache import MutexLock, region as cache_region
from .exceptions import Error, ProviderError, ProviderConfigurationError, ProviderNotAvailable, InvalidSubtitle
from .subtitle import Subtitle
from .video import VIDEO_EXTENSIONS, SUBTITLE_EXTENSIONS, Video, Episode, Movie, scan_videos, scan_video
+30 -4
View File
@@ -1,13 +1,16 @@
# -*- coding: utf-8 -*-
import inspect
import dogpile.cache
from dogpile.cache import make_region # @UnresolvedImport
from dogpile.cache.backends.file import AbstractFileLock # @UnresolvedImport
from dogpile.cache.compat import string_type # @UnresolvedImport
from dogpile.core.readwrite_lock import ReadWriteMutex # @UnresolvedImport
#: Subliminal's cache version
CACHE_VERSION = 1
def subliminal_key_generator(namespace, fn, to_str=dogpile.cache.compat.string_type):
def subliminal_key_generator(namespace, fn, to_str=string_type):
"""Add a :data:`CACHE_VERSION` to dogpile.cache's default function_key_generator"""
if namespace is None:
namespace = '%d:%s:%s' % (CACHE_VERSION, fn.__module__, fn.__name__)
@@ -26,5 +29,28 @@ def subliminal_key_generator(namespace, fn, to_str=dogpile.cache.compat.string_t
return generate_key
#: The dogpile.cache region
region = dogpile.cache.make_region(function_key_generator=subliminal_key_generator)
class MutexLock(AbstractFileLock):
""":class:`MutexLock` is a thread-based rw lock based on :class:`dogpile.core.ReadWriteMutex`"""
def __init__(self, filename):
self.mutex = ReadWriteMutex()
def acquire_read_lock(self, wait):
ret = self.mutex.acquire_read_lock(wait)
return wait or ret
def acquire_write_lock(self, wait):
ret = self.mutex.acquire_write_lock(wait)
return wait or ret
def release_read_lock(self):
return self.mutex.release_read_lock()
def release_write_lock(self):
return self.mutex.release_write_lock()
#: The dogpile.cache region (long-lived)
region = make_region(function_key_generator=subliminal_key_generator)
#: The dogpile.cache region for :meth:`~subliminal.providers.Provider.query` (short-lived)
query_region = make_region(function_key_generator=subliminal_key_generator)
+3 -3
View File
@@ -9,7 +9,7 @@ import sys
import babelfish
import guessit
import pkg_resources
from subliminal import (__version__, PROVIDERS_ENTRY_POINT, cache_region, Video, Episode, Movie, scan_videos,
from subliminal import (__version__, PROVIDERS_ENTRY_POINT, cache_region, MutexLock, Video, Episode, Movie, scan_videos,
download_best_subtitles)
try:
import colorlog
@@ -138,8 +138,8 @@ def subliminal():
logging.getLogger('subliminal.api').setLevel(logging.INFO)
# configure cache
cache_region.configure('dogpile.cache.dbm', expiration_time=datetime.timedelta(days=30),
arguments={'filename': args.cache_file})
cache_region.configure('dogpile.cache.dbm', expiration_time=datetime.timedelta(days=30), # @UndefinedVariable
arguments={'filename': args.cache_file, 'lock_factory': MutexLock})
# scan videos
videos = scan_videos([p for p in args.paths if os.path.exists(p)], subtitles=not args.force,
+6 -6
View File
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from babelfish.converters.name import NameConverter
from babelfish import LanguageReverseConverter, get_language_converter
class Addic7edConverter(NameConverter):
class Addic7edConverter(LanguageReverseConverter):
def __init__(self):
super(Addic7edConverter, self).__init__()
self.name_converter = get_language_converter('name')
self.from_addic7ed = {'Català': ('cat',), 'Chinese (Simplified)': ('zho',), 'Chinese (Traditional)': ('zho',),
'Euskera': ('eus',), 'Galego': ('glg',), 'Greek': ('ell',), 'Malay': ('msa',),
'Portuguese (Brazilian)': ('por', 'BR'), 'Serbian (Cyrillic)': ('srp', None, 'Cyrl'),
@@ -14,7 +14,7 @@ class Addic7edConverter(NameConverter):
self.to_addic7ed = {('cat',): 'Català', ('zho',): 'Chinese (Simplified)', ('eus',): 'Euskera',
('glg',): 'Galego', ('ell',): 'Greek', ('msa',): 'Malay',
('por', 'BR'): 'Portuguese (Brazilian)', ('srp', None, 'Cyrl'): 'Serbian (Cyrillic)'}
self.codes |= set(self.from_addic7ed.keys())
self.codes = self.name_converter.codes | set(self.from_addic7ed.keys())
def convert(self, alpha3, country=None, script=None):
if (alpha3, country, script) in self.to_addic7ed:
@@ -23,9 +23,9 @@ class Addic7edConverter(NameConverter):
return self.to_addic7ed[(alpha3, country)]
if (alpha3,) in self.to_addic7ed:
return self.to_addic7ed[(alpha3,)]
return super(Addic7edConverter, self).convert(alpha3, country, script)
return self.name_converter.convert(alpha3, country, script)
def reverse(self, addic7ed):
if addic7ed in self.from_addic7ed:
return self.from_addic7ed[addic7ed]
return super(Addic7edConverter, self).reverse(addic7ed)
return self.name_converter.reverse(addic7ed)
+4 -5
View File
@@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from babelfish import ReverseConverter, ConvertError, ReverseError
from babelfish import LanguageReverseConverter, LanguageConvertError, LanguageReverseError
class PodnapisiConverter(ReverseConverter):
class PodnapisiConverter(LanguageReverseConverter):
def __init__(self):
super(PodnapisiConverter, self).__init__()
self.from_podnapisi = {2: ('eng',), 28: ('spa',), 26: ('pol',), 36: ('srp',), 1: ('slv',), 38: ('hrv',),
9: ('ita',), 8: ('fra',), 48: ('por', 'BR'), 23: ('nld',), 12: ('ara',), 13: ('ron',),
33: ('bul',), 32: ('por',), 16: ('ell',), 15: ('hun',), 31: ('fin',), 30: ('tur',),
@@ -25,9 +24,9 @@ class PodnapisiConverter(ReverseConverter):
return self.to_podnapisi[(alpha3, country)]
if (alpha3, country, script) in self.to_podnapisi:
return self.to_podnapisi[(alpha3, country, script)]
raise ConvertError(alpha3, country, script)
raise LanguageConvertError(alpha3, country, script)
def reverse(self, podnapisi):
if podnapisi not in self.from_podnapisi:
raise ReverseError(podnapisi)
raise LanguageReverseError(podnapisi)
return self.from_podnapisi[podnapisi]
+6 -6
View File
@@ -1,24 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from babelfish.converters.alpha2 import Alpha2Converter
from babelfish import LanguageReverseConverter, get_language_converter
class TVsubtitlesConverter(Alpha2Converter):
class TVsubtitlesConverter(LanguageReverseConverter):
def __init__(self):
super(TVsubtitlesConverter, self).__init__()
self.alpha2_converter = get_language_converter('alpha2')
self.from_tvsubtitles = {'br': ('por', 'BR'), 'ua': ('ukr',), 'gr': ('ell',), 'cn': ('zho',), 'jp': ('jpn',),
'cz': ('ces',)}
self.to_tvsubtitles = {v: k for k, v in self.from_tvsubtitles}
self.codes |= set(self.from_tvsubtitles.keys())
self.codes = self.alpha2_converter.codes | set(self.from_tvsubtitles.keys())
def convert(self, alpha3, country=None, script=None):
if (alpha3, country) in self.to_tvsubtitles:
return self.to_tvsubtitles[(alpha3, country)]
if (alpha3,) in self.to_tvsubtitles:
return self.to_tvsubtitles[(alpha3,)]
return super(TVsubtitlesConverter, self).convert(alpha3, country, script)
return self.alpha2_converter.convert(alpha3, country, script)
def reverse(self, tvsubtitles):
if tvsubtitles in self.from_tvsubtitles:
return self.from_tvsubtitles[tvsubtitles]
return super(TVsubtitlesConverter, self).reverse(tvsubtitles)
return self.alpha2_converter.reverse(tvsubtitles)
+3
View File
@@ -166,6 +166,9 @@ class Addic7edProvider(Provider):
if cells[5].string != 'Completed':
logger.debug('Skipping incomplete subtitle')
continue
if not cells[3].string:
logger.debug('Skipping empty language')
continue
subtitles.append(Addic7edSubtitle(babelfish.Language.fromaddic7ed(cells[3].string), series, season,
int(cells[1].string), cells[2].string, cells[4].string,
bool(cells[6].string), cells[9].a['href'], link))
+4 -4
View File
@@ -23,8 +23,8 @@ class OpenSubtitlesSubtitle(Subtitle):
provider_name = 'opensubtitles'
series_re = re.compile('^"(?P<series_name>.*)" (?P<series_title>.*)$')
def __init__(self, language, hearing_impaired, id, matched_by, movie_kind, hash, movie_name, movie_release_name, movie_year,
movie_imdb_id, series_season, series_episode):
def __init__(self, language, hearing_impaired, id, matched_by, movie_kind, hash, movie_name, movie_release_name, # @ReservedAssignment
movie_year, movie_imdb_id, series_season, series_episode):
super(OpenSubtitlesSubtitle, self).__init__(language, hearing_impaired)
self.id = id
self.matched_by = matched_by
@@ -83,7 +83,7 @@ class OpenSubtitlesSubtitle(Subtitle):
class OpenSubtitlesProvider(Provider):
languages = {babelfish.Language.fromopensubtitles(l) for l in babelfish.CONVERTERS['opensubtitles'].codes}
languages = {babelfish.Language.fromopensubtitles(l) for l in babelfish.get_language_converter('opensubtitles').codes}
def __init__(self):
self.server = xmlrpclib.ServerProxy('http://api.opensubtitles.org/xml-rpc')
@@ -106,7 +106,7 @@ class OpenSubtitlesProvider(Provider):
if response['status'] != '200 OK':
raise ProviderError('Logout failed with status %r' % response['status'])
def query(self, languages, hash=None, size=None, imdb_id=None, query=None):
def query(self, languages, hash=None, size=None, imdb_id=None, query=None): # @ReservedAssignment
searches = []
if hash and size:
searches.append({'moviehash': hash, 'moviebytesize': str(size)})
+2 -2
View File
@@ -23,7 +23,7 @@ logger = logging.getLogger(__name__)
class PodnapisiSubtitle(Subtitle):
provider_name = 'podnapisi'
def __init__(self, language, id, releases, hearing_impaired, link, series=None, season=None, episode=None,
def __init__(self, language, id, releases, hearing_impaired, link, series=None, season=None, episode=None, # @ReservedAssignment
title=None, year=None):
super(PodnapisiSubtitle, self).__init__(language, hearing_impaired)
self.id = id
@@ -67,7 +67,7 @@ class PodnapisiSubtitle(Subtitle):
class PodnapisiProvider(Provider):
languages = {babelfish.Language.frompodnapisi(l) for l in babelfish.CONVERTERS['podnapisi'].codes}
languages = {babelfish.Language.frompodnapisi(l) for l in babelfish.get_language_converter('podnapisi').codes}
video_types = (Episode, Movie)
server = 'http://simple.podnapisi.net'
link_re = re.compile('^.*(?P<link>/ppodnapisi/download/i/\d+/k/.*$)')
+2 -2
View File
@@ -16,7 +16,7 @@ logger = logging.getLogger(__name__)
class TheSubDBSubtitle(Subtitle):
provider_name = 'thesubdb'
def __init__(self, language, hash):
def __init__(self, language, hash): # @ReservedAssignment
super(TheSubDBSubtitle, self).__init__(language)
self.hash = hash
@@ -55,7 +55,7 @@ class TheSubDBProvider(Provider):
raise ProviderNotAvailable('Timeout after 10 seconds')
return r
def query(self, hash):
def query(self, hash): # @ReservedAssignment
params = {'action': 'search', 'hash': hash}
logger.debug('Searching subtitles %r', params)
r = self.get(params)
+1 -1
View File
@@ -22,7 +22,7 @@ logger = logging.getLogger(__name__)
class TVsubtitlesSubtitle(Subtitle):
provider_name = 'tvsubtitles'
def __init__(self, language, series, season, episode, id, rip, release):
def __init__(self, language, series, season, episode, id, rip, release): # @ReservedAssignment
super(TVsubtitlesSubtitle, self).__init__(language)
self.series = series
self.season = season
+1 -1
View File
@@ -6,7 +6,7 @@ from sympy import Eq, symbols, solve
# Symbols
release_group, resolution, video_codec, audio_codec = symbols('release_group resolution video_codec audio_codec')
imdb_id, hash, title, series, tvdb_id, season, episode = symbols('imdb_id hash title series tvdb_id season episode')
imdb_id, hash, title, series, tvdb_id, season, episode = symbols('imdb_id hash title series tvdb_id season episode') # @ReservedAssignment
year = symbols('year')
+4 -3
View File
@@ -90,7 +90,7 @@ def get_subtitle_path(video_path, language=None):
if language is not None:
try:
return subtitle_path + '.%s.%s' % (language.alpha2, 'srt')
except babelfish.ConvertError:
except babelfish.LanguageConvertError:
return subtitle_path + '.%s.%s' % (language.alpha3, 'srt')
return subtitle_path + '.srt'
@@ -105,8 +105,9 @@ def is_valid_subtitle(subtitle_text):
try:
pysrt.from_string(subtitle_text, error_handling=pysrt.ERROR_RAISE)
return True
except pysrt.Error:
pass
except pysrt.Error as e:
if e.args[0] > 80:
return True
except:
logger.exception('Unexpected error when validating subtitle')
return False
+1 -1
View File
@@ -6,7 +6,7 @@ from subliminal import cache_region
from . import test_providers, test_subliminal
cache_region.configure('dogpile.cache.memory', expiration_time=60 * 30)
cache_region.configure('dogpile.cache.memory', expiration_time=60 * 30) # @UndefinedVariable
suite = TestSuite([test_providers.suite(), test_subliminal.suite()])
+65 -60
View File
@@ -25,17 +25,18 @@ class Addic7edProviderTestCase(ProviderTestCase):
def test_find_show_id(self):
with self.Provider() as provider:
show_id = provider.find_show_id('The Big Bang')
self.assertTrue(show_id == 126)
self.assertEqual(show_id, 126)
def test_find_show_id_error(self):
with self.Provider() as provider:
show_id = provider.find_show_id('the big how i met your mother')
self.assertTrue(show_id is None)
self.assertIsNone(show_id)
def test_get_show_ids(self):
with self.Provider() as provider:
show_ids = provider.get_show_ids()
self.assertTrue('the big bang theory' in show_ids and show_ids['the big bang theory'] == 126)
self.assertIn('the big bang theory', show_ids)
self.assertEqual(show_ids['the big bang theory'], 126)
def test_query_episode_0(self):
video = EPISODES[0]
@@ -50,8 +51,8 @@ class Addic7edProviderTestCase(ProviderTestCase):
frozenset(['series', 'season'])}
with self.Provider() as provider:
subtitles = provider.query(video.series, video.season)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_query_episode_1(self):
video = EPISODES[1]
@@ -68,8 +69,8 @@ class Addic7edProviderTestCase(ProviderTestCase):
frozenset(['series', 'season'])}
with self.Provider() as provider:
subtitles = provider.query(video.series, video.season)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_list_subtitles(self):
video = EPISODES[0]
@@ -78,8 +79,8 @@ class Addic7edProviderTestCase(ProviderTestCase):
frozenset(['series', 'episode', 'season', 'title'])}
with self.Provider() as provider:
subtitles = provider.list_subtitles(video, languages)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_download_subtitle(self):
video = EPISODES[0]
@@ -96,12 +97,12 @@ class BierDopjeProviderTestCase(ProviderTestCase):
def test_find_show_id(self):
with self.Provider() as provider:
show_id = provider.find_show_id('The Big Bang')
self.assertTrue(show_id == 9203)
self.assertEqual(show_id, 9203)
def test_find_show_id_error(self):
with self.Provider() as provider:
show_id = provider.find_show_id('the big how i met your mother')
self.assertTrue(show_id is None)
self.assertIsNone(show_id)
def test_query_episode_0(self):
video = EPISODES[0]
@@ -111,8 +112,8 @@ class BierDopjeProviderTestCase(ProviderTestCase):
frozenset(['episode', 'video_codec', 'season', 'series', 'resolution', 'release_group'])}
with self.Provider() as provider:
subtitles = provider.query(language, video.season, video.episode, series=video.series)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == {language})
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, {language})
def test_query_episode_1(self):
video = EPISODES[1]
@@ -124,8 +125,8 @@ class BierDopjeProviderTestCase(ProviderTestCase):
frozenset(['episode', 'video_codec', 'season', 'series', 'resolution', 'release_group'])}
with self.Provider() as provider:
subtitles = provider.query(language, video.season, video.episode, series=video.series)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == {language})
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, {language})
def test_query_episode_0_tvdb_id(self):
video = EPISODES[0]
@@ -135,8 +136,8 @@ class BierDopjeProviderTestCase(ProviderTestCase):
frozenset(['episode', 'series', 'video_codec', 'tvdb_id', 'resolution', 'season'])}
with self.Provider() as provider:
subtitles = provider.query(language, video.season, video.episode, tvdb_id=video.tvdb_id)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == {language})
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, {language})
def test_list_subtitles(self):
video = EPISODES[1]
@@ -148,8 +149,8 @@ class BierDopjeProviderTestCase(ProviderTestCase):
frozenset(['episode', 'video_codec', 'season', 'series', 'tvdb_id', 'release_group'])}
with self.Provider() as provider:
subtitles = provider.list_subtitles(video, languages)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_download_subtitle(self):
video = EPISODES[0]
@@ -173,8 +174,8 @@ class OpenSubtitlesProviderTestCase(ProviderTestCase):
frozenset(['imdb_id', 'title', 'year', 'video_codec', 'resolution', 'release_group'])}
with self.Provider() as provider:
subtitles = provider.query(languages, query=video.title)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_query_episode_0_query(self):
video = EPISODES[0]
@@ -184,8 +185,8 @@ class OpenSubtitlesProviderTestCase(ProviderTestCase):
frozenset(['episode', 'title', 'series', 'imdb_id', 'video_codec', 'season'])}
with self.Provider() as provider:
subtitles = provider.query(languages, query=video.name.split(os.sep)[-1])
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_query_episode_1_query(self):
video = EPISODES[1]
@@ -198,8 +199,8 @@ class OpenSubtitlesProviderTestCase(ProviderTestCase):
frozenset(['series', 'episode', 'season', 'imdb_id'])}
with self.Provider() as provider:
subtitles = provider.query(languages, query=video.name.split(os.sep)[-1])
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_query_movie_0_imdb_id(self):
video = MOVIES[0]
@@ -211,8 +212,8 @@ class OpenSubtitlesProviderTestCase(ProviderTestCase):
frozenset(['imdb_id', 'resolution', 'title', 'year'])}
with self.Provider() as provider:
subtitles = provider.query(languages, imdb_id=video.imdb_id)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_query_episode_0_imdb_id(self):
video = EPISODES[0]
@@ -223,8 +224,8 @@ class OpenSubtitlesProviderTestCase(ProviderTestCase):
frozenset(['episode', 'title', 'series', 'imdb_id', 'video_codec', 'season'])}
with self.Provider() as provider:
subtitles = provider.query(languages, imdb_id=video.imdb_id)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_query_movie_0_hash(self):
video = MOVIES[0]
@@ -232,12 +233,13 @@ class OpenSubtitlesProviderTestCase(ProviderTestCase):
matches = {frozenset(['hash', 'title', 'video_codec', 'year', 'resolution', 'imdb_id']),
frozenset(['hash', 'title', 'video_codec', 'year', 'resolution', 'release_group', 'imdb_id']),
frozenset(['year', 'video_codec', 'imdb_id', 'hash', 'title']),
frozenset([]),
frozenset(['year', 'resolution', 'imdb_id', 'hash', 'title']),
frozenset(['year', 'imdb_id', 'hash', 'title'])}
with self.Provider() as provider:
subtitles = provider.query(languages, hash=video.hashes['opensubtitles'], size=video.size)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_query_episode_0_hash(self):
video = EPISODES[0]
@@ -248,8 +250,8 @@ class OpenSubtitlesProviderTestCase(ProviderTestCase):
frozenset(['series', 'resolution', 'hash', 'video_codec'])}
with self.Provider() as provider:
subtitles = provider.query(languages, hash=video.hashes['opensubtitles'], size=video.size)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_list_subtitles(self):
video = MOVIES[0]
@@ -259,6 +261,7 @@ class OpenSubtitlesProviderTestCase(ProviderTestCase):
frozenset(['year', 'video_codec', 'imdb_id', 'resolution', 'title']),
frozenset(['hash', 'title', 'video_codec', 'year', 'resolution', 'release_group', 'imdb_id']),
frozenset(['year', 'video_codec', 'imdb_id', 'hash', 'title']),
frozenset([]),
frozenset(['year', 'resolution', 'imdb_id', 'hash', 'title']),
frozenset(['hash', 'title', 'video_codec', 'year', 'resolution', 'imdb_id']),
frozenset(['year', 'imdb_id', 'hash', 'title']),
@@ -266,8 +269,8 @@ class OpenSubtitlesProviderTestCase(ProviderTestCase):
frozenset(['year', 'imdb_id', 'resolution', 'title'])}
with self.Provider() as provider:
subtitles = provider.list_subtitles(video, languages)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_download_subtitle(self):
video = MOVIES[0]
@@ -288,11 +291,12 @@ class PodnapisiProviderTestCase(ProviderTestCase):
frozenset(['title', 'resolution', 'year']),
frozenset(['video_codec', 'title', 'year']),
frozenset(['title', 'year']),
frozenset(['video_codec', 'title', 'resolution', 'release_group', 'year'])}
frozenset(['video_codec', 'title', 'resolution', 'release_group', 'year']),
frozenset(['video_codec', 'title', 'resolution', 'audio_codec', 'year'])}
with self.Provider() as provider:
subtitles = provider.query(language, title=video.title, year=video.year)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == {language})
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, {language})
def test_query_episode_0(self):
video = EPISODES[0]
@@ -301,8 +305,8 @@ class PodnapisiProviderTestCase(ProviderTestCase):
frozenset(['season', 'video_codec', 'episode', 'resolution', 'series'])}
with self.Provider() as provider:
subtitles = provider.query(language, series=video.series, season=video.season, episode=video.episode)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == {language})
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, {language})
def test_list_subtitles(self):
video = MOVIES[0]
@@ -311,11 +315,12 @@ class PodnapisiProviderTestCase(ProviderTestCase):
frozenset(['title', 'resolution', 'year']),
frozenset(['video_codec', 'title', 'year']),
frozenset(['title', 'year']),
frozenset(['video_codec', 'title', 'resolution', 'release_group', 'year'])}
frozenset(['video_codec', 'title', 'resolution', 'release_group', 'year']),
frozenset(['video_codec', 'title', 'resolution', 'audio_codec', 'year'])}
with self.Provider() as provider:
subtitles = provider.list_subtitles(video, languages)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_download_subtitle(self):
video = MOVIES[0]
@@ -335,8 +340,8 @@ class TheSubDBProviderTestCase(ProviderTestCase):
matches = {frozenset(['hash'])}
with self.Provider() as provider:
subtitles = provider.query(video.hashes['thesubdb'])
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_query_episode_1(self):
video = EPISODES[1]
@@ -344,8 +349,8 @@ class TheSubDBProviderTestCase(ProviderTestCase):
matches = {frozenset(['hash'])}
with self.Provider() as provider:
subtitles = provider.query(video.hashes['thesubdb'])
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_list_subtitles(self):
video = MOVIES[0]
@@ -353,8 +358,8 @@ class TheSubDBProviderTestCase(ProviderTestCase):
matches = {frozenset(['hash'])}
with self.Provider() as provider:
subtitles = provider.list_subtitles(video, languages)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_download_subtitle(self):
video = MOVIES[0]
@@ -371,27 +376,27 @@ class TVsubtitlesProviderTestCase(ProviderTestCase):
def test_find_show_id(self):
with self.Provider() as provider:
show_id = provider.find_show_id('The Big Bang')
self.assertTrue(show_id == 154)
self.assertEqual(show_id, 154)
def test_find_show_id_ambiguous(self):
with self.Provider() as provider:
show_id = provider.find_show_id('New Girl')
self.assertTrue(show_id == 977)
self.assertEqual(show_id, 977)
def test_find_show_id_no_dots(self):
with self.Provider() as provider:
show_id = provider.find_show_id('Marvel\'s Agents of S H I E L D')
self.assertTrue(show_id == 1340)
self.assertEqual(show_id, 1340)
def test_find_show_id_error(self):
with self.Provider() as provider:
show_id = provider.find_show_id('the big gaming')
self.assertTrue(show_id is None)
self.assertIsNone(show_id)
def test_find_episode_ids(self):
with self.Provider() as provider:
episode_ids = provider.find_episode_ids(154, 5)
self.assertTrue(set(episode_ids.keys()) == set(range(1, 25)))
self.assertEqual(set(episode_ids.keys()), set(range(1, 25)))
def test_query_episode_0(self):
video = EPISODES[0]
@@ -400,8 +405,8 @@ class TVsubtitlesProviderTestCase(ProviderTestCase):
frozenset(['series', 'episode', 'season'])}
with self.Provider() as provider:
subtitles = provider.query(video.series, video.season, video.episode)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_query_episode_1(self):
video = EPISODES[1]
@@ -412,8 +417,8 @@ class TVsubtitlesProviderTestCase(ProviderTestCase):
frozenset(['series', 'episode', 'season'])}
with self.Provider() as provider:
subtitles = provider.query(video.series, video.season, video.episode)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_list_subtitles(self):
video = EPISODES[0]
@@ -421,8 +426,8 @@ class TVsubtitlesProviderTestCase(ProviderTestCase):
matches = {frozenset(['series', 'episode', 'season'])}
with self.Provider() as provider:
subtitles = provider.list_subtitles(video, languages)
self.assertTrue({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles} == matches)
self.assertTrue({subtitle.language for subtitle in subtitles} == languages)
self.assertEqual({frozenset(subtitle.compute_matches(video)) for subtitle in subtitles}, matches)
self.assertEqual({subtitle.language for subtitle in subtitles}, languages)
def test_download_subtitle(self):
video = EPISODES[0]
+40 -38
View File
@@ -23,22 +23,22 @@ class ApiTestCase(TestCase):
videos = [MOVIES[0]]
languages = {Language('eng')}
subtitles = list_subtitles(videos, languages)
self.assertTrue(len(subtitles) == len(videos))
self.assertTrue(len(subtitles[videos[0]]) > 0)
self.assertEqual(len(subtitles), len(videos))
self.assertGreater(len(subtitles[videos[0]]), 0)
def test_list_subtitles_movie_0_por_br(self):
videos = [MOVIES[0]]
languages = {Language('por', 'BR')}
subtitles = list_subtitles(videos, languages)
self.assertTrue(len(subtitles) == len(videos))
self.assertTrue(len(subtitles[videos[0]]) > 0)
self.assertEqual(len(subtitles), len(videos))
self.assertGreater(len(subtitles[videos[0]]), 0)
def test_list_subtitles_episodes(self):
videos = [EPISODES[0], EPISODES[1]]
languages = {Language('eng'), Language('fra')}
subtitles = list_subtitles(videos, languages)
self.assertTrue(len(subtitles) == len(videos))
self.assertTrue(len(subtitles[videos[0]]) > 0)
self.assertEqual(len(subtitles), len(videos))
self.assertGreater(len(subtitles[videos[0]]), 0)
def test_download_subtitles(self):
videos = [EPISODES[0], EPISODES[1]]
@@ -68,7 +68,7 @@ class ApiTestCase(TestCase):
languages = {Language('eng'), Language('fra')}
subtitles = download_best_subtitles(videos, languages)
for video in videos:
self.assertTrue(video in subtitles and len(subtitles[video]) == 2)
self.assertEqual(video in subtitles and len(subtitles[video]), 2)
self.assertTrue(os.path.exists(os.path.splitext(video.name)[0] + '.en.srt'))
self.assertTrue(os.path.exists(os.path.splitext(video.name)[0] + '.fr.srt'))
@@ -79,7 +79,8 @@ class ApiTestCase(TestCase):
languages = {Language('eng'), Language('fra')}
subtitles = download_best_subtitles(videos, languages, single=True)
for video in videos:
self.assertTrue(video in subtitles and len(subtitles[video]) == 1)
self.assertIn(video, subtitles)
self.assertEqual(len(subtitles[video]), 1)
self.assertTrue(os.path.exists(os.path.splitext(video.name)[0] + '.srt'))
def test_download_best_subtitles_min_score(self):
@@ -88,7 +89,7 @@ class ApiTestCase(TestCase):
video.name = os.path.join(TEST_DIR, video.name.split(os.sep)[-1])
languages = {Language('eng'), Language('fra')}
subtitles = download_best_subtitles(videos, languages, min_score=1000)
self.assertTrue(len(subtitles) == 0)
self.assertEqual(len(subtitles), 0)
def test_download_best_subtitles_hearing_impaired(self):
videos = [MOVIES[0]]
@@ -96,7 +97,7 @@ class ApiTestCase(TestCase):
video.name = os.path.join(TEST_DIR, video.name.split(os.sep)[-1])
languages = {Language('eng')}
subtitles = download_best_subtitles(videos, languages, hearing_impaired=True)
self.assertTrue(subtitles[videos[0]][0].hearing_impaired == True)
self.assertTrue(subtitles[videos[0]][0].hearing_impaired)
class VideoTestCase(TestCase):
@@ -111,47 +112,47 @@ class VideoTestCase(TestCase):
def test_scan_video_movie(self):
video = MOVIES[0]
scanned_video = scan_video(os.path.join(TEST_DIR, os.path.split(video.name)[1]))
self.assertTrue(scanned_video.name == os.path.join(TEST_DIR, os.path.split(video.name)[1]))
self.assertTrue(scanned_video.title.lower() == video.title.lower())
self.assertTrue(scanned_video.year == video.year)
self.assertTrue(scanned_video.video_codec == video.video_codec)
self.assertTrue(scanned_video.resolution == video.resolution)
self.assertTrue(scanned_video.release_group == video.release_group)
self.assertTrue(scanned_video.subtitle_languages == set())
self.assertTrue(scanned_video.hashes == {})
self.assertTrue(scanned_video.audio_codec is None)
self.assertTrue(scanned_video.imdb_id is None)
self.assertTrue(scanned_video.size == 0)
self.assertEqual(scanned_video.name, os.path.join(TEST_DIR, os.path.split(video.name)[1]))
self.assertEqual(scanned_video.title.lower(), video.title.lower())
self.assertEqual(scanned_video.year, video.year)
self.assertEqual(scanned_video.video_codec, video.video_codec)
self.assertEqual(scanned_video.resolution, video.resolution)
self.assertEqual(scanned_video.release_group, video.release_group)
self.assertEqual(scanned_video.subtitle_languages, set())
self.assertEqual(scanned_video.hashes, {})
self.assertIsNone(scanned_video.audio_codec)
self.assertIsNone(scanned_video.imdb_id)
self.assertEqual(scanned_video.size, 0)
def test_scan_video_episode(self):
video = EPISODES[0]
scanned_video = scan_video(os.path.join(TEST_DIR, os.path.split(video.name)[1]))
self.assertTrue(scanned_video.name == os.path.join(TEST_DIR, os.path.split(video.name)[1]))
self.assertTrue(scanned_video.series == video.series)
self.assertTrue(scanned_video.season == video.season)
self.assertTrue(scanned_video.episode == video.episode)
self.assertTrue(scanned_video.video_codec == video.video_codec)
self.assertTrue(scanned_video.resolution == video.resolution)
self.assertTrue(scanned_video.release_group == video.release_group)
self.assertTrue(scanned_video.subtitle_languages == set())
self.assertTrue(scanned_video.hashes == {})
self.assertTrue(scanned_video.title is None)
self.assertTrue(scanned_video.tvdb_id is None)
self.assertTrue(scanned_video.imdb_id is None)
self.assertTrue(scanned_video.audio_codec is None)
self.assertTrue(scanned_video.size == 0)
self.assertEqual(scanned_video.name, os.path.join(TEST_DIR, os.path.split(video.name)[1]))
self.assertEqual(scanned_video.series, video.series)
self.assertEqual(scanned_video.season, video.season)
self.assertEqual(scanned_video.episode, video.episode)
self.assertEqual(scanned_video.video_codec, video.video_codec)
self.assertEqual(scanned_video.resolution, video.resolution)
self.assertEqual(scanned_video.release_group, video.release_group)
self.assertEqual(scanned_video.subtitle_languages, set())
self.assertEqual(scanned_video.hashes, {})
self.assertIsNone(scanned_video.title)
self.assertIsNone(scanned_video.tvdb_id)
self.assertIsNone(scanned_video.imdb_id)
self.assertIsNone(scanned_video.audio_codec)
self.assertEqual(scanned_video.size, 0)
def test_scan_video_subtitle_language_und(self):
video = EPISODES[0]
open(os.path.join(TEST_DIR, os.path.splitext(os.path.split(video.name)[1])[0]) + '.srt', 'w').close()
scanned_video = scan_video(os.path.join(TEST_DIR, os.path.split(video.name)[1]))
self.assertTrue(scanned_video.subtitle_languages == {Language('und')})
self.assertEqual(scanned_video.subtitle_languages, {Language('und')})
def test_scan_video_subtitles_language_eng(self):
video = EPISODES[0]
open(os.path.join(TEST_DIR, os.path.splitext(os.path.split(video.name)[1])[0]) + '.en.srt', 'w').close()
scanned_video = scan_video(os.path.join(TEST_DIR, os.path.split(video.name)[1]))
self.assertTrue(scanned_video.subtitle_languages == {Language('eng')})
self.assertEqual(scanned_video.subtitle_languages, {Language('eng')})
def test_scan_video_subtitles_languages(self):
video = EPISODES[0]
@@ -159,7 +160,8 @@ class VideoTestCase(TestCase):
open(os.path.join(TEST_DIR, os.path.splitext(os.path.split(video.name)[1])[0]) + '.fr.srt', 'w').close()
open(os.path.join(TEST_DIR, os.path.splitext(os.path.split(video.name)[1])[0]) + '.srt', 'w').close()
scanned_video = scan_video(os.path.join(TEST_DIR, os.path.split(video.name)[1]))
self.assertTrue(scanned_video.subtitle_languages == {Language('eng'), Language('fra'), Language('und')})
self.assertEqual(scanned_video.subtitle_languages, {Language('eng'), Language('fra'), Language('und')})
def suite():
suite = TestSuite()
+15 -5
View File
@@ -156,7 +156,7 @@ def scan_subtitle_languages(path):
:rtype: set
"""
language_extensions = tuple('.' + c for c in babelfish.CONVERTERS['alpha2'].codes)
language_extensions = tuple('.' + c for c in babelfish.get_language_converter('alpha2').codes)
dirpath, filename = os.path.split(path)
subtitles = set()
for p in os.listdir(dirpath):
@@ -239,10 +239,20 @@ def scan_video(path, subtitles=True, embedded_subtitles=True):
if embedded_subtitles:
embedded_subtitle_languages = set()
for st in mkv.subtitle_tracks:
try:
embedded_subtitle_languages.add(babelfish.Language.fromalpha3b(st.language or 'und'))
except babelfish.Error:
logger.error('Embedded subtitle language %r is not a valid language', st.language)
if st.language:
try:
embedded_subtitle_languages.add(babelfish.Language.fromalpha3b(st.language))
except babelfish.Error:
logger.error('Embedded subtitle track language %r is not a valid language', st.language)
embedded_subtitle_languages.add(babelfish.Language('und'))
elif st.name:
try:
embedded_subtitle_languages.add(babelfish.Language.fromname(st.name))
except babelfish.Error:
logger.error('Embedded subtitle track name %r is not a valid language', st.name)
embedded_subtitle_languages.add(babelfish.Language('und'))
else:
embedded_subtitle_languages.add(babelfish.Language('und'))
logger.debug('Found embedded subtitle %r with enzyme', embedded_subtitle_languages)
video.subtitle_languages |= embedded_subtitle_languages
else: