Merge pull request #974 from redglory/development

added skip_wrong_fps match and login on redirection
pull/986/head
morpheus65535 5 years ago committed by GitHub
commit 79a6de7d18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -104,7 +104,8 @@ defaults = {
},
'legendasdivx': {
'username': '',
'password': ''
'password': '',
'skip_wrong_fps': 'False'
},
'legendastv': {
'username': '',

@ -135,6 +135,7 @@ def get_providers_auth():
},
'legendasdivx': {'username': settings.legendasdivx.username,
'password': settings.legendasdivx.password,
'skip_wrong_fps': settings.legendasdivx.getboolean('skip_wrong_fps'),
},
'legendastv': {'username': settings.legendastv.username,
'password': settings.legendastv.password,

@ -401,12 +401,19 @@ def save_wizard():
else:
settings_opensubtitles_skip_wrong_fps = 'True'
settings_legendasdivx_skip_wrong_fps = request.forms.get('settings_legendasdivx_skip_wrong_fps')
if settings_legendasdivx_skip_wrong_fps is None:
settings_legendasdivx_skip_wrong_fps = 'False'
else:
settings_legendasdivx_skip_wrong_fps = 'True'
settings.addic7ed.username = request.forms.get('settings_addic7ed_username')
settings.addic7ed.password = request.forms.get('settings_addic7ed_password')
settings.addic7ed.random_agents = text_type(settings_addic7ed_random_agents)
settings.assrt.token = request.forms.get('settings_assrt_token')
settings.legendasdivx.username = request.forms.get('settings_legendasdivx_username')
settings.legendasdivx.password = request.forms.get('settings_legendasdivx_password')
settings.legendasdivx.skip_wrong_fps = text_type(settings_legendasdivx_skip_wrong_fps)
settings.legendastv.username = request.forms.get('settings_legendastv_username')
settings.legendastv.password = request.forms.get('settings_legendastv_password')
settings.opensubtitles.username = request.forms.get('settings_opensubtitles_username')
@ -1543,12 +1550,19 @@ def save_settings():
region.delete("os_token")
region.delete("os_server_url")
settings_legendasdivx_skip_wrong_fps = request.forms.get('settings_legendasdivx_skip_wrong_fps')
if settings_legendasdivx_skip_wrong_fps is None:
settings_legendasdivx_skip_wrong_fps = 'False'
else:
settings_legendasdivx_skip_wrong_fps = 'True'
settings.addic7ed.username = request.forms.get('settings_addic7ed_username')
settings.addic7ed.password = request.forms.get('settings_addic7ed_password')
settings.addic7ed.random_agents = text_type(settings_addic7ed_random_agents)
settings.assrt.token = request.forms.get('settings_assrt_token')
settings.legendasdivx.username = request.forms.get('settings_legendasdivx_username')
settings.legendasdivx.password = request.forms.get('settings_legendasdivx_password')
settings.legendasdivx.skip_wrong_fps = text_type(settings_legendasdivx_skip_wrong_fps)
settings.legendastv.username = request.forms.get('settings_legendastv_username')
settings.legendastv.password = request.forms.get('settings_legendastv_password')
settings.opensubtitles.username = request.forms.get('settings_opensubtitles_username')

@ -5,6 +5,7 @@ import io
import os
import re
import zipfile
from time import sleep
from requests.exceptions import HTTPError
import rarfile
@ -18,7 +19,7 @@ from subliminal.video import Episode, Movie
from subliminal_patch.exceptions import TooManyRequests, IPAddressBlocked
from subliminal_patch.http import RetryingCFSession
from subliminal_patch.providers import Provider
from subliminal_patch.score import get_scores
from subliminal_patch.score import get_scores, framerate_equal
from subliminal_patch.subtitle import Subtitle
from subzero.language import Language
from dogpile.cache.api import NO_VALUE
@ -29,7 +30,7 @@ class LegendasdivxSubtitle(Subtitle):
"""Legendasdivx Subtitle."""
provider_name = 'legendasdivx'
def __init__(self, language, video, data):
def __init__(self, language, video, data, skip_wrong_fps=True):
super(LegendasdivxSubtitle, self).__init__(language)
self.language = language
self.page_link = data['link']
@ -37,8 +38,11 @@ class LegendasdivxSubtitle(Subtitle):
self.exact_match = data['exact_match']
self.description = data['description']
self.video = video
self.sub_frame_rate = data['frame_rate']
self.video_filename = data['video_filename']
self.uploader = data['uploader']
self.wrong_fps = False
self.skip_wrong_fps = skip_wrong_fps
@property
def id(self):
@ -51,6 +55,23 @@ class LegendasdivxSubtitle(Subtitle):
def get_matches(self, video):
matches = set()
# if skip_wrong_fps = True no point to continue if they don't match
subtitle_fps = None
try:
subtitle_fps = float(self.sub_frame_rate)
except ValueError:
pass
# check fps match and skip based on configuration
if video.fps and subtitle_fps and not framerate_equal(video.fps, subtitle_fps):
self.wrong_fps = True
if self.skip_wrong_fps:
logger.debug("Legendasdivx :: Skipping subtitle due to FPS mismatch (expected: %s, got: %s)", video.fps, self.sub_frame_rate)
# not a single match :)
return set()
logger.debug("Legendasdivx :: Frame rate mismatch (expected: %s, got: %s, but continuing...)", video.fps, self.sub_frame_rate)
description = sanitize(self.description)
if sanitize(self.video_filename) in description:
@ -109,8 +130,6 @@ class LegendasdivxSubtitle(Subtitle):
matches.update(['video_codec'])
break
# running guessit on a huge description may break guessit
# matches |= guess_matches(video, guessit(self.description))
return matches
class LegendasdivxProvider(Provider):
@ -122,21 +141,19 @@ class LegendasdivxProvider(Provider):
'User-Agent': os.environ.get("SZ_USER_AGENT", "Sub-Zero/2"),
'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'
'Referer': 'https://www.legendasdivx.pt'
}
loginpage = site + '/forum/ucp.php?mode=login'
logoutpage = site + '/sair.php'
searchurl = site + '/modules.php?name=Downloads&file=jz&d_op=search&op=_jz00&query={query}'
download_link = site + '/modules.php{link}'
def __init__(self, username, password):
def __init__(self, username, password, skip_wrong_fps=True):
# make sure login credentials are configured.
if any((username, password)) and not all((username, password)):
raise ConfigurationError('Legendasdivx.pt :: Username and password must be specified')
self.username = username
self.password = password
self.skip_wrong_fps = skip_wrong_fps
def initialize(self):
logger.info("Legendasdivx.pt :: Creating session for requests")
@ -201,7 +218,6 @@ class LegendasdivxProvider(Provider):
logger.error("LegendasDivx.pt :: Uncaught error: %r", e)
raise ServiceUnavailable("LegendasDivx.pt :: Uncaught error: %r", e)
def _process_page(self, video, bsoup, video_filename):
subtitles = []
@ -210,17 +226,20 @@ class LegendasdivxProvider(Provider):
for _subbox in _allsubs:
hits = 0
for th in _subbox.findAll("th", {"class": "color2"}):
for th in _subbox.findAll("th"):
if th.text == 'Hits:':
hits = int(th.parent.find("td").text)
hits = int(th.find_next("td").text)
if th.text == 'Idioma:':
lang = th.parent.find("td").find("img").get('src')
lang = th.find_next("td").find("img").get('src')
if 'brazil' in lang.lower():
lang = Language.fromopensubtitles('pob')
elif 'portugal' in lang.lower():
lang = Language.fromopensubtitles('por')
else:
continue
if th.text == "Frame Rate:":
frame_rate = th.find_next("td").text.strip()
# get description for matches
description = _subbox.find("td", {"class": "td_desc brd_up"}).get_text()
#get subtitle link
@ -245,11 +264,12 @@ class LegendasdivxProvider(Provider):
'exact_match': exact_match,
'hits': hits,
'uploader': uploader,
'frame_rate': frame_rate,
'video_filename': video_filename,
'description': description
}
subtitles.append(
LegendasdivxSubtitle(lang, video, data)
LegendasdivxSubtitle(lang, video, data, skip_wrong_fps=self.skip_wrong_fps)
)
return subtitles
@ -281,15 +301,23 @@ class LegendasdivxProvider(Provider):
querytext = querytext + lang_filter if lang_filter else querytext
self.headers['Referer'] = self.site + '/index.php'
self.session.headers.update(self.headers.items())
res = self.session.get(_searchurl.format(query=querytext))
try:
# sleep for a 1 second before another request
sleep(1)
self.headers['Referer'] = self.site + '/index.php'
self.session.headers.update(self.headers)
res = self.session.get(_searchurl.format(query=querytext), allow_redirects=False)
res.raise_for_status()
if (res and "A legenda não foi encontrada" in res.text):
if (res.status_code == 200 and "A legenda não foi encontrada" in res.text):
logger.warning('Legendasdivx.pt :: %s not found', querytext)
return []
if res.status_code == 302: # got redirected to login page.
# Seems that our session cookies are no longer valid... clean them from cache
region.delete("legendasdivx_cookies2")
logger.debug("Legendasdivx.pt :: Logging in again. Cookies have expired!")
self.login() # login and try again
res = self.session.get(_searchurl.format(query=querytext))
res.raise_for_status()
except HTTPError as e:
if "bloqueado" in res.text.lower(): # ip blocked on server
logger.error("LegendasDivx.pt :: Your IP is blocked on this server.")
@ -322,6 +350,7 @@ class LegendasdivxProvider(Provider):
# more pages?
if num_pages > 1:
for num_page in range(2, num_pages+1):
sleep(1) # another 1 sec before requesting...
_search_next = self.searchurl.format(query=querytext) + "&page={0}".format(str(num_page))
logger.debug("Legendasdivx.pt :: Moving on to next page: %s", _search_next)
res = self.session.get(_search_next)

