You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
4.9 KiB

Change core system to improve performance and facilitate multi TV info sources. Change migrate core objects TVShow and TVEpisode and everywhere that these objects affect. Add message to logs and disable ui backlog buttons when no media provider has active and/or scheduled searching enabled. Change views for py3 compat. Change set default runtime of 5 mins if none is given for layout Day by Day. Add OpenSubtitles authentication support to config/Subtitles/Subtitles Plugin. Add "Enforce media hash match" to config/Subtitles Plugin/Opensubtitles for accurate subs if enabled, but if disabled, search failures will fallback to use less reliable subtitle results. Add Apprise 0.8.0 (6aa52c3). Add hachoir_py3 3.0a6 (5b9e05a). Add sgmllib3k 1.0.0 Update soupsieve 1.9.1 (24859cc) to soupsieve_py2 1.9.5 (6a38398) Add soupsieve_py3 2.0.0.dev (69194a2). Add Tornado_py3 Web Server 6.0.3 (ff985fe). Add xmlrpclib_to 0.1.1 (c37db9e). Remove ancient Growl lib 0.1 Remove xmltodict library. Change requirements.txt for Cheetah3 to minimum 3.2.4 Change update sabToSickBeard. Change update autoProcessTV. Change remove Twitter notifier. Update NZBGet Process Media extension, SickGear-NG 1.7 → 2.4 Update Kodi addon 1.0.3 → 1.0.4 Update ADBA for py3. Update Beautiful Soup 4.8.0 (r526) to 4.8.1 (r531). Update Send2Trash 1.3.0 (a568370) to 1.5.0 (66afce7). Update soupsieve 1.9.1 (24859cc) to 1.9.5 (6a38398). Change use GNTP (Growl Notification Transport Protocol) from Apprise. Change add multi host support to Growl notifier. Fix Growl notifier when using empty password. Change update links for Growl notifications. Change deprecate confg/Notifications/Growl password field as these are now stored with host setting. Fix prevent infinite memoryError from a particular jpg data structure. Change subliminal for py3. Change enzyme for py3. Change browser_ua for py3. Change feedparser for py3 (sgmlib is no longer available on py3 as standardlib so added ext lib) Fix Guessit. Fix parse_xml for py3. Fix name parser with multi eps for py3. Fix tvdb_api fixes for py3 (search show). Fix config/media process to only display "pattern is invalid" qtip on "Episode naming" tab if the associated field is actually visible. Also, if the field becomes hidden due to a setting change, hide any previously displayed qtip. Note for Javascript::getelementbyid (or $('tag[id="<name>"')) is required when an id is being searched in the dom due to ":" used in a shows id name. Change download anidb xml files to main cache folder and use adba lib folder as a last resort. Change create get anidb show groups as centralised helper func and consolidate dupe code. Change move anidb related functions to newly renamed anime.py (from blacklistandwhitelist.py). Change str encode hex no longer exits in py3, use codecs.encode(...) instead. Change fix b64decode on py3 returns bytestrings. Change use binary read when downloading log file via browser to prevent any encoding issues. Change add case insensitive ordering to anime black/whitelist. Fix anime groups list not excluding whitelisted stuff. Change add Windows utf8 fix ... see: ytdl-org/youtube-dl#820 Change if no qualities are wanted, exit manual search thread. Fix keepalive for py3 process media. Change add a once a month update of tvinfo show mappings to the daily updater. Change autocorrect ids of new shows by updating from -8 to 31 days of the airdate of episode one. Add next run time to Manage/Show Tasks/Daily show update. Change when fetching imdb data, if imdb id is an episode id then try to find and use real show id. Change delete diskcache db in imdbpie when value error (due to change in Python version). Change during startup, cleanup any _cleaner.pyc/o to prevent issues when switching python versions. Add .pyc cleaner if python version is switched. Change replace deprecated gettz_db_metadata() and gettz. Change rebrand "SickGear PostProcessing script" to "SickGear Process Media extension". Change improve setup guide to use the NZBGet version to minimise displayed text based on version. Change NZBGet versions prior to v17 now told to upgrade as those version are no longer supported - code has actually exit on start up for some time but docs were outdated. Change comment out code and unused option sg_base_path. Change supported Python version 2.7.9-2.7.18 inclusive expanded to 3.7.1-3.8.1 inclusive. Change pidfile creation under Linux 0o644. Make logger accept lists to output continuously using the log_lock instead of split up by other processes. Fix long path issues with Windows process media.
6 years ago
from hachoir_py3.core.tools import makePrintable
from hachoir_py3.regex import RegexEmpty, parse, createString
class Pattern:
"""
Abstract class used to define a pattern used in pattern matching
"""
def __init__(self, user):
self.user = user
class StringPattern(Pattern):
"""
Static string pattern
"""
def __init__(self, text, user=None):
Pattern.__init__(self, user)
self.text = text
def __str__(self):
return makePrintable(self.text, 'ASCII')
def __repr__(self):
return "<StringPattern '%s'>" % self
class RegexPattern(Pattern):
"""
Regular expression pattern
"""
def __init__(self, regex, user=None):
Pattern.__init__(self, user)
self.regex = parse(regex)
self._compiled_regex = None
def __str__(self):
return makePrintable(str(self.regex), 'ASCII')
def __repr__(self):
return "<RegexPattern '%s'>" % self
def match(self, data):
return self.compiled_regex.match(data)
def _getCompiledRegex(self):
if self._compiled_regex is None:
self._compiled_regex = self.regex.compile(python=True)
return self._compiled_regex
compiled_regex = property(_getCompiledRegex)
class PatternMatching:
"""
Fast pattern matching class: match multiple patterns at the same time.
Create your patterns:
>>> p=PatternMatching()
>>> p.addString("a")
>>> p.addString("b")
>>> p.addRegex("[cd]e")
Search patterns:
>>> for item in p.search("a b ce"):
... print(item)
...
(0, 1, <StringPattern 'a'>)
(2, 3, <StringPattern 'b'>)
(4, 6, <RegexPattern '[cd]e'>)
"""
def __init__(self):
self.string_patterns = []
self.string_dict = {}
self.regex_patterns = []
self._need_commit = True
# Following attributes are generated by _commit() method
self._regex = None
self._compiled_regex = None
self._max_length = None
def commit(self):
"""
Generate whole regex merging all (string and regex) patterns
"""
if not self._need_commit:
return
self._need_commit = False
length = 0
regex = None
for item in self.string_patterns:
if regex:
regex |= createString(item.text)
else:
regex = createString(item.text)
length = max(length, len(item.text))
for item in self.regex_patterns:
if regex:
regex |= item.regex
else:
regex = item.regex
length = max(length, item.regex.maxLength())
if not regex:
regex = RegexEmpty()
self._regex = regex
self._compiled_regex = regex.compile(python=True)
self._max_length = length
def addString(self, magic, user=None):
item = StringPattern(magic, user)
if item.text in self.string_dict:
# Skip duplicates
return
self.string_patterns.append(item)
self.string_dict[item.text] = item
self._need_commit = True
def addRegex(self, regex, user=None):
item = RegexPattern(regex, user)
if item.regex.maxLength() is None:
raise ValueError(
"Regular expression with no maximum size has forbidden")
self.regex_patterns.append(item)
self._need_commit = True
def getPattern(self, data):
"""
Get pattern item matching data.
Raise KeyError if no pattern does match it.
"""
# Try in string patterns
try:
return self.string_dict[data]
except KeyError:
pass
# Try in regex patterns
for item in self.regex_patterns:
if item.match(data):
return item
raise KeyError("Unable to get pattern item")
def search(self, data):
"""
Search patterns in data.
Return a generator of tuples: (start, end, item)
"""
if not self.max_length:
# No pattern: returns nothing
return
for match in self.compiled_regex.finditer(data):
item = self.getPattern(match.group(0))
yield (match.start(0), match.end(0), item)
def __str__(self):
return makePrintable(str(self.regex), 'ASCII')
def _getAttribute(self, name):
self.commit()
return getattr(self, name)
def _getRegex(self):
return self._getAttribute("_regex")
regex = property(_getRegex)
def _getCompiledRegex(self):
return self._getAttribute("_compiled_regex")
compiled_regex = property(_getCompiledRegex)
def _getMaxLength(self):
return self._getAttribute("_max_length")
max_length = property(_getMaxLength)
if __name__ == "__main__":
import doctest
import sys
failure, nb_test = doctest.testmod()
if failure:
sys.exit(1)