From 1c7584d33a5f928abba7805e74fcd5163ab90454 Mon Sep 17 00:00:00 2001 From: vitiko98 Date: Fri, 25 Jun 2021 19:10:41 -0400 Subject: [PATCH] Solve SSL error with Podnapisi on Ubuntu and Debian machines (Fix #1251) --- libs/subliminal_patch/providers/podnapisi.py | 24 +++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/libs/subliminal_patch/providers/podnapisi.py b/libs/subliminal_patch/providers/podnapisi.py index 6f384bf62..2044228c5 100644 --- a/libs/subliminal_patch/providers/podnapisi.py +++ b/libs/subliminal_patch/providers/podnapisi.py @@ -2,12 +2,19 @@ from __future__ import absolute_import import logging -import re import io +import re +import ssl + +from urllib3 import poolmanager from zipfile import ZipFile from guessit import guessit + +from requests import Session +from requests.adapters import HTTPAdapter + from subliminal.utils import sanitize from subliminal_patch.subtitle import guess_matches from subliminal_patch.providers.mixins import ProviderSubtitleArchiveMixin @@ -102,6 +109,17 @@ class PodnapisiSubtitle(_PodnapisiSubtitle): return matches +class PodnapisiAdapter(HTTPAdapter): + def init_poolmanager(self, connections, maxsize, block=False): + ctx = ssl.create_default_context() + ctx.set_ciphers('DEFAULT@SECLEVEL=1') + self.poolmanager = poolmanager.PoolManager( + num_pools=connections, + maxsize=maxsize, + block=block, + ssl_version=ssl.PROTOCOL_TLS, + ssl_context=ctx + ) class PodnapisiProvider(_PodnapisiProvider, ProviderSubtitleArchiveMixin): languages = ({Language('por', 'BR'), Language('srp', script='Latn'), Language('srp', script='Cyrl')} | @@ -124,6 +142,10 @@ class PodnapisiProvider(_PodnapisiProvider, ProviderSubtitleArchiveMixin): super(PodnapisiProvider, self).__init__() + def initialize(self): + super().initialize() + self.session.mount('https://', PodnapisiAdapter()) + def list_subtitles(self, video, languages): if video.is_special: logger.info("%s can't search for specials right now, skipping", self)