Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fe76634d02 | |||
| b499540bed | |||
| 7b4a9c2060 | |||
| a84cc80a88 | |||
| 241cea9729 | |||
| 4b83ddc63e | |||
| 0b431fbb8d | |||
| 3736d921a1 | |||
| 380fb28d2e | |||
| 64c0ee4ccf | |||
| 5977bf69fb | |||
| 179ae6a24e | |||
| 16942ec4c7 | |||
| 6f5378ea40 | |||
| 02ee2039f4 | |||
| e7f89c1a19 | |||
| be4f9d92eb | |||
| ca63b97e79 | |||
| c1ed4a0232 | |||
| b826a0bf08 | |||
| fd0d87d719 | |||
| 094373f3c1 | |||
| 5dac623c9f | |||
| 57d1e772ec | |||
| 983efbfd9b | |||
| 1f11e293c1 | |||
| bfd278ae1c | |||
| dbe1b9d2af | |||
| d71bc4bf09 | |||
| faf2e1dfa4 | |||
| 93360aa1bb | |||
| 8df7780ef9 |
+23
@@ -1,6 +1,29 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
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
|
||||
|
||||
* Fix TVSubtitles for ambiguous series
|
||||
* Add a CACHE_VERSION to force cache reloading on version change
|
||||
* Set CLI default cache expiration time to 30 days
|
||||
* Add podnapisi provider
|
||||
* Support script for languages e.g. Latn, Cyrl
|
||||
* Improve logging levels
|
||||
* Fix subtitle validation in some rare cases
|
||||
|
||||
|
||||
0.7.1
|
||||
-----
|
||||
**release date:** 2013-11-06
|
||||
|
||||
+2
-1
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
+6
-2
@@ -2,6 +2,10 @@ Cache
|
||||
=====
|
||||
.. module:: subliminal.cache
|
||||
|
||||
.. autodata:: region
|
||||
.. autodata:: CACHE_VERSION
|
||||
.. autofunction:: subliminal_key_generator
|
||||
.. data:: region
|
||||
|
||||
Refer to `dogpile.cache's documentation <http://dogpilecache.readthedocs.org>`_ to see how to configure a region
|
||||
The dogpile.cache region
|
||||
|
||||
Refer to `dogpile.cache's documentation <http://dogpilecache.readthedocs.org>`_ to see how to configure the region
|
||||
|
||||
+2
-1
@@ -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
@@ -1,9 +1,9 @@
|
||||
beautifulsoup4>=4.3.2
|
||||
guessit>=0.6.1
|
||||
guessit>=0.6.2
|
||||
requests>=2.0.1
|
||||
enzyme>=0.4.0
|
||||
html5lib>=0.99
|
||||
dogpile.cache>=0.5.1
|
||||
babelfish>=0.2.1
|
||||
dogpile.cache>=0.5.2
|
||||
babelfish>=0.4.0
|
||||
charade>=1.0.3
|
||||
pysrt>=0.5.0
|
||||
|
||||
@@ -4,7 +4,7 @@ from setuptools import setup, find_packages
|
||||
|
||||
|
||||
setup(name='subliminal',
|
||||
version='0.7.1',
|
||||
version='0.7.3',
|
||||
license='MIT',
|
||||
description='Subtitles, faster than your thoughts',
|
||||
long_description=open('README.rst').read() + '\n\n' + open('HISTORY.rst').read(),
|
||||
@@ -29,10 +29,12 @@ setup(name='subliminal',
|
||||
'subliminal.providers': ['addic7ed = subliminal.providers.addic7ed:Addic7edProvider',
|
||||
'bierdopje = subliminal.providers.bierdopje:BierDopjeProvider',
|
||||
'opensubtitles = subliminal.providers.opensubtitles:OpenSubtitlesProvider',
|
||||
'podnapisi = subliminal.providers.podnapisi:PodnapisiProvider',
|
||||
'thesubdb = subliminal.providers.thesubdb:TheSubDBProvider',
|
||||
'tvsubtitles = subliminal.providers.tvsubtitles:TVsubtitlesProvider'],
|
||||
'babelfish.converters': ['addic7ed = subliminal.converters.addic7ed:Addic7edConverter',
|
||||
'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')
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
__title__ = 'subliminal'
|
||||
__version__ = '0.7.1'
|
||||
__version__ = '0.7.3'
|
||||
__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
|
||||
|
||||
+4
-4
@@ -47,11 +47,11 @@ def list_subtitles(videos, languages, providers=None, provider_configs=None):
|
||||
Provider = provider_entry_point.load()
|
||||
provider_languages = Provider.languages & languages - subtitle_languages
|
||||
if not provider_languages:
|
||||
logger.debug('Skipping provider %r: no language to search for', provider_entry_point.name)
|
||||
logger.info('Skipping provider %r: no language to search for', provider_entry_point.name)
|
||||
continue
|
||||
provider_videos = [v for v in videos if Provider.check(v)]
|
||||
if not provider_videos:
|
||||
logger.debug('Skipping provider %r: no video to search for', provider_entry_point.name)
|
||||
logger.info('Skipping provider %r: no video to search for', provider_entry_point.name)
|
||||
continue
|
||||
|
||||
# list subtitles with the provider
|
||||
@@ -184,10 +184,10 @@ def download_best_subtitles(videos, languages, providers=None, provider_configs=
|
||||
continue
|
||||
Provider = provider_entry_point.load()
|
||||
if not Provider.languages & languages - subtitle_languages:
|
||||
logger.debug('Skipping provider %r: no language to search for', provider_entry_point.name)
|
||||
logger.info('Skipping provider %r: no language to search for', provider_entry_point.name)
|
||||
continue
|
||||
if not [v for v in videos if Provider.check(v)]:
|
||||
logger.debug('Skipping provider %r: no video to search for', provider_entry_point.name)
|
||||
logger.info('Skipping provider %r: no video to search for', provider_entry_point.name)
|
||||
continue
|
||||
provider = Provider(**provider_configs.get(provider_entry_point.name, {}))
|
||||
try:
|
||||
|
||||
+53
-3
@@ -1,6 +1,56 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import dogpile.cache
|
||||
import inspect
|
||||
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
|
||||
|
||||
|
||||
#: The subliminal's dogpile.cache region
|
||||
region = dogpile.cache.make_region()
|
||||
#: Subliminal's cache version
|
||||
CACHE_VERSION = 1
|
||||
|
||||
|
||||
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__)
|
||||
else:
|
||||
namespace = '%d:%s:%s|%s' % (CACHE_VERSION, fn.__module__, fn.__name__, namespace)
|
||||
|
||||
args = inspect.getargspec(fn)
|
||||
has_self = args[0] and args[0][0] in ('self', 'cls')
|
||||
|
||||
def generate_key(*args, **kw):
|
||||
if kw:
|
||||
raise ValueError('Keyword arguments not supported')
|
||||
if has_self:
|
||||
args = args[1:]
|
||||
return namespace + '|' + ' '.join(map(to_str, args))
|
||||
return generate_key
|
||||
|
||||
|
||||
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)
|
||||
|
||||
+6
-5
@@ -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
|
||||
@@ -29,7 +29,7 @@ def subliminal():
|
||||
required_arguments_group = parser.add_argument_group('required arguments')
|
||||
required_arguments_group.add_argument('paths', nargs='+', metavar='PATH', help='path to video file or folder')
|
||||
required_arguments_group.add_argument('-l', '--languages', nargs='+', required=True, metavar='LANGUAGE',
|
||||
help='wanted languages as alpha2 code (ISO-639-1)')
|
||||
help='wanted languages as IETF codes e.g. fr, pt-BR, sr-Cyrl ')
|
||||
|
||||
# configuration
|
||||
configuration_group = parser.add_argument_group('configuration')
|
||||
@@ -81,9 +81,9 @@ def subliminal():
|
||||
|
||||
# parse languages
|
||||
try:
|
||||
args.languages = {babelfish.Language.fromalpha2(l) for l in args.languages}
|
||||
args.languages = {babelfish.Language.fromietf(l) for l in args.languages}
|
||||
except babelfish.Error:
|
||||
parser.error('argument -l/--languages: codes are not ISO-639-1: %r' % args.languages)
|
||||
parser.error('argument -l/--languages: codes are not IETF: %r' % args.languages)
|
||||
|
||||
# parse age
|
||||
if args.age is not None:
|
||||
@@ -138,7 +138,8 @@ def subliminal():
|
||||
logging.getLogger('subliminal.api').setLevel(logging.INFO)
|
||||
|
||||
# configure cache
|
||||
cache_region.configure('dogpile.cache.dbm', 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,
|
||||
|
||||
@@ -1,29 +1,31 @@
|
||||
# -*- 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.from_addic7ed = {'Català': ('cat', None), 'Chinese (Simplified)': ('zho', None),
|
||||
'Chinese (Traditional)': ('zho', None), 'Euskera': ('eus', None),
|
||||
'Galego': ('glg', None), 'Greek': ('ell', None),
|
||||
'Malay': ('msa', None), 'Portuguese (Brazilian)': ('por', 'BR'),
|
||||
'Serbian (Cyrillic)': ('srp', None), 'Serbian (Latin)': ('srp', None),
|
||||
'Spanish (Latin America)': ('spa', None), 'Spanish (Spain)': ('spa', None)}
|
||||
self.to_addic7ed = {('cat', None): 'Català', ('zho', None): 'Chinese (Simplified)',
|
||||
('eus', None): 'Euskera', ('glg', None): 'Galego',
|
||||
('ell', None): 'Greek', ('msa', None): 'Malay',
|
||||
('por', 'BR'): 'Portuguese (Brazilian)', ('srp', None): 'Serbian (Cyrillic)'}
|
||||
self.codes |= set(self.from_addic7ed.keys())
|
||||
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'),
|
||||
'Serbian (Latin)': ('srp',), 'Spanish (Latin America)': ('spa',),
|
||||
'Spanish (Spain)': ('spa',)}
|
||||
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 = self.name_converter.codes | set(self.from_addic7ed.keys())
|
||||
|
||||
def convert(self, alpha3, country=None):
|
||||
def convert(self, alpha3, country=None, script=None):
|
||||
if (alpha3, country, script) in self.to_addic7ed:
|
||||
return self.to_addic7ed[(alpha3, country, script)]
|
||||
if (alpha3, country) in self.to_addic7ed:
|
||||
return self.to_addic7ed[(alpha3, country)]
|
||||
return super(Addic7edConverter, self).convert(alpha3, country)
|
||||
if (alpha3,) in self.to_addic7ed:
|
||||
return self.to_addic7ed[(alpha3,)]
|
||||
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)
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from babelfish import LanguageReverseConverter, LanguageConvertError, LanguageReverseError
|
||||
|
||||
|
||||
class PodnapisiConverter(LanguageReverseConverter):
|
||||
def __init__(self):
|
||||
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',),
|
||||
7: ('ces',), 25: ('swe',), 27: ('rus',), 24: ('dan',), 22: ('heb',), 51: ('vie',),
|
||||
52: ('fas',), 5: ('deu',), 14: ('spa', 'AR'), 54: ('ind',), 47: ('srp', None, 'Cyrl'),
|
||||
3: ('nor',), 20: ('est',), 10: ('bos',), 17: ('zho',), 37: ('slk',), 35: ('mkd',),
|
||||
11: ('jpn',), 4: ('kor',), 29: ('sqi',), 6: ('isl',), 19: ('lit',), 46: ('ukr',),
|
||||
44: ('tha',), 53: ('cat',), 56: ('sin',), 21: ('lav',), 40: ('cmn',), 55: ('msa',),
|
||||
42: ('hin',), 50: ('bel',)}
|
||||
self.to_podnapisi = {v: k for k, v in self.from_podnapisi.items()}
|
||||
self.codes = set(self.from_podnapisi.keys())
|
||||
|
||||
def convert(self, alpha3, country=None, script=None):
|
||||
if (alpha3,) in self.to_podnapisi:
|
||||
return self.to_podnapisi[(alpha3,)]
|
||||
if (alpha3, country) in self.to_podnapisi:
|
||||
return self.to_podnapisi[(alpha3, country)]
|
||||
if (alpha3, country, script) in self.to_podnapisi:
|
||||
return self.to_podnapisi[(alpha3, country, script)]
|
||||
raise LanguageConvertError(alpha3, country, script)
|
||||
|
||||
def reverse(self, podnapisi):
|
||||
if podnapisi not in self.from_podnapisi:
|
||||
raise LanguageReverseError(podnapisi)
|
||||
return self.from_podnapisi[podnapisi]
|
||||
@@ -1,22 +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.from_tvsubtitles = {'br': ('por', 'BR'), 'ua': ('ukr', None), 'gr': ('ell', None), 'cn': ('zho', None),
|
||||
'jp': ('jpn', None), 'cz': ('ces', None)}
|
||||
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):
|
||||
def convert(self, alpha3, country=None, script=None):
|
||||
if (alpha3, country) in self.to_tvsubtitles:
|
||||
return self.to_tvsubtitles[(alpha3, country)]
|
||||
return super(TVsubtitlesConverter, self).convert(alpha3, country)
|
||||
if (alpha3,) in self.to_tvsubtitles:
|
||||
return self.to_tvsubtitles[(alpha3,)]
|
||||
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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -118,10 +118,7 @@ class BierDopjeProvider(Provider):
|
||||
result.find('downloadlink').text) for result in root.find('response/results')]
|
||||
|
||||
def list_subtitles(self, video, languages):
|
||||
subtitles = []
|
||||
for language in languages:
|
||||
subtitles.extend(self.query(language, video.season, video.episode, video.tvdb_id, video.series))
|
||||
return subtitles
|
||||
return [s for l in languages for s in self.query(l, video.season, video.episode, video.tvdb_id, video.series)]
|
||||
|
||||
def download_subtitle(self, subtitle):
|
||||
try:
|
||||
|
||||
@@ -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)})
|
||||
@@ -128,7 +128,6 @@ class OpenSubtitlesProvider(Provider):
|
||||
if not response['data']:
|
||||
logger.debug('No subtitle found')
|
||||
return []
|
||||
logger.debug('Found subtitles %r', response['data'])
|
||||
return [OpenSubtitlesSubtitle(babelfish.Language.fromopensubtitles(r['SubLanguageID']),
|
||||
bool(int(r['SubHearingImpaired'])), r['IDSubtitleFile'], r['MatchedBy'],
|
||||
r['MovieKind'], r['MovieHash'], r['MovieName'], r['MovieReleaseName'],
|
||||
@@ -141,7 +140,8 @@ class OpenSubtitlesProvider(Provider):
|
||||
query = None
|
||||
if ('opensubtitles' not in video.hashes or not video.size) and not video.imdb_id:
|
||||
query = video.name.split(os.sep)[-1]
|
||||
return self.query(languages, hash=video.hashes.get('opensubtitles'), size=video.size, imdb_id=video.imdb_id, query=query)
|
||||
return self.query(languages, hash=video.hashes.get('opensubtitles'), size=video.size, imdb_id=video.imdb_id,
|
||||
query=query)
|
||||
|
||||
def download_subtitle(self, subtitle):
|
||||
try:
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import io
|
||||
import logging
|
||||
import re
|
||||
import xml.etree.ElementTree
|
||||
import zipfile
|
||||
import babelfish
|
||||
import bs4
|
||||
import charade
|
||||
import guessit
|
||||
import requests
|
||||
from . import Provider
|
||||
from .. import __version__
|
||||
from ..exceptions import InvalidSubtitle, ProviderNotAvailable, ProviderError
|
||||
from ..subtitle import Subtitle, is_valid_subtitle, compute_guess_matches
|
||||
from ..video import Episode, Movie
|
||||
|
||||
|
||||
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, # @ReservedAssignment
|
||||
title=None, year=None):
|
||||
super(PodnapisiSubtitle, self).__init__(language, hearing_impaired)
|
||||
self.id = id
|
||||
self.releases = releases
|
||||
self.hearing_impaired = hearing_impaired
|
||||
self.link = link
|
||||
self.series = series
|
||||
self.season = season
|
||||
self.episode = episode
|
||||
self.title = title
|
||||
self.year = year
|
||||
|
||||
def compute_matches(self, video):
|
||||
matches = set()
|
||||
# episode
|
||||
if isinstance(video, Episode):
|
||||
# series
|
||||
if video.series and self.series.lower() == video.series.lower():
|
||||
matches.add('series')
|
||||
# season
|
||||
if video.season and self.season == video.season:
|
||||
matches.add('season')
|
||||
# episode
|
||||
if video.episode and self.episode == video.episode:
|
||||
matches.add('episode')
|
||||
# guess
|
||||
for release in self.releases:
|
||||
matches |= compute_guess_matches(video, guessit.guess_episode_info(release + '.mkv'))
|
||||
# movie
|
||||
elif isinstance(video, Movie):
|
||||
# title
|
||||
if video.title and self.title.lower() == video.title.lower():
|
||||
matches.add('title')
|
||||
# year
|
||||
if video.year and self.year == video.year:
|
||||
matches.add('year')
|
||||
# guess
|
||||
for release in self.releases:
|
||||
matches |= compute_guess_matches(video, guessit.guess_movie_info(release + '.mkv'))
|
||||
return matches
|
||||
|
||||
|
||||
class PodnapisiProvider(Provider):
|
||||
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/.*$)')
|
||||
|
||||
def initialize(self):
|
||||
self.session = requests.Session()
|
||||
self.session.headers = {'User-Agent': 'Subliminal/%s' % __version__}
|
||||
|
||||
def terminate(self):
|
||||
self.session.close()
|
||||
|
||||
def get(self, url, params=None, is_xml=True):
|
||||
"""Make a GET request on `url` with the given parameters
|
||||
|
||||
:param string url: part of the URL to reach with the leading slash
|
||||
:param dict params: params of the request
|
||||
:param bool xml: whether the response content is XML or not
|
||||
:return: the response
|
||||
:rtype: :class:`xml.etree.ElementTree.Element` or :class:`bs4.BeautifulSoup`
|
||||
:raise: :class:`~subliminal.exceptions.ProviderNotAvailable`
|
||||
|
||||
"""
|
||||
try:
|
||||
r = self.session.get(self.server + '/ppodnapisi' + url, params=params, timeout=10)
|
||||
except requests.Timeout:
|
||||
raise ProviderNotAvailable('Timeout after 10 seconds')
|
||||
if r.status_code != 200:
|
||||
raise ProviderNotAvailable('Request failed with status code %d' % r.status_code)
|
||||
if is_xml:
|
||||
return xml.etree.ElementTree.fromstring(r.content)
|
||||
else:
|
||||
return bs4.BeautifulSoup(r.content, ['permissive'])
|
||||
|
||||
def query(self, language, series=None, season=None, episode=None, title=None, year=None):
|
||||
params = {'sXML': 1, 'sJ': language.podnapisi}
|
||||
if series and season and episode:
|
||||
params['sK'] = series
|
||||
params['sTS'] = season
|
||||
params['sTE'] = episode
|
||||
elif title:
|
||||
params['sK'] = title
|
||||
if year:
|
||||
params['sY'] = year
|
||||
else:
|
||||
raise ValueError('Missing parameters series and season and episode or title')
|
||||
logger.debug('Searching episode %r', params)
|
||||
subtitles = []
|
||||
while True:
|
||||
root = self.get('/search', params)
|
||||
if not int(root.find('pagination/results').text):
|
||||
logger.debug('No subtitle found')
|
||||
break
|
||||
if series and season and episode:
|
||||
subtitles.extend([PodnapisiSubtitle(language, int(s.find('id').text), s.find('release').text.split(),
|
||||
'h' in (s.find('flags').text or ''), s.find('url').text[38:],
|
||||
series=series, season=season, episode=episode)
|
||||
for s in root.findall('subtitle')])
|
||||
elif title:
|
||||
subtitles.extend([PodnapisiSubtitle(language, int(s.find('id').text), s.find('release').text.split(),
|
||||
'h' in (s.find('flags').text or ''), s.find('url').text[38:],
|
||||
title=title, year=year)
|
||||
for s in root.findall('subtitle')])
|
||||
if int(root.find('pagination/current').text) >= int(root.find('pagination/count').text):
|
||||
break
|
||||
params['page'] = int(root.find('pagination/current').text) + 1
|
||||
return subtitles
|
||||
|
||||
def list_subtitles(self, video, languages):
|
||||
if isinstance(video, Episode):
|
||||
return [s for l in languages for s in self.query(l, series=video.series, season=video.season,
|
||||
episode=video.episode)]
|
||||
elif isinstance(video, Movie):
|
||||
return [s for l in languages for s in self.query(l, title=video.title, year=video.year)]
|
||||
|
||||
def download_subtitle(self, subtitle):
|
||||
soup = self.get(subtitle.link, is_xml=False)
|
||||
link = soup.find('a', href=self.link_re)
|
||||
if not link:
|
||||
raise ProviderError('Cannot find the download link')
|
||||
try:
|
||||
r = self.session.get(self.server + self.link_re.match(link['href']).group('link'), timeout=10)
|
||||
except requests.Timeout:
|
||||
raise ProviderNotAvailable('Timeout after 10 seconds')
|
||||
if r.status_code != 200:
|
||||
raise ProviderNotAvailable('Request failed with status code %d' % r.status_code)
|
||||
with zipfile.ZipFile(io.BytesIO(r.content)) as zf:
|
||||
if len(zf.namelist()) > 1:
|
||||
raise ProviderError('More than one file to unzip')
|
||||
subtitle_bytes = zf.read(zf.namelist()[0])
|
||||
subtitle_text = subtitle_bytes.decode(charade.detect(subtitle_bytes)['encoding'], 'replace')
|
||||
if not is_valid_subtitle(subtitle_text):
|
||||
raise InvalidSubtitle
|
||||
return subtitle_text
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
@@ -61,8 +61,9 @@ class TVsubtitlesProvider(Provider):
|
||||
'nld', 'pol', 'por', 'ron', 'rus', 'spa', 'swe', 'tur', 'ukr', 'zho']}
|
||||
video_types = (Episode,)
|
||||
server = 'http://www.tvsubtitles.net'
|
||||
episode_id_re = re.compile('^episode-(\d+)\.html$')
|
||||
subtitle_re = re.compile('^\/subtitle-(\d+)\.html$')
|
||||
episode_id_re = re.compile('^episode-\d+\.html$')
|
||||
subtitle_re = re.compile('^\/subtitle-\d+\.html$')
|
||||
link_re = re.compile('^(?P<series>.+) \(\d{4}-\d{4}\)$')
|
||||
|
||||
def initialize(self):
|
||||
self.session = requests.Session()
|
||||
@@ -77,6 +78,7 @@ class TVsubtitlesProvider(Provider):
|
||||
:param string url: part of the URL to reach with the leading slash
|
||||
:param dict params: params of the request
|
||||
:param dict data: data of the request
|
||||
:param string method: method of the request
|
||||
:return: the response
|
||||
:rtype: :class:`bs4.BeautifulSoup`
|
||||
:raise: :class:`~subliminal.exceptions.ProviderNotAvailable`
|
||||
@@ -106,6 +108,13 @@ class TVsubtitlesProvider(Provider):
|
||||
if not links:
|
||||
logger.info('Series %r not found', series)
|
||||
return None
|
||||
for link in links:
|
||||
match = self.link_re.match(link.string)
|
||||
if not match:
|
||||
logger.warning('Could not parse %r', link.string)
|
||||
continue
|
||||
if match.group('series').lower().replace('.', ' ').strip() == series.lower():
|
||||
return int(link['href'][8:-5])
|
||||
return int(links[0]['href'][8:-5])
|
||||
|
||||
@region.cache_on_arguments()
|
||||
|
||||
+1
-1
@@ -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')
|
||||
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ class Subtitle(object):
|
||||
return score
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s [%r]>' % (self.__class__.__name__, self.language)
|
||||
return '<%s [%s]>' % (self.__class__.__name__, self.language)
|
||||
|
||||
|
||||
def get_subtitle_path(video_path, language=None):
|
||||
@@ -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,12 @@ def is_valid_subtitle(subtitle_text):
|
||||
try:
|
||||
pysrt.from_string(subtitle_text, error_handling=pysrt.ERROR_RAISE)
|
||||
return True
|
||||
except pysrt.Error:
|
||||
return False
|
||||
except pysrt.Error as e:
|
||||
if e.args[0] > 80:
|
||||
return True
|
||||
except:
|
||||
logger.exception('Unexpected error when validating subtitle')
|
||||
return False
|
||||
|
||||
|
||||
def compute_guess_matches(video, guess):
|
||||
|
||||
@@ -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()])
|
||||
|
||||
|
||||
|
||||
@@ -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,58 @@ 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]
|
||||
languages = {Language('eng'), Language('fra')}
|
||||
with self.Provider() as provider:
|
||||
subtitles = provider.list_subtitles(video, languages)
|
||||
subtitle_text = provider.download_subtitle(subtitles[0])
|
||||
self.assertTrue(is_valid_subtitle(subtitle_text))
|
||||
|
||||
|
||||
class PodnapisiProviderTestCase(ProviderTestCase):
|
||||
provider_name = 'podnapisi'
|
||||
|
||||
def test_query_movie_0(self):
|
||||
video = MOVIES[0]
|
||||
language = Language('eng')
|
||||
matches = {frozenset(['video_codec', 'title', 'resolution', 'year']),
|
||||
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', 'audio_codec', 'year'])}
|
||||
with self.Provider() as provider:
|
||||
subtitles = provider.query(language, title=video.title, year=video.year)
|
||||
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]
|
||||
language = Language('eng')
|
||||
matches = {frozenset(['episode', 'series', 'season', 'video_codec', 'resolution', 'release_group']),
|
||||
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.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]
|
||||
languages = {Language('eng'), Language('fra')}
|
||||
matches = {frozenset(['video_codec', 'title', 'resolution', 'year']),
|
||||
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', 'audio_codec', 'year'])}
|
||||
with self.Provider() as provider:
|
||||
subtitles = provider.list_subtitles(video, 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]
|
||||
@@ -287,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]
|
||||
@@ -296,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]
|
||||
@@ -305,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]
|
||||
@@ -323,17 +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.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.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]
|
||||
@@ -342,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]
|
||||
@@ -354,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]
|
||||
@@ -363,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]
|
||||
@@ -380,6 +443,7 @@ def suite():
|
||||
suite.addTest(TestLoader().loadTestsFromTestCase(Addic7edProviderTestCase))
|
||||
suite.addTest(TestLoader().loadTestsFromTestCase(BierDopjeProviderTestCase))
|
||||
suite.addTest(TestLoader().loadTestsFromTestCase(OpenSubtitlesProviderTestCase))
|
||||
suite.addTest(TestLoader().loadTestsFromTestCase(PodnapisiProviderTestCase))
|
||||
suite.addTest(TestLoader().loadTestsFromTestCase(TheSubDBProviderTestCase))
|
||||
suite.addTest(TestLoader().loadTestsFromTestCase(TVsubtitlesProviderTestCase))
|
||||
return suite
|
||||
|
||||
@@ -5,7 +5,7 @@ import os
|
||||
import shutil
|
||||
from unittest import TestCase, TestSuite, TestLoader, TextTestRunner
|
||||
from babelfish import Language
|
||||
from subliminal import list_subtitles, download_subtitles, download_best_subtitles, scan_video, scan_videos
|
||||
from subliminal import list_subtitles, download_subtitles, download_best_subtitles, scan_video
|
||||
from subliminal.tests.common import MOVIES, EPISODES
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
+16
-6
@@ -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,14 +239,24 @@ 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:
|
||||
logger.info('MKV has no subtitle track')
|
||||
logger.debug('MKV has no subtitle track')
|
||||
except enzyme.Error:
|
||||
logger.error('Parsing video metadata with enzyme failed')
|
||||
return video
|
||||
|
||||
Reference in New Issue
Block a user