Compare commits

..

5 Commits

Author SHA1 Message Date
panni cd9028354b incremental tmp 2021-03-09 03:09:52 +01:00
panni c77489a5be the heat 2020-08-12 17:02:54 +02:00
panni 25f204b330 whoops, missed dev flag 2020-08-12 17:01:06 +02:00
panni 89dded387d core: properly handle ReadTimeout 2020-08-12 16:09:53 +02:00
panni a9b677f0ce core: catch more exceptions 2020-08-08 03:46:57 +02:00
5 changed files with 121 additions and 10 deletions
+8 -1
View File
@@ -10,6 +10,8 @@ import jstyleson
import datetime
import stat
import traceback
import socket
import requests
import subliminal
import subliminal_patch
@@ -63,7 +65,9 @@ def int_or_default(s, default):
VALID_THROTTLE_EXCEPTIONS = (TooManyRequests, DownloadLimitExceeded, DownloadLimitPerDayExceeded,
ServiceUnavailable, APIThrottled)
ServiceUnavailable, APIThrottled, requests.Timeout, requests.ReadTimeout, socket.timeout)
def_timeout = (datetime.timedelta(minutes=20), "20 minutes")
PROVIDER_THROTTLE_MAP = {
"default": {
@@ -73,6 +77,9 @@ PROVIDER_THROTTLE_MAP = {
ServiceUnavailable: (datetime.timedelta(minutes=20), "20 minutes"),
APIThrottled: (datetime.timedelta(minutes=10), "10 minutes"),
AuthenticationError: (datetime.timedelta(hours=2), "2 hours"),
requests.Timeout: def_timeout,
socket.timeout: def_timeout,
requests.ReadTimeout: def_timeout,
},
"opensubtitles": {
TooManyRequests: (datetime.timedelta(hours=3), "3 hours"),
+1 -1
View File
@@ -23,7 +23,7 @@
<key>PlexPluginConsoleLogging</key>
<string>0</string>
<key>PlexPluginDevMode</key>
<string>0</string>
<string>1</string>
<key>PlexPluginCodePolicy</key>
<!-- this allows channels to access some python methods which are otherwise blocked, as well as import external code libraries, and interact with the PMS HTTP API -->
<string>Elevated</string>
@@ -108,10 +108,12 @@ class SZProviderPool(ProviderPool):
try:
logger.info('Terminating provider %s', name)
self.initialized_providers[name].terminate()
except (requests.Timeout, socket.timeout):
except (requests.Timeout, socket.timeout) as e:
logger.error('Provider %r timed out, improperly terminated', name)
except:
self.throttle_callback(name, e)
except Exception as e:
logger.exception('Provider %r terminated unexpectedly', name)
self.throttle_callback(name, e)
del self.initialized_providers[name]
@@ -183,8 +185,9 @@ class SZProviderPool(ProviderPool):
return out
except (requests.Timeout, socket.timeout):
logger.error('Provider %r timed out', provider)
except (requests.Timeout, socket.timeout) as e:
logger.exception('Provider %r timed out', provider)
self.throttle_callback(provider, e)
except Exception as e:
logger.exception('Unexpected error in provider %r: %s', provider, traceback.format_exc())
@@ -263,10 +266,11 @@ class SZProviderPool(ProviderPool):
requests.exceptions.ProxyError,
requests.exceptions.SSLError,
requests.Timeout,
socket.timeout):
socket.timeout) as e:
logger.exception('Provider %r connection error', subtitle.provider_name)
self.throttle_callback(subtitle.provider_name, e)
except ResponseNotReady:
except ResponseNotReady as e:
logger.error('Provider %r response error, reinitializing', subtitle.provider_name)
try:
self[subtitle.provider_name].terminate()
@@ -274,6 +278,7 @@ class SZProviderPool(ProviderPool):
except:
logger.error('Provider %r reinitialization error: %s', subtitle.provider_name,
traceback.format_exc())
self.throttle_callback(subtitle.provider_name, e)
except rarfile.BadRarFile:
logger.error('Malformed RAR file from provider %r, skipping subtitle.', subtitle.provider_name)
+1 -1
View File
@@ -21,7 +21,7 @@ if debug:
logging.basicConfig(level=logging.DEBUG)
#sub = Subtitle(Language.fromietf("eng:forced"), mods=["common", "remove_HI", "OCR_fixes", "fix_uppercase", "shift_offset(ms=-500)", "shift_offset(ms=500)", "shift_offset(s=2,ms=800)"])
sub = Subtitle(Language.fromietf("eng"), mods=["common", "remove_HI", "OCR_fixes", "fix_uppercase", "shift_offset(ms=0,s=1)"])
sub = Subtitle(Language.fromietf("eng"), mods=["common", "remove_HI", "OCR_fixes", "fix_uppercase", "shift_offset(ms=0,s=1)", "fix_incremental", "fix_short"])
sub.content = open(fn).read()
sub.normalize()
sub.is_valid()
@@ -1,6 +1,8 @@
# coding=utf-8
import re
import logging
from collections import OrderedDict
from subzero.language import Language
from subzero.modification.mods import SubtitleTextModification, empty_line_post_processors, SubtitleModification
@@ -9,7 +11,7 @@ from subzero.modification.processors.re_processor import NReProcessor
from subzero.modification import registry
from tld import get_tld
logger = logging.getLogger(__name__)
ENGLISH = Language("eng")
@@ -181,7 +183,104 @@ class FixUppercase(SubtitleModification):
entry.plaintext = self.capitalize(entry.plaintext)
class FixIncremental(SubtitleModification):
identifier = "fix_incremental"
description = "Fixes inremental-repeating subtitles"
modifies_whole_file = True
exclusive = True
long_description = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
def modify(self, content, debug=False, parent=None, **kwargs):
prev_entry = None
for entry in parent.f:
subs = []
for sub in entry.text.split("\N"):
if prev_entry and prev_entry.text and prev_entry.text.lower().endswith(sub.lower()):
if debug:
logger.debug(u"Skipping incremental/dup: %s" % sub)
continue
subs.append(sub)
if subs:
entry.text = "\N".join(subs)
prev_entry = entry
class FixShort(SubtitleModification):
identifier = "fix_short"
description = "ASDasdasdasdasdd"
modifies_whole_file = True
exclusive = True
long_description = "adsadsdasdsadsa"
def modify(self, content, debug=False, parent=None, **kwargs):
prev_entry = None
prev_entry_dur = None
max_duration = 500
max_line_len = 200
max_lines = 3
entries = []
last_lines = []
for index, entry in enumerate(parent.f):
current_new_lines = []
if not last_lines and parent.f[index-1]:
print "YOO"
# find last lines
last_lines = parent.f[index-1].text.split("\N")
has_space = len(last_lines) < max_lines
last_line = ""
# go through each line and pack them
for line in entry.text.split("\N"):
new_line = ""
if line:
if last_line != line and last_line and len(last_line + line) <= max_line_len:
# new line plus line fits
if re.match(".+\W$", line):
if last_line.endswith(" "):
new_line = last_line + line
else:
new_line = last_line + " " + line
logger.debug("MERGING '%s' with '%s' to '%s'", last_line, line, new_line)
else:
new_line = line
last_line = new_line
current_new_lines.append(new_line)
# merge entries
if prev_entry:
#print prev_entry.duration, max_duration, len(new_lines), max_lines
if prev_entry.duration < max_duration and len(current_new_lines) < max_lines:
#len(prev_entry.text) < max_len
print "HIT", prev_entry.text, " + ", entry.text
entry_text = prev_entry.text + "\N" + "\N".join(current_new_lines)
else:
entry_text = "\N".join(current_new_lines)
else:
entry_text = "\N".join(current_new_lines)
#prev_entry = entry.copy()
if not prev_entry:
prev_entry = entry.copy()
continue
new_entry = prev_entry.copy()
new_entry.text = entry_text
prev_entry = new_entry.copy()
entries.append(new_entry)
#new_entries.append(entry.copy())
parent.f.entries = entries
registry.register(CommonFixes)
registry.register(RemoveTags)
registry.register(ReverseRTL)
registry.register(FixUppercase)
registry.register(FixIncremental)
registry.register(FixShort)