From b1c9b71846404ff5dc225227e37088bb7c714495 Mon Sep 17 00:00:00 2001 From: echel0n Date: Sun, 22 Jun 2014 11:33:58 -0700 Subject: [PATCH 1/5] Testing new faster method of obtaining show object via regex matching for series name during Name Parsing for results. --- sickbeard/name_parser/parser.py | 64 ++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/sickbeard/name_parser/parser.py b/sickbeard/name_parser/parser.py index adc40df2..2dcee219 100644 --- a/sickbeard/name_parser/parser.py +++ b/sickbeard/name_parser/parser.py @@ -37,7 +37,8 @@ class NameParser(object): SPORTS_REGEX = 2 ANIME_REGEX = 3 - def __init__(self, file_name=True, showObj=None, epObj=None, useIndexers=False, convert=False, naming_pattern=False): + def __init__(self, file_name=True, showObj=None, epObj=None, useIndexers=False, convert=False, + naming_pattern=False): self.file_name = file_name self.showList = sickbeard.showList or [] @@ -47,17 +48,6 @@ class NameParser(object): self.convert = convert self.naming_pattern = naming_pattern - self.regexMode = self.ALL_REGEX - if self.showObj and self.showObj.is_anime: - self.regexMode = self.ANIME_REGEX - elif self.showObj and self.showObj.is_sports: - self.regexMode = self.SPORTS_REGEX - elif self.showObj and not self.showObj.is_anime and not self.showObj.is_sports: - self.regexMode = self.NORMAL_REGEX - - self.compiled_regexes = {} - self._compile_regexes(self.regexMode) - def clean_series_name(self, series_name): """Cleans up series name by removing any . and _ characters, along with any trailing hyphens. @@ -117,6 +107,36 @@ class NameParser(object): if not name: return + if not self.naming_pattern: + # Regex pattern to return the Show / Series Name regardless of the file pattern tossed at it, matched 53 show name examples from regexes.py + show_pattern = '''^(?:(UEFA|MLB|ESPN|WWE|MMA|UFC|TNA|EPL|NASCAR|NBA|NFL|NHL|NRL|PGA|SUPER LEAGUE|FORMULA|FIFA|NETBALL|MOTOG(P)))?(?:[0-9]+)?(?:\[(?:.+?)\][ ._-])?(?P.*?)(?:[ ._-])+?(?:Season|Part)?(?:.[eE][0-9][0-9]?)?(?:.?[sS]?[0-9][0-9]?)''' + try: + show_regex = re.compile(show_pattern, re.VERBOSE | re.IGNORECASE) + except re.error, errormsg: + logger.log(u"WARNING: Invalid show series name pattern, %s: [%s]" % (errormsg, show_pattern)) + else: + seriesname_match = show_regex.match(name) + seriesname_groups = seriesname_match.groupdict().keys() + + if not self.showObj and 'series_name' in seriesname_groups: + # Do we have recognize this show? + series_name = self.clean_series_name(seriesname_match.group('series_name')) + self.showObj = helpers.get_show_by_name(series_name, useIndexer=self.useIndexers) + + if not self.showObj: + return + + regexMode = self.ALL_REGEX + if self.showObj and self.showObj.is_anime: + regexMode = self.ANIME_REGEX + elif self.showObj and self.showObj.is_sports: + regexMode = self.SPORTS_REGEX + elif self.showObj and not self.showObj.is_anime and not self.showObj.is_sports: + regexMode = self.NORMAL_REGEX + + self.compiled_regexes = {} + self._compile_regexes(regexMode) + matches = [] result = None for (cur_regex_type, cur_regex_name), cur_regex in self.compiled_regexes.items(): @@ -137,22 +157,6 @@ class NameParser(object): result.series_name = self.clean_series_name(result.series_name) result.score += 1 - if not self.showObj and not self.naming_pattern: - self.showObj = helpers.get_show_by_name(result.series_name, useIndexer=self.useIndexers) - - if self.showObj: - result.show = self.showObj - if getattr(self.showObj, 'air_by_date', None) and not cur_regex_type == 'normal': - continue - elif getattr(self.showObj, 'sports', None) and not cur_regex_type == 'sports': - continue - elif getattr(self.showObj, 'anime', None) and not cur_regex_type == 'anime': - continue - - # don't continue parsing if we don't have a show object by now, try next regex pattern - if not self.showObj and not self.naming_pattern: - continue - if 'season_num' in named_groups: tmp_season = int(match.group('season_num')) if not (cur_regex_name == 'bare' and tmp_season in (19, 20)): @@ -555,7 +559,9 @@ class ParseResult(object): self.episode_numbers = new_episode_numbers self.season_number = new_season_numbers[0] - logger.log(u"Converted parsed result " + self.original_name + " into " + str(self).decode('utf-8', 'xmlcharrefreplace'), logger.DEBUG) + logger.log(u"Converted parsed result " + self.original_name + " into " + str(self).decode('utf-8', + 'xmlcharrefreplace'), + logger.DEBUG) return self From 0573a8add643c6dcaac02858e2628ce54c64e4d1 Mon Sep 17 00:00:00 2001 From: echel0n Date: Sun, 22 Jun 2014 12:25:54 -0700 Subject: [PATCH 2/5] Fix for NoneType name parsing issues from new test code. Fix for h264/x264 matching as absolute number. --- sickbeard/name_parser/parser.py | 10 ++++--- sickbeard/name_parser/regexes.py | 46 ++++++++++++++++---------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/sickbeard/name_parser/parser.py b/sickbeard/name_parser/parser.py index 2dcee219..b4dffeab 100644 --- a/sickbeard/name_parser/parser.py +++ b/sickbeard/name_parser/parser.py @@ -107,7 +107,7 @@ class NameParser(object): if not name: return - if not self.naming_pattern: + if not self.showObj and not self.naming_pattern: # Regex pattern to return the Show / Series Name regardless of the file pattern tossed at it, matched 53 show name examples from regexes.py show_pattern = '''^(?:(UEFA|MLB|ESPN|WWE|MMA|UFC|TNA|EPL|NASCAR|NBA|NFL|NHL|NRL|PGA|SUPER LEAGUE|FORMULA|FIFA|NETBALL|MOTOG(P)))?(?:[0-9]+)?(?:\[(?:.+?)\][ ._-])?(?P.*?)(?:[ ._-])+?(?:Season|Part)?(?:.[eE][0-9][0-9]?)?(?:.?[sS]?[0-9][0-9]?)''' try: @@ -116,9 +116,11 @@ class NameParser(object): logger.log(u"WARNING: Invalid show series name pattern, %s: [%s]" % (errormsg, show_pattern)) else: seriesname_match = show_regex.match(name) - seriesname_groups = seriesname_match.groupdict().keys() + if not seriesname_match: + return - if not self.showObj and 'series_name' in seriesname_groups: + seriesname_groups = seriesname_match.groupdict().keys() + if 'series_name' in seriesname_groups: # Do we have recognize this show? series_name = self.clean_series_name(seriesname_match.group('series_name')) self.showObj = helpers.get_show_by_name(series_name, useIndexer=self.useIndexers) @@ -247,7 +249,7 @@ class NameParser(object): result = result.convert() # get quality - result.quality = common.Quality.nameQuality(name, bool(result.show and result.show.is_anime)) + result.quality = common.Quality.nameQuality(name, result.show.is_anime) return result diff --git a/sickbeard/name_parser/regexes.py b/sickbeard/name_parser/regexes.py index fc56bbda..e4d74a5a 100644 --- a/sickbeard/name_parser/regexes.py +++ b/sickbeard/name_parser/regexes.py @@ -222,8 +222,8 @@ anime_regexes = {'anime':[ """ ^(?:\[(?P.+?)\][ ._-]*) (?P.+?)[ ._-]+ - (?P(?!(1080|720|480)[pi])\d{1,3}) - (-(?P(?!(1080|720|480)[pi])\d{1,3}))?[ ._-]+? + (?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}) + (-(?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}))?[ ._-]+? (?:v(?P[0-9]))? (?:[\w\.]*) (?:(?:(?:[\[\(])(?P\d{3,4}[xp]?\d{0,4}[\.\w\s-]*)(?:[\]\)]))|(?:\d{3,4}[xp])) @@ -241,8 +241,8 @@ anime_regexes = {'anime':[ ''' ^(\[(?P.+?)\][ ._-]*)? # Release Group and separator (?P.+?)[ ._-]+ # Show_Name and separator - (?P(?!(1080|720|480)[pi])\d{1,3}) # E01 - (-(?P(?!(1080|720|480)[pi])\d{1,3}))? # E02 + (?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}) # E01 + (-(?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}))? # E02 (v(?P[0-9]))? # version [ ._-]+\[(?P\d{3,4}[xp]?\d{0,4}[\.\w\s-]*)\] # Source_Quality_Etc- (\[(?P\w{8})\])? # CRC @@ -256,8 +256,8 @@ anime_regexes = {'anime':[ ''' ^(\[(?P.+?)\][ ._-]*)? # Release Group and separator (?P.+?)[ ._-]+ # Show_Name and separator - (?P(?!(1080|720|480)[pi])\d{1,3}) # E01 - (-(?P(?!(1080|720|480)[pi])\d{1,3}))? # E02 + (?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}) # E01 + (-(?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}))? # E02 (v(?P[0-9]))? # version [ ._-]+\((?P(CX[ ._-]?)?\d{3,4}[xp]?\d{0,4}[\.\w\s-]*)\) # Source_Quality_Etc- (\[(?P\w{8})\])? # CRC @@ -269,8 +269,8 @@ anime_regexes = {'anime':[ ''' ^(\[(?P.+?)\][ ._-]*)? # Release Group and separator (?P.+?)[ ._-]+ # Show_Name and separator - (?P(?!(1080|720|480)[pi])\d{1,3}) # E01 - (-(?P(?!(1080|720|480)[pi])\d{1,3}))? # E02 + (?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}) # E01 + (-(?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}))? # E02 (v(?P[0-9]))? # version [ ._-]+\[(?P\d{3,4}p) # Source_Quality_Etc- (\[(?P\w{8})\])? # CRC @@ -285,8 +285,8 @@ anime_regexes = {'anime':[ ^(\[(?P.+?)\][ ._-]*)? # Release Group and separator (?P.+?)[ ._]* # Show_Name and separator ([ ._-]+-[ ._-]+[A-Z]+[ ._-]+)?[ ._-]+ # funny stuff, this is sooo nuts ! this will kick me in the butt one day - (?P(?!(1080|720|480)[pi])\d{1,3}) # E01 - (-(?P(?!(1080|720|480)[pi])\d{1,3}))? # E02 + (?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}) # E01 + (-(?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}))? # E02 (v(?P[0-9]))? # version ([ ._-](\[\w{1,2}\])?\[[a-z][.]?\w{2,4}\])? #codec [ ._-]*\[(?P(\d{3,4}[xp]?\d{0,4})?[\.\w\s-]*)\] # Source_Quality_Etc- @@ -298,7 +298,7 @@ anime_regexes = {'anime':[ ''' ^(?:\[(?P.*?)\][ ._-]*)? (?:(?P.*?)[ ._-]*)? - (?:(?P((?!(1080|720|480)[pi])\d{1,3}))[ ._-]*).+? + (?:(?P(((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}))[ ._-]*).+? (?:\[(?P.*?)\][ ._-]*) (?:\[(?P\w{8})\])? .*? @@ -315,8 +315,8 @@ anime_regexes = {'anime':[ (([. _-]*e|-) # linking e/- char (?P\d+))* # additional E03/etc ([ ._-]{2,}|[ ._]+) # if "-" is used to separate at least something else has to be there(->{2,}) "s16e03-04-313-314" would make sens any way - ((?P(?!(1080|720|480)[pi])\d{1,3}))? # absolute number - (-(?P(?!(1080|720|480)[pi])\d{1,3}))? # "-" as separator and anditional absolute number, all optinal + ((?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}))? # absolute number + (-(?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}))? # "-" as separator and anditional absolute number, all optinal (v(?P[0-9]))? # the version e.g. "v2" .*? ''' @@ -334,8 +334,8 @@ anime_regexes = {'anime':[ (([. _-]*e|-) # linking e/- char (?P\d+))* # additional E03/etc ([ ._-]{2,}|[ ._]+) # if "-" is used to separate at least something else has to be there(->{2,}) "s16e03-04-313-314" would make sens any way - ((?P(?!(1080|720|480)[pi])\d{1,3}))? # absolute number - (-(?P(?!(1080|720|480)[pi])\d{1,3}))? # "-" as separator and anditional absolute number, all optinal + ((?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}))? # absolute number + (-(?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}))? # "-" as separator and anditional absolute number, all optinal (v(?P[0-9]))? # the version e.g. "v2" .*? ''' @@ -346,8 +346,8 @@ anime_regexes = {'anime':[ # Bleach - 313-314 - s16e03-04 ''' ^(?P.+?)[ ._-]+ # start of string and series name and non optinal separator - (?P(?!(1080|720|480)[pi])\d{1,3}) # absolute number - (-(?P(?!(1080|720|480)[pi])\d{1,3}))? # "-" as separator and anditional absolute number, all optinal + (?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}) # absolute number + (-(?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}))? # "-" as separator and anditional absolute number, all optinal (v(?P[0-9]))? # the version e.g. "v2" ([ ._-]{2,}|[ ._]+) # if "-" is used to separate at least something else has to be there(->{2,}) "s16e03-04-313-314" would make sens any way [sS](?P\d+)[. _-]* # S01 and optional separator @@ -361,8 +361,8 @@ anime_regexes = {'anime':[ ('anime_and_normal_front', # 165.Naruto Shippuuden.s08e014 ''' - ^(?P(?!(1080|720|480)[pi])\d{1,3}) # start of string and absolute number - (-(?P(?!(1080|720|480)[pi])\d{1,3}))? # "-" as separator and anditional absolute number, all optinal + ^(?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}) # start of string and absolute number + (-(?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}))? # "-" as separator and anditional absolute number, all optinal (v(?P[0-9]))?[ ._-]+ # the version e.g. "v2" (?P.+?)[ ._-]+ [sS](?P\d+)[. _-]* # S01 and optional separator @@ -377,8 +377,8 @@ anime_regexes = {'anime':[ ''' ^(?:\[(?P.+?)\][ ._-]*) (?P.+?)[ ._-]+ - (?P(?!(1080|720|480)[pi])\d{1,3}) - (-(?P(?!(1080|720|480)[pi])\d{1,3}))?[ ._-]*? + (?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}) + (-(?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}))?[ ._-]*? (?:v(?P[0-9])[ ._-]+?)? (?:.+?[ ._-]+?)? \[(?P\w+)\][ ._-]? @@ -393,8 +393,8 @@ anime_regexes = {'anime':[ ''' ^(\[(?P.+?)\][ ._-]*)? (?P.+?)[ ._-]+ # Show_Name and separator - (?P(?!(1080|720|480)[pi])\d{1,3}) # E01 - (-(?P(?!(1080|720|480)[pi])\d{1,3}))? # E02 + (?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}) # E01 + (-(?P((?!(1080|720|480)[pi])|(?![hx].?264))\d{1,3}))? # E02 (v(?P[0-9]))? # v2 .*? # Separator and EOL ''') From 688263bd62063250a7f8dd3b88a4571961ff06e7 Mon Sep 17 00:00:00 2001 From: echel0n Date: Sun, 22 Jun 2014 12:58:26 -0700 Subject: [PATCH 3/5] Fix for missing code in Name Parser --- sickbeard/name_parser/parser.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sickbeard/name_parser/parser.py b/sickbeard/name_parser/parser.py index b4dffeab..2f805120 100644 --- a/sickbeard/name_parser/parser.py +++ b/sickbeard/name_parser/parser.py @@ -230,12 +230,14 @@ class NameParser(object): result.release_group = match.group('release_group') result.score += 1 - if getattr(self.showObj, 'air_by_date', None) and result.air_date: - result.score += 1 - elif getattr(self.showObj, 'sports', None) and result.sports_event_date: - result.score += 1 - elif getattr(self.showObj, 'anime', None) and len(result.ab_episode_numbers): - result.score += 1 + if self.showObj: + result.show = self.showObj + if getattr(self.showObj, 'air_by_date', None) and result.air_date: + result.score += 1 + elif getattr(self.showObj, 'sports', None) and result.sports_event_date: + result.score += 1 + elif getattr(self.showObj, 'anime', None) and len(result.ab_episode_numbers): + result.score += 1 result.score += 1 matches.append(result) From b0149cc65df8a8091f9f51d1729c2e875a2f9747 Mon Sep 17 00:00:00 2001 From: echel0n Date: Sun, 22 Jun 2014 13:06:20 -0700 Subject: [PATCH 4/5] Fix so that scene converting does not happening when performing naming pattern routines. --- sickbeard/name_parser/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sickbeard/name_parser/parser.py b/sickbeard/name_parser/parser.py index 2f805120..ad4dddf5 100644 --- a/sickbeard/name_parser/parser.py +++ b/sickbeard/name_parser/parser.py @@ -246,7 +246,7 @@ class NameParser(object): result = max(matches, key=lambda x: x.score) if result.show: - if self.convert: + if self.convert and not self.naming_pattern: # scene convert result result = result.convert() From 0599a89565dcfc3ef433fea6e0f836456db36f4f Mon Sep 17 00:00:00 2001 From: echel0n Date: Sun, 22 Jun 2014 18:24:55 -0700 Subject: [PATCH 5/5] Fix for DB issues on new installs relating to database version checks. --- sickbeard/db.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sickbeard/db.py b/sickbeard/db.py index 0f46f68e..2097d2d3 100644 --- a/sickbeard/db.py +++ b/sickbeard/db.py @@ -105,10 +105,10 @@ class DBConnection(object): result = None try: - result = self.select("SELECT db_version FROM db_version") - except sqlite3.OperationalError, e: - if "no such table: db_version" in e.args[0]: - return 0 + if self.hasTable('db_version'): + result = self.select("SELECT db_version FROM db_version") + except: + pass if result: return int(result[0]["db_version"])