2019-08-09 14:41:35 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
from requests import Session
|
|
|
|
from subzero.language import Language
|
|
|
|
|
|
|
|
from subliminal import Movie, Episode, ProviderError, __short_version__
|
|
|
|
from subliminal_patch.subtitle import Subtitle, guess_matches
|
2020-10-04 02:05:05 +00:00
|
|
|
from subliminal.providers import ParserBeautifulSoup
|
2019-08-09 14:41:35 +00:00
|
|
|
from subliminal.subtitle import fix_line_ending, SUBTITLE_EXTENSIONS
|
|
|
|
from subliminal_patch.providers import Provider
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class SubtitulamosTVSubtitle(Subtitle):
|
|
|
|
provider_name = 'subtitulamostv'
|
2019-10-10 19:25:03 +00:00
|
|
|
hash_verifiable = False
|
|
|
|
|
2020-10-04 02:05:05 +00:00
|
|
|
def __init__(self, language, page_link, download_link, title, release_info):
|
|
|
|
super(SubtitulamosTVSubtitle, self).__init__(language, hearing_impaired=False, page_link=page_link)
|
2019-10-10 19:25:03 +00:00
|
|
|
self.download_link = download_link
|
|
|
|
self.title = title
|
2019-10-10 20:24:13 +00:00
|
|
|
self.release_info = release_info
|
2019-08-09 14:41:35 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def id(self):
|
2019-10-10 19:25:03 +00:00
|
|
|
return self.download_link
|
2019-08-09 14:41:35 +00:00
|
|
|
|
|
|
|
def get_matches(self, video):
|
2020-10-04 02:05:05 +00:00
|
|
|
matches = {'series', 'season', 'episode', 'year'}
|
|
|
|
|
|
|
|
title_lower = self.title.lower()
|
|
|
|
release_info_lower = self.release_info.lower()
|
2019-08-09 14:41:35 +00:00
|
|
|
|
2020-10-04 02:05:05 +00:00
|
|
|
if video.title and video.title.lower() in title_lower:
|
|
|
|
matches.add('title')
|
|
|
|
|
|
|
|
if video.release_group and video.release_group.lower() in release_info_lower:
|
2019-10-10 19:25:03 +00:00
|
|
|
matches.add('release_group')
|
|
|
|
|
2020-10-04 02:05:05 +00:00
|
|
|
if video.resolution and video.resolution.lower() in release_info_lower:
|
2019-10-10 19:25:03 +00:00
|
|
|
matches.add('resolution')
|
|
|
|
|
2020-05-20 15:29:39 +00:00
|
|
|
if video.source:
|
|
|
|
formats = [video.source.lower()]
|
|
|
|
if formats[0] == "web":
|
2019-10-10 19:25:03 +00:00
|
|
|
formats.append("webdl")
|
2020-10-04 02:05:05 +00:00
|
|
|
formats.append("web-dl")
|
2019-10-10 19:25:03 +00:00
|
|
|
formats.append("webrip")
|
|
|
|
for frmt in formats:
|
2020-10-04 02:05:05 +00:00
|
|
|
if frmt in release_info_lower:
|
2020-05-20 15:29:39 +00:00
|
|
|
matches.add('source')
|
2019-10-10 19:25:03 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
if video.video_codec:
|
|
|
|
video_codecs = [video.video_codec.lower()]
|
2020-10-04 02:05:05 +00:00
|
|
|
if video_codecs[0] == "h.264":
|
|
|
|
video_codecs.append("h264")
|
|
|
|
video_codecs.append("x264")
|
|
|
|
elif video_codecs[0] == "h.265":
|
|
|
|
video_codecs.append("h265")
|
|
|
|
video_codecs.append("x265")
|
|
|
|
for vc in video_codecs:
|
|
|
|
if vc in release_info_lower:
|
2019-10-10 19:25:03 +00:00
|
|
|
matches.add('video_codec')
|
|
|
|
break
|
2019-08-09 14:41:35 +00:00
|
|
|
|
|
|
|
return matches
|
|
|
|
|
|
|
|
|
|
|
|
class SubtitulamosTVProvider(Provider):
|
|
|
|
"""Subtitulamostv Provider"""
|
2020-10-04 02:05:05 +00:00
|
|
|
languages = {Language.fromietf(lang) for lang in ['en', 'es']}
|
2019-08-09 14:41:35 +00:00
|
|
|
video_types = (Episode,)
|
|
|
|
|
2020-10-04 02:05:05 +00:00
|
|
|
server_url = 'https://subtitulamos.tv'
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.session = None
|
|
|
|
|
2019-08-09 14:41:35 +00:00
|
|
|
def initialize(self):
|
|
|
|
self.session = Session()
|
|
|
|
self.session.headers = {
|
|
|
|
'User-Agent': os.environ.get("SZ_USER_AGENT", "Sub-Zero/2")}
|
|
|
|
|
|
|
|
def terminate(self):
|
|
|
|
self.session.close()
|
|
|
|
|
|
|
|
def query(self, languages, video):
|
2020-10-04 02:05:05 +00:00
|
|
|
subtitle_name = "%s %dx%02d" % (video.series, video.season, video.episode)
|
|
|
|
logger.debug('Searching subtitles "%s"' % subtitle_name)
|
2019-08-09 14:41:35 +00:00
|
|
|
|
2020-10-04 02:05:05 +00:00
|
|
|
response = self.session.get(self.server_url + '/search/query', params={'q': video.series}, timeout=10)
|
|
|
|
response.raise_for_status()
|
|
|
|
result = response.json()
|
2019-08-09 14:41:35 +00:00
|
|
|
|
|
|
|
subtitles = []
|
2020-10-04 02:05:05 +00:00
|
|
|
for serie in result:
|
|
|
|
# skip non-matching series
|
|
|
|
if video.series.lower() != serie['name'].lower():
|
|
|
|
continue
|
|
|
|
|
|
|
|
response = self.session.get(self.server_url + "/shows/%d/season/%d" % (serie['id'], video.season),
|
|
|
|
timeout=10)
|
|
|
|
response.raise_for_status()
|
|
|
|
soup = ParserBeautifulSoup(response.text, ['lxml', 'html.parser'])
|
|
|
|
|
|
|
|
for episode in soup.select('div.episode'):
|
|
|
|
episode_soup = episode.find('a')
|
|
|
|
episode_name = episode_soup.text
|
|
|
|
episode_url = episode_soup['href']
|
|
|
|
|
|
|
|
# skip non-matching episodes
|
|
|
|
if subtitle_name.lower() not in episode_name.lower():
|
|
|
|
continue
|
|
|
|
|
|
|
|
for lang in episode.select("div.subtitle-language"):
|
|
|
|
if "English" in lang.text:
|
2019-08-09 14:41:35 +00:00
|
|
|
language = "en"
|
2020-10-04 02:05:05 +00:00
|
|
|
elif "Español" in lang.text:
|
|
|
|
language = "es"
|
|
|
|
else:
|
|
|
|
continue # not supported yet
|
2019-08-09 14:41:35 +00:00
|
|
|
logger.debug('Found subtitles in "%s" language.', language)
|
|
|
|
|
2020-10-04 02:05:05 +00:00
|
|
|
for release in lang.find_next_sibling("div").select("div.sub"):
|
|
|
|
release_name = release.select('div.version-name')[0].text
|
|
|
|
release_url = release.select('a[href*="/download"]')[0]['href']
|
|
|
|
|
2019-10-10 19:25:03 +00:00
|
|
|
subtitles.append(
|
|
|
|
SubtitulamosTVSubtitle(
|
2020-10-04 02:05:05 +00:00
|
|
|
Language.fromietf(language),
|
|
|
|
self.server_url + episode_url,
|
|
|
|
self.server_url + release_url,
|
|
|
|
episode_name,
|
|
|
|
release_name
|
2019-10-10 19:25:03 +00:00
|
|
|
)
|
|
|
|
)
|
2020-10-04 02:05:05 +00:00
|
|
|
|
2019-08-09 14:41:35 +00:00
|
|
|
return subtitles
|
|
|
|
|
|
|
|
def list_subtitles(self, video, languages):
|
|
|
|
return self.query(languages, video)
|
|
|
|
|
|
|
|
def download_subtitle(self, subtitle):
|
|
|
|
logger.info('Downloading subtitle %r', subtitle)
|
|
|
|
r = self.session.get(subtitle.download_link, timeout=10)
|
|
|
|
r.raise_for_status()
|
|
|
|
|
2019-10-31 03:57:50 +00:00
|
|
|
r.encoding = "ISO-8859-1"
|
2019-11-08 00:37:56 +00:00
|
|
|
subtitle_content = r.content
|
2019-08-09 14:41:35 +00:00
|
|
|
|
|
|
|
if subtitle_content:
|
|
|
|
subtitle.content = fix_line_ending(subtitle_content)
|
|
|
|
else:
|
|
|
|
logger.debug('Could not download subtitle from %s', subtitle.download_link)
|