|
|
@ -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
|
|
|
@ -224,7 +230,7 @@ class TitloviProvider(Provider, ProviderSubtitleArchiveMixin):
|
|
|
|
if match:
|
|
|
|
if match:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
# decode language
|
|
|
|
# decode language
|
|
|
|
lang = Language.fromtitlovi(match.group('lang') + match.group('script'))
|
|
|
|
lang = Language.fromtitlovi(match.group('lang')+match.group('script'))
|
|
|
|
except ValueError:
|
|
|
|
except ValueError:
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|