Small fix for sous-titres.eu to circumvent Cloudflare protection.

pull/1038/head
Louis Vézina 4 years ago
parent c3dcf766b3
commit 37b5ad4e26

@ -4,13 +4,12 @@ import io
import os import os
import logging import logging
from urllib.parse import unquote from urllib.parse import unquote
from random import randint
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 guessit import guessit from guessit import guessit
from requests import Session import cloudscraper
import chardet import chardet
from bs4 import NavigableString, UnicodeDammit from bs4 import NavigableString, UnicodeDammit
from subzero.language import Language from subzero.language import Language
@ -43,6 +42,7 @@ class SoustitreseuSubtitle(Subtitle):
self.content = content self.content = content
self.hearing_impaired = None self.hearing_impaired = None
self.is_perfect_match = is_perfect_match self.is_perfect_match = is_perfect_match
self._guessed_encoding = None
@property @property
def id(self): def id(self):
@ -110,8 +110,7 @@ class SoustitreseuProvider(Provider, ProviderSubtitleArchiveMixin):
self.is_perfect_match = False self.is_perfect_match = False
def initialize(self): def initialize(self):
self.session = Session() self.session = cloudscraper.create_scraper(debug=False)
self.session.headers['User-Agent'] = AGENT_LIST[randint(0, len(AGENT_LIST) - 1)]
self.session.headers['Referer'] = self.server_url self.session.headers['Referer'] = self.server_url
def terminate(self): def terminate(self):
@ -226,18 +225,13 @@ class SoustitreseuProvider(Provider, ProviderSubtitleArchiveMixin):
return subtitles return subtitles
def list_subtitles(self, video, languages): def list_subtitles(self, video, languages):
if isinstance(video, Episode):
titles = [video.series] + video.alternative_series
else:
titles = [video.title] + video.alternative_titles
subtitles = [] subtitles = []
# query for subtitles # query for subtitles
for title in titles: if isinstance(video, Episode):
if isinstance(video, Episode): subtitles += [s for s in self.query_series(video, video.series) if s.language in languages]
subtitles += [s for s in self.query_series(video, title) if s.language in languages] else:
else: subtitles += [s for s in self.query_movies(video, video.title) if s.language in languages]
subtitles += [s for s in self.query_movies(video, title) if s.language in languages]
return subtitles return subtitles

Loading…
Cancel
Save