Merge branch 'development' into morpheus

pull/479/head
Louis Vézina 6 years ago
commit 72b933c88b

@ -14,6 +14,9 @@ from config import settings
from check_update import check_releases from check_update import check_releases
from get_args import args from get_args import args
# set subliminal_patch user agent
os.environ["SZ_USER_AGENT"] = "Bazarr/1"
# Check if args.config_dir exist # Check if args.config_dir exist
if not os.path.exists(args.config_dir): if not os.path.exists(args.config_dir):
# Create config_dir directory tree # Create config_dir directory tree

@ -147,7 +147,7 @@ class ArgenteamProvider(Provider, ProviderSubtitleArchiveMixin):
def initialize(self): def initialize(self):
self.session = Session() self.session = Session()
self.session.headers = {'User-Agent': "Bazarr/1"} self.session.headers = {'User-Agent': os.environ.get("SZ_USER_AGENT", "Sub-Zero/2")}
def terminate(self): def terminate(self):
self.session.close() self.session.close()

@ -103,7 +103,7 @@ class AssrtProvider(Provider):
def initialize(self): def initialize(self):
self.session = Session() self.session = Session()
self.session.headers = {'User-Agent': "Bazarr/1"} self.session.headers = {'User-Agent': os.environ.get("SZ_USER_AGENT", "Sub-Zero/2")}
def terminate(self): def terminate(self):
self.session.close() self.session.close()

@ -133,7 +133,7 @@ class HosszupuskaProvider(Provider, ProviderSubtitleArchiveMixin):
def initialize(self): def initialize(self):
self.session = Session() self.session = Session()
self.session.headers = {'User-Agent': "Bazarr/1"} self.session.headers = {'User-Agent': os.environ.get("SZ_USER_AGENT", "Sub-Zero/2")}
def terminate(self): def terminate(self):
self.session.close() self.session.close()

@ -121,7 +121,7 @@ class OpenSubtitlesProvider(ProviderRetryMixin, _OpenSubtitlesProvider):
def get_server_proxy(self, url, timeout=None): def get_server_proxy(self, url, timeout=None):
return ServerProxy(url, SubZeroRequestsTransport(use_https=self.use_ssl, timeout=timeout or self.timeout, return ServerProxy(url, SubZeroRequestsTransport(use_https=self.use_ssl, timeout=timeout or self.timeout,
user_agent="Bazarr/1")) user_agent=os.environ.get("SZ_USER_AGENT", "Sub-Zero/2")))
def log_in(self, server_url=None): def log_in(self, server_url=None):
if server_url: if server_url:
@ -132,7 +132,7 @@ class OpenSubtitlesProvider(ProviderRetryMixin, _OpenSubtitlesProvider):
response = self.retry( response = self.retry(
lambda: checked( lambda: checked(
lambda: self.server.LogIn(self.username, self.password, 'eng', lambda: self.server.LogIn(self.username, self.password, 'eng',
"Bazarr/1") os.environ.get("SZ_USER_AGENT", "Sub-Zero/2"))
) )
) )
@ -296,8 +296,8 @@ class OpenSubtitlesProvider(ProviderRetryMixin, _OpenSubtitlesProvider):
elif not only_foreign and not also_foreign and foreign_parts_only: elif not only_foreign and not also_foreign and foreign_parts_only:
continue continue
# foreign/forced *also* wanted # set subtitle language to forced if it's foreign_parts_only
elif also_foreign and foreign_parts_only: elif (also_foreign or only_foreign) and foreign_parts_only:
language = Language.rebuild(language, forced=True) language = Language.rebuild(language, forced=True)
if language not in languages: if language not in languages:

@ -150,7 +150,7 @@ class SuperSubtitlesProvider(Provider, ProviderSubtitleArchiveMixin):
def initialize(self): def initialize(self):
self.session = Session() self.session = Session()
self.session.headers = {'User-Agent': "Bazarr/1"} self.session.headers = {'User-Agent': os.environ.get("SZ_USER_AGENT", "Sub-Zero/2")}
def terminate(self): def terminate(self):
self.session.close() self.session.close()

@ -4,7 +4,6 @@ import io
import logging import logging
import math import math
import re import re
from random import randint
import rarfile import rarfile
@ -12,7 +11,7 @@ from bs4 import BeautifulSoup
from zipfile import ZipFile, is_zipfile from zipfile import ZipFile, is_zipfile
from rarfile import RarFile, is_rarfile from rarfile import RarFile, is_rarfile
from babelfish import language_converters, Script from babelfish import language_converters, Script
from requests import Session from requests import Session, RequestException
from guessit import guessit from guessit import guessit
from subliminal_patch.providers import Provider from subliminal_patch.providers import Provider
from subliminal_patch.providers.mixins import ProviderSubtitleArchiveMixin from subliminal_patch.providers.mixins import ProviderSubtitleArchiveMixin
@ -25,6 +24,8 @@ from subliminal.subtitle import guess_matches
from subliminal.video import Episode, Movie from subliminal.video import Episode, Movie
from subliminal.subtitle import fix_line_ending from subliminal.subtitle import fix_line_ending
from subzero.language import Language from subzero.language import Language
from random import randint
from .utils import FIRST_THOUSAND_OR_SO_USER_AGENTS as AGENT_LIST from .utils import FIRST_THOUSAND_OR_SO_USER_AGENTS as AGENT_LIST
# parsing regex definitions # parsing regex definitions
@ -136,6 +137,7 @@ class TitloviProvider(Provider, ProviderSubtitleArchiveMixin):
def initialize(self): def initialize(self):
self.session = Session() self.session = Session()
logger.debug("Using random user agents")
self.session.headers['User-Agent'] = AGENT_LIST[randint(0, len(AGENT_LIST) - 1)] self.session.headers['User-Agent'] = AGENT_LIST[randint(0, len(AGENT_LIST) - 1)]
logger.debug('User-Agent set to %s', self.session.headers['User-Agent']) logger.debug('User-Agent set to %s', self.session.headers['User-Agent'])
self.session.headers['Referer'] = self.server_url self.session.headers['Referer'] = self.server_url
@ -179,7 +181,11 @@ class TitloviProvider(Provider, ProviderSubtitleArchiveMixin):
try: try:
r = self.session.get(self.search_url, params=params, timeout=10) r = self.session.get(self.search_url, params=params, timeout=10)
r.raise_for_status() r.raise_for_status()
except RequestException as e:
logger.exception('RequestException %s', e)
break
try:
soup = BeautifulSoup(r.content, 'lxml') soup = BeautifulSoup(r.content, 'lxml')
# number of results # number of results

Loading…
Cancel
Save