From 0995df6c7d11102155170063257da4ea6ba59a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Thu, 20 Jun 2019 21:34:14 -0400 Subject: [PATCH] Fix for #436 and #459. --- bazarr/config.py | 4 + bazarr/get_providers.py | 7 +- bazarr/main.py | 4 + libs/subliminal_patch/providers/subscene.py | 109 +++++++++++++++++--- views/providers.tpl | 26 ++++- 5 files changed, 129 insertions(+), 21 deletions(-) diff --git a/bazarr/config.py b/bazarr/config.py index d11c5c205..66515e5aa 100644 --- a/bazarr/config.py +++ b/bazarr/config.py @@ -115,6 +115,10 @@ defaults = { 'napisy24': { 'username': '', 'password': '' + }, + 'subscene': { + 'username': '', + 'password': '' } } diff --git a/bazarr/get_providers.py b/bazarr/get_providers.py index c87c38674..93d3faec0 100644 --- a/bazarr/get_providers.py +++ b/bazarr/get_providers.py @@ -100,9 +100,10 @@ def get_providers_auth(): 'only_foreign': False, # fixme 'also_foreign': False, # fixme }, - 'subscene': { - 'only_foreign': False, # fixme - }, + 'subscene': {'username': settings.subscene.username, + 'password': settings.subscene.password, + 'only_foreign': False, # fixme + }, 'legendastv': {'username': settings.legendastv.username, 'password': settings.legendastv.password, }, diff --git a/bazarr/main.py b/bazarr/main.py index 0f92f5fdc..4b73915ee 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -395,6 +395,8 @@ def save_wizard(): settings.xsubs.password = request.forms.get('settings_xsubs_password') settings.napisy24.username = request.forms.get('settings_napisy24_username') settings.napisy24.password = request.forms.get('settings_napisy24_password') + settings.subscene.username = request.forms.get('settings_subscene_username') + settings.subscene.password = request.forms.get('settings_subscene_password') settings_subliminal_languages = request.forms.getall('settings_subliminal_languages') c.execute("UPDATE table_settings_languages SET enabled = 0") @@ -1526,6 +1528,8 @@ def save_settings(): settings.xsubs.password = request.forms.get('settings_xsubs_password') settings.napisy24.username = request.forms.get('settings_napisy24_username') settings.napisy24.password = request.forms.get('settings_napisy24_password') + settings.subscene.username = request.forms.get('settings_subscene_username') + settings.subscene.password = request.forms.get('settings_subscene_password') settings_subliminal_languages = request.forms.getall('settings_subliminal_languages') c.execute("UPDATE table_settings_languages SET enabled = 0") diff --git a/libs/subliminal_patch/providers/subscene.py b/libs/subliminal_patch/providers/subscene.py index 098447ad5..a5cab3fd8 100644 --- a/libs/subliminal_patch/providers/subscene.py +++ b/libs/subliminal_patch/providers/subscene.py @@ -4,24 +4,34 @@ import io import logging import os import time +import traceback + +import requests + import inflect +import re +import json +import HTMLParser +import urlparse from zipfile import ZipFile from babelfish import language_converters from guessit import guessit +from dogpile.cache.api import NO_VALUE from subliminal import Episode, ProviderError +from subliminal.exceptions import ConfigurationError from subliminal.utils import sanitize_release_group +from subliminal.cache import region from subliminal_patch.http import RetryingCFSession from subliminal_patch.providers import Provider from subliminal_patch.providers.mixins import ProviderSubtitleArchiveMixin from subliminal_patch.subtitle import Subtitle, guess_matches from subliminal_patch.converters.subscene import language_ids, supported_languages -from subscene_api.subscene import search, Subtitle as APISubtitle +from subscene_api.subscene import search, Subtitle as APISubtitle, SITE_DOMAIN from subzero.language import Language p = inflect.engine() - language_converters.register('subscene = subliminal_patch.converters.subscene:SubsceneConverter') logger = logging.getLogger(__name__) @@ -112,16 +122,67 @@ class SubsceneProvider(Provider, ProviderSubtitleArchiveMixin): skip_wrong_fps = False hearing_impaired_verifiable = True only_foreign = False + username = None + password = None - search_throttle = 2 # seconds + search_throttle = 5 # seconds + + def __init__(self, only_foreign=False, username=None, password=None): + if not all((username, password)): + raise ConfigurationError('Username and password must be specified') - def __init__(self, only_foreign=False): self.only_foreign = only_foreign + self.username = username + self.password = password def initialize(self): logger.info("Creating session") self.session = RetryingCFSession() + def login(self): + r = self.session.get("https://subscene.com/account/login") + match = re.search(r"", r.content) + + if match: + h = HTMLParser.HTMLParser() + data = json.loads(h.unescape(match.group(1))) + login_url = urlparse.urljoin(data["siteUrl"], data["loginUrl"]) + time.sleep(1.0) + + r = self.session.post(login_url, + { + "username": self.username, + "password": self.password, + data["antiForgery"]["name"]: data["antiForgery"]["value"] + }) + pep_content = re.search(r"