diff --git a/libs/subliminal_patch/providers/argenteam.py b/libs/subliminal_patch/providers/argenteam.py index 5220a50b9..6a2c7aec8 100644 --- a/libs/subliminal_patch/providers/argenteam.py +++ b/libs/subliminal_patch/providers/argenteam.py @@ -147,7 +147,7 @@ class ArgenteamProvider(Provider, ProviderSubtitleArchiveMixin): def initialize(self): 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): self.session.close() diff --git a/libs/subliminal_patch/providers/assrt.py b/libs/subliminal_patch/providers/assrt.py index eec57f12a..67300dd0b 100644 --- a/libs/subliminal_patch/providers/assrt.py +++ b/libs/subliminal_patch/providers/assrt.py @@ -103,7 +103,7 @@ class AssrtProvider(Provider): def initialize(self): 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): self.session.close() diff --git a/libs/subliminal_patch/providers/hosszupuska.py b/libs/subliminal_patch/providers/hosszupuska.py index ab3c4f608..186fb06d7 100644 --- a/libs/subliminal_patch/providers/hosszupuska.py +++ b/libs/subliminal_patch/providers/hosszupuska.py @@ -133,7 +133,7 @@ class HosszupuskaProvider(Provider, ProviderSubtitleArchiveMixin): def initialize(self): 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): self.session.close() diff --git a/libs/subliminal_patch/providers/opensubtitles.py b/libs/subliminal_patch/providers/opensubtitles.py index f9fa8c080..032b89058 100644 --- a/libs/subliminal_patch/providers/opensubtitles.py +++ b/libs/subliminal_patch/providers/opensubtitles.py @@ -121,7 +121,7 @@ class OpenSubtitlesProvider(ProviderRetryMixin, _OpenSubtitlesProvider): def get_server_proxy(self, url, timeout=None): 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): if server_url: @@ -132,7 +132,7 @@ class OpenSubtitlesProvider(ProviderRetryMixin, _OpenSubtitlesProvider): response = self.retry( lambda: checked( 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: continue - # foreign/forced *also* wanted - elif also_foreign and foreign_parts_only: + # set subtitle language to forced if it's foreign_parts_only + elif (also_foreign or only_foreign) and foreign_parts_only: language = Language.rebuild(language, forced=True) if language not in languages: diff --git a/libs/subliminal_patch/providers/supersubtitles.py b/libs/subliminal_patch/providers/supersubtitles.py index 7af3f0e0e..97c841103 100644 --- a/libs/subliminal_patch/providers/supersubtitles.py +++ b/libs/subliminal_patch/providers/supersubtitles.py @@ -150,7 +150,7 @@ class SuperSubtitlesProvider(Provider, ProviderSubtitleArchiveMixin): def initialize(self): 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): self.session.close() diff --git a/libs/subliminal_patch/providers/titlovi.py b/libs/subliminal_patch/providers/titlovi.py index 8639cf6d9..ec339fef8 100644 --- a/libs/subliminal_patch/providers/titlovi.py +++ b/libs/subliminal_patch/providers/titlovi.py @@ -4,7 +4,6 @@ import io import logging import math import re -from random import randint import rarfile @@ -12,7 +11,7 @@ from bs4 import BeautifulSoup from zipfile import ZipFile, is_zipfile from rarfile import RarFile, is_rarfile from babelfish import language_converters, Script -from requests import Session +from requests import Session, RequestException from guessit import guessit from subliminal_patch.providers import Provider 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.subtitle import fix_line_ending from subzero.language import Language + +from random import randint from .utils import FIRST_THOUSAND_OR_SO_USER_AGENTS as AGENT_LIST # parsing regex definitions @@ -136,6 +137,7 @@ class TitloviProvider(Provider, ProviderSubtitleArchiveMixin): def initialize(self): self.session = Session() + logger.debug("Using random user agents") 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']) self.session.headers['Referer'] = self.server_url @@ -179,7 +181,11 @@ class TitloviProvider(Provider, ProviderSubtitleArchiveMixin): try: r = self.session.get(self.search_url, params=params, timeout=10) r.raise_for_status() + except RequestException as e: + logger.exception('RequestException %s', e) + break + try: soup = BeautifulSoup(r.content, 'lxml') # number of results @@ -224,7 +230,7 @@ class TitloviProvider(Provider, ProviderSubtitleArchiveMixin): if match: try: # decode language - lang = Language.fromtitlovi(match.group('lang') + match.group('script')) + lang = Language.fromtitlovi(match.group('lang')+match.group('script')) except ValueError: continue