# Conflicts: # bazarr/get_providers.py # libs/subliminal_patch/providers/titrari.pypull/835/head v0.8.4.1
commit
f81f7ed27c
@ -0,0 +1,235 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
import logging
|
||||
import io
|
||||
import os
|
||||
|
||||
from requests import Session
|
||||
from guessit import guessit
|
||||
from subliminal_patch.providers import Provider
|
||||
from subliminal_patch.subtitle import Subtitle
|
||||
from subliminal.utils import sanitize_release_group
|
||||
from subliminal.subtitle import guess_matches
|
||||
from subzero.language import Language
|
||||
|
||||
import gzip
|
||||
import random
|
||||
from time import sleep
|
||||
from xml.etree import ElementTree
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class BSPlayerSubtitle(Subtitle):
|
||||
"""BSPlayer Subtitle."""
|
||||
provider_name = 'bsplayer'
|
||||
|
||||
def __init__(self, language, filename, subtype, video, link):
|
||||
super(BSPlayerSubtitle, self).__init__(language)
|
||||
self.language = language
|
||||
self.filename = filename
|
||||
self.page_link = link
|
||||
self.subtype = subtype
|
||||
self.video = video
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.page_link
|
||||
|
||||
@property
|
||||
def release_info(self):
|
||||
return self.filename
|
||||
|
||||
def get_matches(self, video):
|
||||
matches = set()
|
||||
|
||||
video_filename = video.name
|
||||
video_filename = os.path.basename(video_filename)
|
||||
video_filename, _ = os.path.splitext(video_filename)
|
||||
video_filename = sanitize_release_group(video_filename)
|
||||
|
||||
subtitle_filename = self.filename
|
||||
subtitle_filename = os.path.basename(subtitle_filename)
|
||||
subtitle_filename, _ = os.path.splitext(subtitle_filename)
|
||||
subtitle_filename = sanitize_release_group(subtitle_filename)
|
||||
|
||||
|
||||
matches |= guess_matches(video, guessit(self.filename))
|
||||
|
||||
matches.add(id(self))
|
||||
matches.add('hash')
|
||||
|
||||
return matches
|
||||
|
||||
|
||||
|
||||
class BSPlayerProvider(Provider):
|
||||
"""BSPlayer Provider."""
|
||||
languages = {Language('por', 'BR')} | {Language(l) for l in [
|
||||
'ara', 'bul', 'ces', 'dan', 'deu', 'ell', 'eng', 'fin', 'fra', 'hun', 'ita', 'jpn', 'kor', 'nld', 'pol', 'por',
|
||||
'ron', 'rus', 'spa', 'swe', 'tur', 'ukr', 'zho'
|
||||
]}
|
||||
SEARCH_THROTTLE = 8
|
||||
|
||||
# batantly based on kodi's bsplayer plugin
|
||||
# also took from BSPlayer-Subtitles-Downloader
|
||||
def __init__(self):
|
||||
self.initialize()
|
||||
|
||||
def initialize(self):
|
||||
self.session = Session()
|
||||
self.search_url = self.get_sub_domain()
|
||||
self.token = None
|
||||
self.login()
|
||||
|
||||
def terminate(self):
|
||||
self.session.close()
|
||||
self.logout()
|
||||
|
||||
def api_request(self, func_name='logIn', params='', tries=5):
|
||||
headers = {
|
||||
'User-Agent': 'BSPlayer/2.x (1022.12360)',
|
||||
'Content-Type': 'text/xml; charset=utf-8',
|
||||
'Connection': 'close',
|
||||
'SOAPAction': '"http://api.bsplayer-subtitles.com/v1.php#{func_name}"'.format(func_name=func_name)
|
||||
}
|
||||
data = (
|
||||
'<?xml version="1.0" encoding="UTF-8"?>\n'
|
||||
'<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
|
||||
'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
|
||||
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
|
||||
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="{search_url}">'
|
||||
'<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
|
||||
'<ns1:{func_name}>{params}</ns1:{func_name}></SOAP-ENV:Body></SOAP-ENV:Envelope>'
|
||||
).format(search_url=self.search_url, func_name=func_name, params=params)
|
||||
logger.info('Sending request: %s.' % func_name)
|
||||
for i in iter(range(tries)):
|
||||
try:
|
||||
self.session.headers.update(headers.items())
|
||||
res = self.session.post(self.search_url, data)
|
||||
return ElementTree.fromstring(res.text)
|
||||
|
||||
### with requests
|
||||
# res = requests.post(
|
||||
# url=self.search_url,
|
||||
# data=data,
|
||||
# headers=headers
|
||||
# )
|
||||
# return ElementTree.fromstring(res.text)
|
||||
|
||||
except Exception as ex:
|
||||
logger.info("ERROR: %s." % ex)
|
||||
if func_name == 'logIn':
|
||||
self.search_url = self.get_sub_domain()
|
||||
sleep(1)
|
||||
logger.info('ERROR: Too many tries (%d)...' % tries)
|
||||
raise Exception('Too many tries...')
|
||||
|
||||
def login(self):
|
||||
# If already logged in
|
||||
if self.token:
|
||||
return True
|
||||
|
||||
root = self.api_request(
|
||||
func_name='logIn',
|
||||
params=('<username></username>'
|
||||
'<password></password>'
|
||||
'<AppID>BSPlayer v2.67</AppID>')
|
||||
)
|
||||
res = root.find('.//return')
|
||||
if res.find('status').text == 'OK':
|
||||
self.token = res.find('data').text
|
||||
logger.info("Logged In Successfully.")
|
||||
return True
|
||||
return False
|
||||
|
||||
def logout(self):
|
||||
# If already logged out / not logged in
|
||||
if not self.token:
|
||||
return True
|
||||
|
||||
root = self.api_request(
|
||||
func_name='logOut',
|
||||
params='<handle>{token}</handle>'.format(token=self.token)
|
||||
)
|
||||
res = root.find('.//return')
|
||||
self.token = None
|
||||
if res.find('status').text == 'OK':
|
||||
logger.info("Logged Out Successfully.")
|
||||
return True
|
||||
return False
|
||||
|
||||
def query(self, video, video_hash, language):
|
||||
if not self.login():
|
||||
return []
|
||||
|
||||
if isinstance(language, (tuple, list, set)):
|
||||
# language_ids = ",".join(language)
|
||||
# language_ids = 'spa'
|
||||
language_ids = ','.join(sorted(l.opensubtitles for l in language))
|
||||
|
||||
|
||||
if video.imdb_id is None:
|
||||
imdbId = '*'
|
||||
else:
|
||||
imdbId = video.imdb_id
|
||||
sleep(self.SEARCH_THROTTLE)
|
||||
root = self.api_request(
|
||||
func_name='searchSubtitles',
|
||||
params=(
|
||||
'<handle>{token}</handle>'
|
||||
'<movieHash>{movie_hash}</movieHash>'
|
||||
'<movieSize>{movie_size}</movieSize>'
|
||||
'<languageId>{language_ids}</languageId>'
|
||||
'<imdbId>{imdbId}</imdbId>'
|
||||
).format(token=self.token, movie_hash=video_hash,
|
||||
movie_size=video.size, language_ids=language_ids, imdbId=imdbId)
|
||||
)
|
||||
res = root.find('.//return/result')
|
||||
if res.find('status').text != 'OK':
|
||||
return []
|
||||
|
||||
items = root.findall('.//return/data/item')
|
||||
subtitles = []
|
||||
if items:
|
||||
logger.info("Subtitles Found.")
|
||||
for item in items:
|
||||
subID=item.find('subID').text
|
||||
subDownloadLink=item.find('subDownloadLink').text
|
||||
subLang= Language.fromopensubtitles(item.find('subLang').text)
|
||||
subName=item.find('subName').text
|
||||
subFormat=item.find('subFormat').text
|
||||
subtitles.append(
|
||||
BSPlayerSubtitle(subLang,subName, subFormat, video, subDownloadLink)
|
||||
)
|
||||
return subtitles
|
||||
|
||||
def list_subtitles(self, video, languages):
|
||||
return self.query(video, video.hashes['bsplayer'], languages)
|
||||
|
||||
def get_sub_domain(self):
|
||||
# s1-9, s101-109
|
||||
SUB_DOMAINS = ['s1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9',
|
||||
's101', 's102', 's103', 's104', 's105', 's106', 's107', 's108', 's109']
|
||||
API_URL_TEMPLATE = "http://{sub_domain}.api.bsplayer-subtitles.com/v1.php"
|
||||
sub_domains_end = len(SUB_DOMAINS) - 1
|
||||
return API_URL_TEMPLATE.format(sub_domain=SUB_DOMAINS[random.randint(0, sub_domains_end)])
|
||||
|
||||
def download_subtitle(self, subtitle):
|
||||
session = Session()
|
||||
_addheaders = {
|
||||
'User-Agent': 'Mozilla/4.0 (compatible; Synapse)'
|
||||
}
|
||||
session.headers.update(_addheaders)
|
||||
res = session.get(subtitle.page_link)
|
||||
if res:
|
||||
if res.text == '500':
|
||||
raise ValueError('Error 500 on server')
|
||||
|
||||
with gzip.GzipFile(fileobj=io.BytesIO(res.content)) as gf:
|
||||
subtitle.content = gf.read()
|
||||
subtitle.normalize()
|
||||
|
||||
return subtitle
|
||||
raise ValueError('Problems conecting to the server')
|
||||
|
||||
|
@ -0,0 +1,307 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
import logging
|
||||
import io
|
||||
import os
|
||||
import rarfile
|
||||
import zipfile
|
||||
|
||||
from requests import Session
|
||||
from guessit import guessit
|
||||
from subliminal_patch.exceptions import ParseResponseError
|
||||
from subliminal_patch.providers import Provider
|
||||
from subliminal.providers import ParserBeautifulSoup
|
||||
from subliminal_patch.subtitle import Subtitle
|
||||
from subliminal.video import Episode
|
||||
from subliminal.subtitle import SUBTITLE_EXTENSIONS, fix_line_ending,guess_matches
|
||||
from subzero.language import Language
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class LegendasdivxSubtitle(Subtitle):
|
||||
"""Legendasdivx Subtitle."""
|
||||
provider_name = 'legendasdivx'
|
||||
|
||||
def __init__(self, language, video, data):
|
||||
super(LegendasdivxSubtitle, self).__init__(language)
|
||||
self.language = language
|
||||
self.page_link = data['link']
|
||||
self.hits=data['hits']
|
||||
self.exact_match=data['exact_match']
|
||||
self.description=data['description'].lower()
|
||||
self.video = video
|
||||
self.videoname =data['videoname']
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.page_link
|
||||
|
||||
@property
|
||||
def release_info(self):
|
||||
return self.description
|
||||
|
||||
def get_matches(self, video):
|
||||
matches = set()
|
||||
|
||||
if self.videoname.lower() in self.description:
|
||||
matches.update(['title'])
|
||||
matches.update(['season'])
|
||||
matches.update(['episode'])
|
||||
|
||||
# episode
|
||||
if video.title and video.title.lower() in self.description:
|
||||
matches.update(['title'])
|
||||
if video.year and '{:04d}'.format(video.year) in self.description:
|
||||
matches.update(['year'])
|
||||
|
||||
if isinstance(video, Episode):
|
||||
# already matched in search query
|
||||
if video.season and 's{:02d}'.format(video.season) in self.description:
|
||||
matches.update(['season'])
|
||||
if video.episode and 'e{:02d}'.format(video.episode) in self.description:
|
||||
matches.update(['episode'])
|
||||
if video.episode and video.season and video.series:
|
||||
if '{}.s{:02d}e{:02d}'.format(video.series.lower(),video.season,video.episode) in self.description:
|
||||
matches.update(['series'])
|
||||
matches.update(['season'])
|
||||
matches.update(['episode'])
|
||||
if '{} s{:02d}e{:02d}'.format(video.series.lower(),video.season,video.episode) in self.description:
|
||||
matches.update(['series'])
|
||||
matches.update(['season'])
|
||||
matches.update(['episode'])
|
||||
|
||||
# release_group
|
||||
if video.release_group and video.release_group.lower() in self.description:
|
||||
matches.update(['release_group'])
|
||||
|
||||
# resolution
|
||||
|
||||
if video.resolution and video.resolution.lower() in self.description:
|
||||
matches.update(['resolution'])
|
||||
|
||||
# format
|
||||
formats = []
|
||||
if video.format:
|
||||
formats = [video.format.lower()]
|
||||
if formats[0] == "web-dl":
|
||||
formats.append("webdl")
|
||||
formats.append("webrip")
|
||||
formats.append("web ")
|
||||
for frmt in formats:
|
||||
if frmt.lower() in self.description:
|
||||
matches.update(['format'])
|
||||
break
|
||||
|
||||
# video_codec
|
||||
if video.video_codec:
|
||||
video_codecs = [video.video_codec.lower()]
|
||||
if video_codecs[0] == "h264":
|
||||
formats.append("x264")
|
||||
elif video_codecs[0] == "h265":
|
||||
formats.append("x265")
|
||||
for vc in formats:
|
||||
if vc.lower() in self.description:
|
||||
matches.update(['video_codec'])
|
||||
break
|
||||
|
||||
matches |= guess_matches(video, guessit(self.description))
|
||||
return matches
|
||||
|
||||
|
||||
|
||||
|
||||
class LegendasdivxProvider(Provider):
|
||||
"""Legendasdivx Provider."""
|
||||
languages = {Language('por', 'BR')} | {Language('por')}
|
||||
SEARCH_THROTTLE = 8
|
||||
site = 'https://www.legendasdivx.pt'
|
||||
headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0',
|
||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
|
||||
'Origin': 'https://www.legendasdivx.pt',
|
||||
'Referer': 'https://www.legendasdivx.pt',
|
||||
'Pragma': 'no-cache',
|
||||
'Cache-Control': 'no-cache'
|
||||
}
|
||||
loginpage = site + '/forum/ucp.php?mode=login'
|
||||
searchurl = site + '/modules.php?name=Downloads&file=jz&d_op=search&op=_jz00&query={query}'
|
||||
language_list = list(languages)
|
||||
|
||||
|
||||
def __init__(self, username, password):
|
||||
self.username = username
|
||||
self.password = password
|
||||
|
||||
def initialize(self):
|
||||
self.session = Session()
|
||||
self.login()
|
||||
|
||||
def terminate(self):
|
||||
self.logout()
|
||||
self.session.close()
|
||||
|
||||
def login(self):
|
||||
logger.info('Logging in')
|
||||
self.headers['Referer'] = self.site + '/index.php'
|
||||
self.session.headers.update(self.headers.items())
|
||||
res = self.session.get(self.loginpage)
|
||||
bsoup = ParserBeautifulSoup(res.content, ['lxml'])
|
||||
|
||||
_allinputs = bsoup.findAll('input')
|
||||
fields = {}
|
||||
for field in _allinputs:
|
||||
fields[field.get('name')] = field.get('value')
|
||||
|
||||
fields['username'] = self.username
|
||||
fields['password'] = self.password
|
||||
fields['autologin'] = 'on'
|
||||
fields['viewonline'] = 'on'
|
||||
|
||||
self.headers['Referer'] = self.loginpage
|
||||
self.session.headers.update(self.headers.items())
|
||||
res = self.session.post(self.loginpage, fields)
|
||||
try:
|
||||
logger.debug('Got session id %s' %
|
||||
self.session.cookies.get_dict()['PHPSESSID'])
|
||||
except KeyError as e:
|
||||
logger.error(repr(e))
|
||||
logger.error("Didn't get session id, check your credentials")
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(repr(e))
|
||||
logger.error('uncached error #legendasdivx #AA')
|
||||
return False
|
||||
|
||||
return True
|
||||
def logout(self):
|
||||
# need to figure this out
|
||||
return True
|
||||
|
||||
def query(self, video, language):
|
||||
try:
|
||||
logger.debug('Got session id %s' %
|
||||
self.session.cookies.get_dict()['PHPSESSID'])
|
||||
except Exception as e:
|
||||
self.login()
|
||||
return []
|
||||
|
||||
language_ids = '0'
|
||||
if isinstance(language, (tuple, list, set)):
|
||||
if len(language) == 1:
|
||||
language_ids = ','.join(sorted(l.opensubtitles for l in language))
|
||||
if language_ids == 'por':
|
||||
language_ids = '&form_cat=28'
|
||||
else:
|
||||
language_ids = '&form_cat=29'
|
||||
|
||||
querytext = video.name
|
||||
querytext = os.path.basename(querytext)
|
||||
querytext, _ = os.path.splitext(querytext)
|
||||
videoname = querytext
|
||||
querytext = querytext.lower()
|
||||
querytext = querytext.replace(
|
||||
".", "+").replace("[", "").replace("]", "")
|
||||
if language_ids != '0':
|
||||
querytext = querytext + language_ids
|
||||
self.headers['Referer'] = self.site + '/index.php'
|
||||
self.session.headers.update(self.headers.items())
|
||||
res = self.session.get(self.searchurl.format(query=querytext))
|
||||
# form_cat=28 = br
|
||||
# form_cat=29 = pt
|
||||
if "A legenda não foi encontrada" in res.text:
|
||||
logger.warning('%s not found', querytext)
|
||||
return []
|
||||
|
||||
bsoup = ParserBeautifulSoup(res.content, ['html.parser'])
|
||||
_allsubs = bsoup.findAll("div", {"class": "sub_box"})
|
||||
subtitles = []
|
||||
lang = Language.fromopensubtitles("pob")
|
||||
for _subbox in _allsubs:
|
||||
hits=0
|
||||
for th in _subbox.findAll("th", {"class": "color2"}):
|
||||
if th.string == 'Hits:':
|
||||
hits = int(th.parent.find("td").string)
|
||||
if th.string == 'Idioma:':
|
||||
lang = th.parent.find("td").find ("img").get ('src')
|
||||
if 'brazil' in lang:
|
||||
lang = Language.fromopensubtitles('pob')
|
||||
else:
|
||||
lang = Language.fromopensubtitles('por')
|
||||
|
||||
|
||||
description = _subbox.find("td", {"class": "td_desc brd_up"})
|
||||
download = _subbox.find("a", {"class": "sub_download"})
|
||||
try:
|
||||
# sometimes BSoup just doesn't get the link
|
||||
logger.debug(download.get('href'))
|
||||
except Exception as e:
|
||||
logger.warning('skipping subbox on %s' % self.searchurl.format(query=querytext))
|
||||
continue
|
||||
|
||||
exact_match = False
|
||||
if video.name.lower() in description.get_text().lower():
|
||||
exact_match = True
|
||||
data = {'link': self.site + '/modules.php' + download.get('href'),
|
||||
'exact_match': exact_match,
|
||||
'hits': hits,
|
||||
'videoname': videoname,
|
||||
'description': description.get_text() }
|
||||
subtitles.append(
|
||||
LegendasdivxSubtitle(lang, video, data)
|
||||
)
|
||||
|
||||
return subtitles
|
||||
|
||||
def list_subtitles(self, video, languages):
|
||||
return self.query(video, languages)
|
||||
|
||||
def download_subtitle(self, subtitle):
|
||||
res = self.session.get(subtitle.page_link)
|
||||
if res:
|
||||
if res.text == '500':
|
||||
raise ValueError('Error 500 on server')
|
||||
|
||||
archive = self._get_archive(res.content)
|
||||
# extract the subtitle
|
||||
subtitle_content = self._get_subtitle_from_archive(archive)
|
||||
subtitle.content = fix_line_ending(subtitle_content)
|
||||
subtitle.normalize()
|
||||
|
||||
return subtitle
|
||||
raise ValueError('Problems conecting to the server')
|
||||
|
||||
def _get_archive(self, content):
|
||||
# open the archive
|
||||
# stole^H^H^H^H^H inspired from subvix provider
|
||||
archive_stream = io.BytesIO(content)
|
||||
if rarfile.is_rarfile(archive_stream):
|
||||
logger.debug('Identified rar archive')
|
||||
archive = rarfile.RarFile(archive_stream)
|
||||
elif zipfile.is_zipfile(archive_stream):
|
||||
logger.debug('Identified zip archive')
|
||||
archive = zipfile.ZipFile(archive_stream)
|
||||
else:
|
||||
# raise ParseResponseError('Unsupported compressed format')
|
||||
raise Exception('Unsupported compressed format')
|
||||
|
||||
return archive
|
||||
|
||||
def _get_subtitle_from_archive(self, archive):
|
||||
# some files have a non subtitle with .txt extension
|
||||
_tmp = list(SUBTITLE_EXTENSIONS)
|
||||
_tmp.remove('.txt')
|
||||
_subtitle_extensions = tuple(_tmp)
|
||||
|
||||
for name in archive.namelist():
|
||||
# discard hidden files
|
||||
if os.path.split(name)[-1].startswith('.'):
|
||||
continue
|
||||
|
||||
# discard non-subtitle files
|
||||
if not name.lower().endswith(_subtitle_extensions):
|
||||
continue
|
||||
|
||||
logger.debug("returning from archive: %s" % name)
|
||||
return archive.read(name)
|
||||
|
||||
raise ParseResponseError('Can not find the subtitle in the compressed file')
|
@ -0,0 +1,229 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import absolute_import
|
||||
import io
|
||||
import logging
|
||||
import re
|
||||
from subliminal import __short_version__
|
||||
import rarfile
|
||||
|
||||
from zipfile import ZipFile, is_zipfile
|
||||
from rarfile import RarFile, is_rarfile
|
||||
from subliminal_patch.providers import Provider
|
||||
from subliminal_patch.providers.mixins import ProviderSubtitleArchiveMixin
|
||||
from subliminal_patch.subtitle import Subtitle
|
||||
from subliminal_patch.utils import sanitize, fix_inconsistent_naming as _fix_inconsistent_naming
|
||||
from subliminal.exceptions import ProviderError
|
||||
from subliminal.providers import ParserBeautifulSoup
|
||||
from subliminal.video import Episode, Movie
|
||||
from subzero.language import Language
|
||||
|
||||
# parsing regex definitions
|
||||
title_re = re.compile(r'(?P<title>(?:.+(?= [Aa][Kk][Aa] ))|.+)(?:(?:.+)(?P<altitle>(?<= [Aa][Kk][Aa] ).+))?')
|
||||
|
||||
|
||||
def fix_inconsistent_naming(title):
|
||||
"""Fix titles with inconsistent naming using dictionary and sanitize them.
|
||||
|
||||
:param str title: original title.
|
||||
:return: new title.
|
||||
:rtype: str
|
||||
|
||||
"""
|
||||
return _fix_inconsistent_naming(title, {"DC's Legends of Tomorrow": "Legends of Tomorrow",
|
||||
"Marvel's Jessica Jones": "Jessica Jones"})
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Configure :mod:`rarfile` to use the same path separator as :mod:`zipfile`
|
||||
rarfile.PATH_SEP = '/'
|
||||
|
||||
class TitrariSubtitle(Subtitle):
|
||||
|
||||
provider_name = 'titrari'
|
||||
|
||||
def __init__(self, language, download_link, sid, releases, title, imdb_id, year=None, download_count=None, comments=None):
|
||||
super(TitrariSubtitle, self).__init__(language)
|
||||
self.sid = sid
|
||||
self.title = title
|
||||
self.imdb_id = imdb_id
|
||||
self.download_link = download_link
|
||||
self.year = year
|
||||
self.download_count = download_count
|
||||
self.releases = self.release_info = releases
|
||||
self.comments = comments
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.sid
|
||||
|
||||
def __str__(self):
|
||||
return self.title + "(" + str(self.year) + ")" + " -> " + self.download_link
|
||||
|
||||
def __repr__(self):
|
||||
return self.title + "(" + str(self.year) + ")"
|
||||
|
||||
def get_matches(self, video):
|
||||
matches = set()
|
||||
|
||||
if isinstance(video, Movie):
|
||||
# title
|
||||
if video.title and sanitize(self.title) == fix_inconsistent_naming(video.title):
|
||||
matches.add('title')
|
||||
|
||||
if video.year and self.year == video.year:
|
||||
matches.add('year')
|
||||
|
||||
if video.imdb_id and self.imdb_id == video.imdb_id:
|
||||
matches.add('imdb_id')
|
||||
|
||||
if video.release_group and video.release_group in self.comments:
|
||||
matches.add('release_group')
|
||||
|
||||
if video.resolution and video.resolution.lower() in self.comments:
|
||||
matches.add('resolution')
|
||||
|
||||
self.matches = matches
|
||||
|
||||
return matches
|
||||
|
||||
|
||||
class TitrariProvider(Provider, ProviderSubtitleArchiveMixin):
|
||||
subtitle_class = TitrariSubtitle
|
||||
languages = {Language(l) for l in ['ron', 'eng']}
|
||||
languages.update(set(Language.rebuild(l, forced=True) for l in languages))
|
||||
api_url = 'https://www.titrari.ro/'
|
||||
query_advanced_search = 'cautareavansata'
|
||||
|
||||
def __init__(self):
|
||||
self.session = None
|
||||
|
||||
def initialize(self):
|
||||
self.session = Session()
|
||||
self.session.headers['User-Agent'] = 'Subliminal/{}'.format(__short_version__)
|
||||
|
||||
def terminate(self):
|
||||
self.session.close()
|
||||
|
||||
def query(self, languages=None, title=None, imdb_id=None, video=None):
|
||||
subtitles = []
|
||||
|
||||
params = self.getQueryParams(imdb_id, title)
|
||||
|
||||
search_response = self.session.get(self.api_url, params=params, timeout=15)
|
||||
search_response.raise_for_status()
|
||||
|
||||
if not search_response.content:
|
||||
logger.debug('[#### Provider: titrari.ro] No data returned from provider')
|
||||
return []
|
||||
|
||||
soup = ParserBeautifulSoup(search_response.content.decode('utf-8', 'ignore'), ['lxml', 'html.parser'])
|
||||
|
||||
# loop over subtitle cells
|
||||
rows = soup.select('td[rowspan=\'5\']')
|
||||
for index, row in enumerate(rows):
|
||||
result_anchor_el = row.select_one('a')
|
||||
|
||||
# Download link
|
||||
href = result_anchor_el.get('href')
|
||||
download_link = self.api_url + href
|
||||
|
||||
fullTitle = row.parent.find("h1").find("a").text
|
||||
|
||||
#Get title
|
||||
try:
|
||||
title = fullTitle.split("(")[0]
|
||||
except:
|
||||
logger.error("[#### Provider: titrari.ro] Error parsing title.")
|
||||
|
||||
# Get downloads count
|
||||
try:
|
||||
downloads = int(row.parent.parent.select("span")[index].text[12:])
|
||||
except:
|
||||
logger.error("[#### Provider: titrari.ro] Error parsing downloads.")
|
||||
|
||||
# Get year
|
||||
try:
|
||||
year = int(fullTitle.split("(")[1].split(")")[0])
|
||||
except:
|
||||
year = None
|
||||
logger.error("[#### Provider: titrari.ro] Error parsing year.")
|
||||
|
||||
# Get imdbId
|
||||
sub_imdb_id = self.getImdbIdFromSubtitle(row)
|
||||
|
||||
try:
|
||||
comments = row.parent.parent.find_all("td", class_=re.compile("comment"))[index*2+1].text
|
||||
except:
|
||||
logger.error("Error parsing comments.")
|
||||
|
||||
subtitle = self.subtitle_class(next(iter(languages)), download_link, index, None, title, sub_imdb_id, year, downloads, comments)
|
||||
logger.debug('[#### Provider: titrari.ro] Found subtitle %r', str(subtitle))
|
||||
subtitles.append(subtitle)
|
||||
|
||||
ordered_subs = self.order(subtitles, video)
|
||||
|
||||
return ordered_subs
|
||||
|
||||
def order(self, subtitles, video):
|
||||
logger.debug("[#### Provider: titrari.ro] Sorting by download count...")
|
||||
sorted_subs = sorted(subtitles, key=lambda s: s.download_count, reverse=True)
|
||||
return sorted_subs
|
||||
|
||||
def getImdbIdFromSubtitle(self, row):
|
||||
try:
|
||||
imdbId = row.parent.parent.find_all(src=re.compile("imdb"))[0].parent.get('href').split("tt")[-1]
|
||||
except:
|
||||
logger.error("[#### Provider: titrari.ro] Error parsing imdbId.")
|
||||
if imdbId is not None:
|
||||
return "tt" + imdbId
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def getQueryParams(self, imdb_id, title):
|
||||
queryParams = {
|
||||
'page': self.query_advanced_search,
|
||||
'z8': '1'
|
||||
}
|
||||
if imdb_id is not None:
|
||||
queryParams["z5"] = imdb_id
|
||||
elif title is not None:
|
||||
queryParams["z7"] = title
|
||||
|
||||
return queryParams
|
||||
|
||||
def list_subtitles(self, video, languages):
|
||||
title = fix_inconsistent_naming(video.title)
|
||||
imdb_id = None
|
||||
try:
|
||||
imdb_id = video.imdb_id[2:]
|
||||
except:
|
||||
logger.error("[#### Provider: titrari.ro] Error parsing video.imdb_id.")
|
||||
|
||||
return [s for s in
|
||||
self.query(languages, title, imdb_id, video)]
|
||||
|
||||
def download_subtitle(self, subtitle):
|
||||
r = self.session.get(subtitle.download_link, headers={'Referer': self.api_url}, timeout=10)
|
||||
r.raise_for_status()
|
||||
|
||||
# open the archive
|
||||
archive_stream = io.BytesIO(r.content)
|
||||
if is_rarfile(archive_stream):
|
||||
logger.debug('[#### Provider: titrari.ro] Archive identified as rar')
|
||||
archive = RarFile(archive_stream)
|
||||
elif is_zipfile(archive_stream):
|
||||
logger.debug('[#### Provider: titrari.ro] Archive identified as zip')
|
||||
archive = ZipFile(archive_stream)
|
||||
else:
|
||||
subtitle.content = r.content
|
||||
if subtitle.is_valid():
|
||||
return
|
||||
subtitle.content = None
|
||||
|
||||
raise ProviderError('[#### Provider: titrari.ro] Unidentified archive type')
|
||||
|
||||
subtitle.content = self.get_subtitle_from_archive(subtitle, archive)
|
||||
|
Loading…
Reference in new issue