Skip to content

Commit

Permalink
Updated subliminal to 1.1.0.dev0, added no_setup patch, added napipro…
Browse files Browse the repository at this point in the history
…jekt subtitles provider, fixed SickChill#3251
  • Loading branch information
medariox committed Oct 11, 2015
1 parent 4e9e531 commit 24d891e
Show file tree
Hide file tree
Showing 19 changed files with 473 additions and 84 deletions.
151 changes: 151 additions & 0 deletions .build/patches/subliminal.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
diff --git a/sublimnal/api.py b/subliminal/api.py
index 13c614f..6fe3368 100644
--- a/sublimnal/api.py
+++ b/subliminal/api.py
@@ -7,6 +7,7 @@ import os.path
import socket

from babelfish import Language
+from pkg_resources import EntryPoint
import requests
from stevedore import EnabledExtensionManager, ExtensionManager

@@ -14,7 +15,30 @@ from .subtitle import compute_score, get_subtitle_path

logger = logging.getLogger(__name__)

-provider_manager = ExtensionManager('subliminal.providers')
+
+class InternalExtensionManager(ExtensionManager):
+ """Add support for internal entry points to the :class:`~stevedore.extension.Extensionmanager`
+ Internal entry points are useful for libraries that ship their own plugins but still keep the entry point open.
+ All other parameters are passed onwards to the :class:`~stevedore.extension.Extensionmanager` constructor.
+ :param internal_entry_points: the internal providers
+ :type internal_entry_points: list of :class:`~pkg_resources.EntryPoint`
+ """
+ def __init__(self, namespace, internal_entry_points, **kwargs):
+ self.internal_entry_points = list(internal_entry_points)
+ super(InternalExtensionManager, self).__init__(namespace, **kwargs)
+
+ def _find_entry_points(self, namespace):
+ return self.internal_entry_points + super(InternalExtensionManager, self)._find_entry_points(namespace)
+
+
+provider_manager = InternalExtensionManager('subliminal.providers', [EntryPoint.parse(ep) for ep in (
+ 'addic7ed = subliminal.providers.addic7ed:Addic7edProvider',
+ 'napiprojekt = subliminal.providers.napiprojekt:NapiProjektProvider',
+ 'opensubtitles = subliminal.providers.opensubtitles:OpenSubtitlesProvider',
+ 'podnapisi = subliminal.providers.podnapisi:PodnapisiProvider',
+ 'thesubdb = subliminal.providers.thesubdb:TheSubDBProvider',
+ 'tvsubtitles = subliminal.providers.tvsubtitles:TVsubtitlesProvider'
+)])


class ProviderPool(object):
diff --git a/subliminal/compat.py b/subliminal/compat.py
new file mode 100644
index 0000000..28bd3e8
--- /dev/null
+++ b/subliminal/compat.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+import sys
+import socket
+
+
+if sys.version_info[0] == 2:
+ from xmlrpclib import ServerProxy, Transport
+ from httplib import HTTPConnection
+elif sys.version_info[0] == 3:
+ from xmlrpc.client import ServerProxy, Transport
+ from http.client import HTTPConnection
+
+
+class TimeoutTransport(Transport, object):
+ def __init__(self, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, *args, **kwargs):
+ super(TimeoutTransport, self).__init__(*args, **kwargs)
+ self.timeout = timeout
+
+ def make_connection(self, host):
+ h = HTTPConnection(host, timeout=self.timeout)
+ return h
diff --git a/subliminal/converters/podnapisi.py b/subliminal/converters/podnapisi.py
new file mode 100644
index 0000000..d73cb1c
--- /dev/null
+++ b/subliminal/converters/podnapisi.py
@@ -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]
diff --git a/sublimnal/providers/addic7ed.py b/subliminal/providers/addic7ed.py
index edaa728..3edfe35 100644
--- a/sublimnal/providers/addic7ed.py
+++ b/subliminal/providers/addic7ed.py
@@ -2,7 +2,7 @@
import logging
import re

-from babelfish import Language
+from babelfish import Language, language_converters
from requests import Session

from . import ParserBeautifulSoup, Provider, get_version
@@ -13,6 +13,7 @@ from ..subtitle import Subtitle, fix_line_ending, guess_matches, guess_propertie
from ..video import Episode

logger = logging.getLogger(__name__)
+language_converters.register('addic7ed = subliminal.converters.addic7ed:Addic7edConverter')

series_year_re = re.compile('^(?P<series>[ \w]+)(?: \((?P<year>\d{4})\))?$')

diff --git a/sublimnal/providers/tvsubtitles.py b/subliminal/providers/tvsubtitles.py
index e63cd43..06fd878 100644
--- a/sublimnal/providers/tvsubtitles.py
+++ b/subliminal/providers/tvsubtitles.py
@@ -4,7 +4,7 @@ import logging
import re
from zipfile import ZipFile

-from babelfish import Language
+from babelfish import Language, language_converters
from requests import Session

from . import ParserBeautifulSoup, Provider, get_version
@@ -15,6 +15,7 @@ from ..subtitle import Subtitle, fix_line_ending, guess_matches, guess_propertie
from ..video import Episode