@ -265,6 +265,24 @@
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned six wide column">
<label>Skip wrong FPS</label>
</div>
<div class="one wide column">
<div id="settings_legendasdivx_skip_wrong_fps" class="ui toggle checkbox" data-ldfps={{settings.legendasdivx.getboolean('skip_wrong_fps')}}>
<input type="checkbox" name="settings_legendasdivx_skip_wrong_fps">
<label></label>
</div>
</div>
<div class="collapsed column">
<div class="collapsed center aligned column">
<div class="ui basic icon" data-tooltip="Skip Subtitles with a mismatched FPS value; might lead to more results when disabled but also to more false-positives." data-inverted="">
<i class="help circle large icon"></i>
</div>
</div>
</div>
</div>
</div>
<div class="middle aligned row">
@ -500,8 +518,9 @@
</div>
</div>
<div id="regielive_option" class="ui grid container">
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Subdivx</label>
@ -733,7 +752,7 @@
</div>
</div>
<div id="titlovi_option" class="ui grid container">
<div class="middle aligned row">
<div class="middle aligned row">
<div class="right aligned six wide column">
<label>Username</label>
</div>
@ -833,7 +852,7 @@
</div>
</div>
<div id="xsubs_option" class="ui grid container">
<div class="middle aligned row">
<div class="middle aligned row">
<div class="right aligned six wide column">
<label>Username</label>
</div>
@ -944,6 +963,12 @@
$("#settings_opensubtitles_skip_wrong_fps").checkbox('uncheck');
}
if ($('#settings_legendasdivx_skip_wrong_fps').data("ldfps") === "True") {
$("#settings_legendasdivx_skip_wrong_fps").checkbox('check');
} else {
$("#settings_legendasdivx_skip_wrong_fps").checkbox('uncheck');
}
$('#settings_providers').dropdown('clear');
$('#settings_providers').dropdown('set selected',{{!enabled_providers}});
$('#settings_providers').dropdown();
@ -971,4 +996,4 @@
$('#'+$(this).parent().attr('id')+'_option').hide();
}
});
</script>
</script>
Loading…
Cancel
Save