Skip to content

Commit

Permalink
Merge be472d9 into ffa808b
Browse files Browse the repository at this point in the history
  • Loading branch information
ratoaq2 committed Feb 25, 2019
2 parents ffa808b + be472d9 commit f4f0fdd
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 7 deletions.
1 change: 1 addition & 0 deletions subliminal/cli.py
Expand Up @@ -279,6 +279,7 @@ def subliminal(ctx, addic7ed, legendastv, opensubtitles, omdb, cache_dir, debug)
ctx.obj['provider_configs']['legendastv'] = {'username': legendastv[0], 'password': legendastv[1]}
if opensubtitles:
ctx.obj['provider_configs']['opensubtitles'] = {'username': opensubtitles[0], 'password': opensubtitles[1]}
ctx.obj['provider_configs']['opensubtitlesvip'] = {'username': opensubtitles[0], 'password': opensubtitles[1]}

# refiner configs
if omdb:
Expand Down
4 changes: 2 additions & 2 deletions subliminal/core.py
Expand Up @@ -13,7 +13,7 @@
from rarfile import BadRarFile, NotRarFile, RarCannotExec, RarFile, Error, is_rarfile
from zipfile import BadZipfile

from .extensions import provider_manager, refiner_manager
from .extensions import provider_manager, default_providers, refiner_manager
from .score import compute_score as default_compute_score
from .subtitle import SUBTITLE_EXTENSIONS
from .utils import handle_exception
Expand Down Expand Up @@ -41,7 +41,7 @@ class ProviderPool(object):
"""
def __init__(self, providers=None, provider_configs=None):
#: Name of providers to use
self.providers = providers or provider_manager.names()
self.providers = providers or default_providers

#: Provider configuration
self.provider_configs = provider_configs or {}
Expand Down
7 changes: 7 additions & 0 deletions subliminal/extensions.py
Expand Up @@ -92,12 +92,19 @@ def unregister(self, entry_point):
'argenteam = subliminal.providers.argenteam:ArgenteamProvider',
'legendastv = subliminal.providers.legendastv:LegendasTVProvider',
'opensubtitles = subliminal.providers.opensubtitles:OpenSubtitlesProvider',
'opensubtitlesvip = subliminal.providers.opensubtitles:OpenSubtitlesVipProvider',
'podnapisi = subliminal.providers.podnapisi:PodnapisiProvider',
'shooter = subliminal.providers.shooter:ShooterProvider',
'thesubdb = subliminal.providers.thesubdb:TheSubDBProvider',
'tvsubtitles = subliminal.providers.tvsubtitles:TVsubtitlesProvider'
])

#: Disabled providers
disabled_providers = ['opensubtitlesvip']

#: Default enabled providers
default_providers = [p for p in provider_manager.names() if p not in disabled_providers]

#: Refiner manager
refiner_manager = RegistrableExtensionManager('subliminal.refiners', [
'hash = subliminal.refiners.hash:refine',
Expand Down
11 changes: 11 additions & 0 deletions subliminal/providers/opensubtitles.py
Expand Up @@ -219,6 +219,17 @@ def download_subtitle(self, subtitle):
subtitle.content = fix_line_ending(zlib.decompress(base64.b64decode(response['data'][0]['data']), 47))


class OpenSubtitlesVipSubtitle(OpenSubtitlesSubtitle):
"""OpenSubtitles Subtitle."""
provider_name = 'opensubtitlesvip'


class OpenSubtitlesVipProvider(OpenSubtitlesProvider):
"""OpenSubtitles Provider using VIP url."""
server_url = 'https://vip-api.opensubtitles.org/xml-rpc'
subtitle_class = OpenSubtitlesVipSubtitle


class OpenSubtitlesError(ProviderError):
"""Base class for non-generic :class:`OpenSubtitlesProvider` exceptions."""
pass
Expand Down
5 changes: 3 additions & 2 deletions subliminal/refiners/hash.py
@@ -1,14 +1,15 @@
# -*- coding: utf-8 -*-
import logging

from ..extensions import provider_manager
from ..extensions import provider_manager, default_providers
from ..utils import hash_napiprojekt, hash_opensubtitles, hash_shooter, hash_thesubdb

logger = logging.getLogger(__name__)

hash_functions = {
'napiprojekt': hash_napiprojekt,
'opensubtitles': hash_opensubtitles,
'opensubtitlesvip': hash_opensubtitles,
'shooter': hash_shooter,
'thesubdb': hash_thesubdb
}
Expand All @@ -27,7 +28,7 @@ def refine(video, providers=None, languages=None, **kwargs):
return

logger.debug('Computing hashes for %r', video.name)
for name in providers or provider_manager.names():
for name in providers or default_providers:
provider = provider_manager[name].plugin
if name not in hash_functions:
continue
Expand Down
82 changes: 82 additions & 0 deletions tests/cassettes/opensubtitles/test_login_vip_bad_password.yaml
@@ -0,0 +1,82 @@
interactions:
- request:
body: !!python/unicode '<?xml version=''1.0''?>

<methodCall>

<methodName>LogIn</methodName>

<params>

<param>

<value><string>python-subliminal</string></value>

</param>

<param>

<value><string>lanimilbus</string></value>

</param>

<param>

<value><string>eng</string></value>

</param>

<param>

<value><string>subliminal v2.1</string></value>

</param>

</params>

</methodCall>

'
headers:
Accept-Encoding: [gzip]
Content-Length: ['344']
Content-Type: [text/xml]
User-Agent: [xmlrpclib.py/1.0.1 (by www.pythonware.com)]
method: POST
uri: https://vip-api.opensubtitles.org/xml-rpc
response:
body:
string: !!binary |
H4sIAAAAAAAAA42Q3WrDMAxGXyXkuotdKFsCqgvt6AOEhY3eObHahcVy658w9vTLhlPatBe9six9
OogDq2/dJT1a1xpapvOMpwlSY1RLh2Ua/P4pT1cCNPpPo0p0R0MOBRylldrFV0AvuzB0nbeh8X9p
XaMVQFKj8OYLCdh/fREc+KLs3WtFu4+6a16oUO+zt3A4bZ63600BLGaAxR02Uq/ozksf3H38gs+T
imQYTrftD6qHmdgYUlOoMqHuUPCM8xxY/N2S2CjhPImO2OiMTWT+ArDm40CDAQAA
headers:
accept-ranges: [bytes]
access-control-allow-headers: ['Origin,X-Requested-With,Content-Type,Accept,DNT,Keep-Alive,User-Agent,If-Modified-Since,Cache-Control']
access-control-allow-methods: ['GET, POST, OPTIONS']
access-control-allow-origin: ['*']
age: ['0']
cf-ray: [4ae2119ddcb5cc48-ZRH]
connection: [keep-alive]
content-encoding: [gzip]
content-length: ['219']
content-type: [text/xml;charset=UTF-8]
date: ['Sun, 24 Feb 2019 12:52:20 GMT']
expect-ct: ['max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"']
server: [cloudflare]
set-cookie: ['__cfduid=d3f61f7c813d6c85eaa7452c1c00c54841551012740; expires=Mon,
24-Feb-20 12:52:20 GMT; path=/; domain=.opensubtitles.org; HttpOnly', 'PHPSESSID=RvsDUnZXblc7n9dW%2CTugqC6FBC9;
expires=Sun, 24-Feb-2019 18:52:20 GMT; Max-Age=21600; path=/; domain=.opensubtitles.org;
HttpOnly', 'remember_sid=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT;
Max-Age=0; path=/; domain=.opensubtitles.org; httponly']
vary: [Accept-Encoding]
x-cache: [MISS]
x-cache-backend: [web5]
x-compressed-content-length: ['219']
x-content-encoding: [gzip]
x-ratelimit-remaining: ['38']
x-uncompressed-content-length: ['387']
x-via: [fw2.int.opensubtitles.org]
status: {code: 200, message: OK}
version: 1
82 changes: 82 additions & 0 deletions tests/cassettes/opensubtitles/test_login_vip_login.yaml
@@ -0,0 +1,82 @@
interactions:
- request:
body: !!python/unicode '<?xml version=''1.0''?>

<methodCall>

<methodName>LogIn</methodName>

<params>

<param>

<value><string>python-subliminal</string></value>

</param>

<param>

<value><string>subliminal</string></value>

</param>

<param>

<value><string>eng</string></value>

</param>

<param>

<value><string>subliminal v2.1</string></value>

</param>

</params>

</methodCall>

'
headers:
Accept-Encoding: [gzip]
Content-Length: ['344']
Content-Type: [text/xml]
User-Agent: [xmlrpclib.py/1.0.1 (by www.pythonware.com)]
method: POST
uri: https://vip-api.opensubtitles.org/xml-rpc
response:
body:
string: !!binary |
H4sIAAAAAAAAA42QyQrCMBRFf6V0bU2LFhRiRPALHHDYpclTi82LZCji11slFa0uXL3pvsPl0ulV
VVENxpYaJ3HWT+MIUGhZ4nESe3dIRvGUUQXupOUC7EWjBUYv3HBlQ2W05pVvttYZL9xDrQowjCJX
wJw+A1Ly7N+EDZ/NpcyT7Wooq32C+W5uNj2RzcR4uR5QEjSUhB/SUj/o1nHn7W/8MM2iNXLfWDfl
DeTfTBAaZRcqtS8qYGk/zRp3YfomkTaE1yVkRNrMSCfMO7e3JkeDAQAA
headers:
accept-ranges: [bytes]
access-control-allow-headers: ['Origin,X-Requested-With,Content-Type,Accept,DNT,Keep-Alive,User-Agent,If-Modified-Since,Cache-Control']
access-control-allow-methods: ['GET, POST, OPTIONS']
access-control-allow-origin: ['*']
age: ['0']
cf-ray: [4ae2119caddb3eaa-ZRH]
connection: [keep-alive]
content-encoding: [gzip]
content-length: ['213']
content-type: [text/xml;charset=UTF-8]
date: ['Sun, 24 Feb 2019 12:52:20 GMT']
expect-ct: ['max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"']
server: [cloudflare]
set-cookie: ['__cfduid=da5e0dea44f1740bccab1c0a8457a5b7a1551012740; expires=Mon,
24-Feb-20 12:52:20 GMT; path=/; domain=.opensubtitles.org; HttpOnly', 'weblang=en;
expires=Mon, 24-Feb-2020 12:52:20 GMT; Max-Age=31536000; path=/; domain=.opensubtitles.org',
'PHPSESSID=Ddd5-XT4dlZ-n5YDrW%2Cc1Ac9SU3; expires=Sun, 24-Feb-2019 18:52:20
GMT; Max-Age=21600; path=/; domain=.opensubtitles.org; HttpOnly']
vary: [Accept-Encoding]
x-cache: [MISS]
x-cache-backend: [web5]
x-compressed-content-length: ['213']
x-content-encoding: [gzip]
x-ratelimit-remaining: ['39']
x-uncompressed-content-length: ['387']
x-via: [fw2.int.opensubtitles.org]
status: {code: 200, message: OK}
version: 1
7 changes: 5 additions & 2 deletions tests/test_extensions.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pkg_resources import EntryPoint, iter_entry_points

from subliminal.extensions import RegistrableExtensionManager, provider_manager
from subliminal.extensions import RegistrableExtensionManager, provider_manager, default_providers, disabled_providers


def test_registrable_extension_manager_all_extensions():
Expand Down Expand Up @@ -52,4 +52,7 @@ def test_registrable_extension_manager_unregister():
def test_provider_manager():
setup_names = {ep.name for ep in iter_entry_points(provider_manager.namespace)}
internal_names = {EntryPoint.parse(iep).name for iep in provider_manager.internal_extensions}
assert setup_names == internal_names
enabled_names = set(default_providers)
disabled_names = set(disabled_providers)
assert setup_names == enabled_names
assert internal_names == enabled_names | disabled_names
20 changes: 19 additions & 1 deletion tests/test_opensubtitles.py
Expand Up @@ -6,7 +6,9 @@
from vcr import VCR

from subliminal.exceptions import ConfigurationError
from subliminal.providers.opensubtitles import OpenSubtitlesProvider, OpenSubtitlesSubtitle, Unauthorized
from subliminal.providers.opensubtitles import (
OpenSubtitlesProvider, OpenSubtitlesVipProvider, OpenSubtitlesSubtitle, Unauthorized
)


vcr = VCR(path_transformer=lambda path: path + '.yaml',
Expand Down Expand Up @@ -104,6 +106,22 @@ def test_login_bad_password():
provider.initialize()


@pytest.mark.integration
@vcr.use_cassette
def test_login_vip_login():
provider = OpenSubtitlesVipProvider('python-subliminal', 'subliminal')
with pytest.raises(Unauthorized):
provider.initialize()


@pytest.mark.integration
@vcr.use_cassette
def test_login_vip_bad_password():
provider = OpenSubtitlesVipProvider('python-subliminal', 'lanimilbus')
with pytest.raises(Unauthorized):
provider.initialize()


@pytest.mark.integration
@vcr.use_cassette
def test_logout():
Expand Down

0 comments on commit f4f0fdd

Please sign in to comment.