logger = logging.getLogger(__name__)
+language_converters.register('tvsubtitles = subliminal.converters.tvsubtitles:TVsubtitlesConverter')

link_re = re.compile('^(?P<series>.+?)(?: \(?\d{4}\)?| \((?:US|UK)\))? \((?P<first_year>\d{4})-\d{4}\)$')
episode_id_re = re.compile('^episode-\d+\.html$')
Binary file added gui/slick/images/subtitles/napiprojekt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions lib/subliminal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
__title__ = 'subliminal'
__version__ = '1.0.dev0'
__version__ = '1.1.0.dev0'
__author__ = 'Antoine Bertin'
__license__ = 'MIT'
__copyright__ = 'Copyright 2015, Antoine Bertin'
Expand All @@ -12,7 +12,7 @@
from .cache import region
from .exceptions import Error, ProviderError
from .providers import Provider
from .subtitle import Subtitle
from .subtitle import Subtitle, compute_score
from .video import SUBTITLE_EXTENSIONS, VIDEO_EXTENSIONS, Episode, Movie, Video, scan_video, scan_videos

logging.getLogger(__name__).addHandler(logging.NullHandler())
19 changes: 5 additions & 14 deletions lib/subliminal/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from collections import defaultdict
import io
import logging
Expand All @@ -10,8 +9,7 @@
from babelfish import Language
from pkg_resources import EntryPoint
import requests
from stevedore import ExtensionManager
from stevedore.dispatch import DispatchExtensionManager
from stevedore import EnabledExtensionManager, ExtensionManager

from .subtitle import compute_score, get_subtitle_path

Expand All @@ -20,14 +18,10 @@

class InternalExtensionManager(ExtensionManager):
"""Add support for internal entry points to the :class:`~stevedore.extension.Extensionmanager`
Internal entry points are useful for libraries that ship their own plugins but still keep the entry point open.
All other parameters are passed onwards to the :class:`~stevedore.extension.Extensionmanager` constructor.
:param internal_entry_points: the internal providers
:type internal_entry_points: list of :class:`~pkg_resources.EntryPoint`
"""
def __init__(self, namespace, internal_entry_points, **kwargs):
self.internal_entry_points = list(internal_entry_points)
Expand All @@ -39,6 +33,7 @@ def _find_entry_points(self, namespace):

provider_manager = InternalExtensionManager('subliminal.providers', [EntryPoint.parse(ep) for ep in (
'addic7ed = subliminal.providers.addic7ed:Addic7edProvider',
'napiprojekt = subliminal.providers.napiprojekt:NapiProjektProvider',
'opensubtitles = subliminal.providers.opensubtitles:OpenSubtitlesProvider',
'podnapisi = subliminal.providers.podnapisi:PodnapisiProvider',
'thesubdb = subliminal.providers.thesubdb:TheSubDBProvider',
Expand Down Expand Up @@ -74,8 +69,8 @@ def __init__(self, providers=None, provider_configs=None):
#: Discarded providers
self.discarded_providers = set()

#: Dedicated :data:`provider_manager` as :class:`~stevedore.dispatch.DispatchExtensionManager`
self.manager = DispatchExtensionManager(provider_manager.namespace, lambda e: e.name in self.providers)
#: Dedicated :data:`provider_manager` as :class:`~stevedore.enabled.EnabledExtensionManager`
self.manager = EnabledExtensionManager(provider_manager.namespace, lambda e: e.name in self.providers)

def __enter__(self):
return self
Expand Down Expand Up @@ -217,7 +212,7 @@ def download_best_subtitles(self, subtitles, video, languages, min_score=0, hear
for subtitle, score in scored_subtitles:
# check score
if score < min_score:
logger.info('Score %d is below min_score (%d)', (score, min_score))
logger.info('Score %d is below min_score (%d)', score, min_score)
break

# check downloaded languages
Expand Down Expand Up @@ -297,7 +292,6 @@ def list_subtitles(videos, languages, **kwargs):
:type videos: set of :class:`~subliminal.video.Video`
:param languages: languages to search for.
:type languages: set of :class:`~babelfish.language.Language`
:param providers: name of providers to use, if not all.
:return: found subtitles per video.
:rtype: dict of :class:`~subliminal.video.Video` to list of :class:`~subliminal.subtitle.Subtitle`
Expand Down Expand Up @@ -334,8 +328,6 @@ def download_subtitles(subtitles, **kwargs):
:param subtitles: subtitles to download.
:type subtitles: list of :class:`~subliminal.subtitle.Subtitle`
:param dict provider_configs: provider configuration as keyword arguments per provider name to pass when.
instanciating the :class:`~subliminal.providers.Provider`.
"""
with ProviderPool(**kwargs) as pool:
Expand All @@ -356,7 +348,6 @@ def download_best_subtitles(videos, languages, min_score=0, hearing_impaired=Fal
:type videos: set of :class:`~subliminal.video.Video`
:param languages: languages to download.
:type languages: set of :class:`~babelfish.language.Language`
:param providers: name of providers to use, if not all.
:param int min_score: minimum score for a subtitle to be downloaded.
:param bool hearing_impaired: hearing impaired preference.
:param bool only_one: download only one subtitle, not one per language.
Expand Down
Loading

0 comments on commit 24d891e

Please sign in to comment.