From 24dfbc3f15c7a708b77d983f5e3e5ecc4cf3b7dc Mon Sep 17 00:00:00 2001 From: echel0n Date: Sat, 7 Jun 2014 04:06:21 -0700 Subject: [PATCH] Quality is now set during parsing of results. Fixed more anime regex bugs. Fixed Indexer API issues for anime shows and unicode problems. --- lib/tvdb_api/tvdb_api.py | 4 +-- lib/tvrage_api/tvrage_api.py | 5 ++-- sickbeard/classes.py | 6 ++--- sickbeard/name_parser/parser.py | 18 +++++++++++-- sickbeard/name_parser/regexes.py | 44 ++++++++++++++++---------------- sickbeard/postProcessor.py | 2 +- sickbeard/providers/generic.py | 2 +- sickbeard/tv.py | 2 +- sickbeard/webserve.py | 2 ++ 9 files changed, 51 insertions(+), 34 deletions(-) diff --git a/lib/tvdb_api/tvdb_api.py b/lib/tvdb_api/tvdb_api.py index 2895f030..47d798c7 100644 --- a/lib/tvdb_api/tvdb_api.py +++ b/lib/tvdb_api/tvdb_api.py @@ -598,11 +598,11 @@ class Tvdb: zipdata = StringIO.StringIO() zipdata.write(resp.content) myzipfile = zipfile.ZipFile(zipdata) - return xmltodict.parse(myzipfile.read('%s.xml' % language).strip(), postprocessor=process) + return xmltodict.parse(myzipfile.read('%s.xml' % language).strip().encode('utf-8'), postprocessor=process) except zipfile.BadZipfile: raise tvdb_error("Bad zip file received from thetvdb.com, could not read it") else: - return xmltodict.parse(resp.content.strip(), postprocessor=process) + return xmltodict.parse(resp.content.strip().encode('utf-8'), postprocessor=process) def _getetsrc(self, url, params=None, language=None): """Loads a URL using caching, returns an ElementTree of the source diff --git a/lib/tvrage_api/tvrage_api.py b/lib/tvrage_api/tvrage_api.py index c30f4173..4d47e088 100644 --- a/lib/tvrage_api/tvrage_api.py +++ b/lib/tvrage_api/tvrage_api.py @@ -462,7 +462,7 @@ class TVRage: return (key, value) if resp.ok: - return xmltodict.parse(resp.content.strip(), postprocessor=remap_keys) + return xmltodict.parse(resp.content.strip().encode('utf-8'), postprocessor=remap_keys) def _getetsrc(self, url, params=None): """Loads a URL using caching, returns an ElementTree of the source @@ -527,6 +527,7 @@ class TVRage: if not isinstance(data, dict or list): data = data.replace(u"&", u"&") data = data.strip() + return data def search(self, series): @@ -597,7 +598,7 @@ class TVRage: self.config['params_epInfo']['sid'] = sid epsEt = self._getetsrc(self.config['url_epInfo'], self.config['params_epInfo']) - for season in epsEt['episodelist']['season']: + for season in epsEt['episodelist'].values(): episodes = season['episode'] if not isinstance(episodes, list): episodes = [episodes] diff --git a/sickbeard/classes.py b/sickbeard/classes.py index 8fa2a317..6abdb7e5 100644 --- a/sickbeard/classes.py +++ b/sickbeard/classes.py @@ -163,12 +163,12 @@ class AllShowsListUI: continue if 'seriesname' in curShow: - seriesnames.append(unicode(curShow['seriesname'])) + seriesnames.append(curShow['seriesname'].encode('utf-8')) if 'aliasnames' in curShow: - seriesnames.extend(unicode(curShow['aliasnames']).split('|')) + seriesnames.extend(curShow['aliasnames'].encode('utf-8').split('|')) for name in seriesnames: - if str(searchterm).lower() in str(name).lower(): + if searchterm.lower() in name.lower(): if 'firstaired' not in curShow: curShow['firstaired'] = str(datetime.date.fromordinal(1)) curShow['firstaired'] = re.sub("([-]0{2}){1,}", "", curShow['firstaired']) diff --git a/sickbeard/name_parser/parser.py b/sickbeard/name_parser/parser.py index 962413bb..897dc8a2 100644 --- a/sickbeard/name_parser/parser.py +++ b/sickbeard/name_parser/parser.py @@ -23,7 +23,7 @@ import threading import regexes import sickbeard -from sickbeard import logger, helpers, scene_numbering +from sickbeard import logger, helpers, scene_numbering, common from dateutil import parser nameparser_lock = threading.Lock() @@ -214,6 +214,7 @@ class NameParser(object): result.score += 1 elif self.showObj.anime and len(result.ab_episode_numbers): result.score += 1 + matches.append(result) continue @@ -234,6 +235,10 @@ class NameParser(object): if len(matches): result = max(matches, key=lambda x: x.score) + # get quality + if result.show: + result.quality = common.Quality.nameQuality(name, bool(result.show and result.show.is_anime)) + return result def _combine_results(self, first, second, attr): @@ -355,6 +360,7 @@ class NameParser(object): final_result.which_regex += dir_name_result.which_regex final_result.show = self._combine_results(file_name_result, dir_name_result, 'show') + final_result.quality = self._combine_results(file_name_result, dir_name_result, 'quality') # if there's no useful info in it then raise an exception if final_result.season_number == None and not final_result.episode_numbers and final_result.air_date == None and not final_result.series_name: @@ -380,7 +386,8 @@ class ParseResult(object): air_date=None, ab_episode_numbers=None, show=None, - score=None + score=None, + quality=None ): self.original_name = original_name @@ -397,6 +404,11 @@ class ParseResult(object): else: self.ab_episode_numbers = ab_episode_numbers + if not quality: + self.quality = common.Quality.UNKNOWN + else: + self.quality = quality + self.extra_info = extra_info self.release_group = release_group @@ -438,6 +450,8 @@ class ParseResult(object): return False if self.score != other.score: return False + if self.quality != other.quality: + return False return True diff --git a/sickbeard/name_parser/regexes.py b/sickbeard/name_parser/regexes.py index c9aed6f9..6396cbb0 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\d{1,3}))?[ ._-]+? + (?P(?!(1080|720|480)[pi])\d+) + (-(?P(?!(1080|720|480)[pi])\d+))?[ ._-]+? (?: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\d{1,3}))? # E02 + (?P(?!(1080|720|480)[pi])\d+) # E01 + (-(?P(?!(1080|720|480)[pi])\d+))? # 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\d{1,3}))? # E02 + (?P(?!(1080|720|480)[pi])\d+) # E01 + (-(?P(?!(1080|720|480)[pi])\d+))? # 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\d{1,3}))? # E02 + (?P(?!(1080|720|480)[pi])\d+) # E01 + (-(?P(?!(1080|720|480)[pi])\d+))? # 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\d{1,3}))? # E02 + (?P(?!(1080|720|480)[pi])\d+) # E01 + (-(?P(?!(1080|720|480)[pi])\d+))? # 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- @@ -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\d{1,3}))? # "-" as separator and anditional absolute number, all optinal + (?P(?!(1080|720|480)[pi])\d+) # absolute number + (-(?P(?!(1080|720|480)[pi])\d+))? # "-" 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\d{1,3}))? # "-" as separator and anditional absolute number, all optinal + (?P(?!(1080|720|480)[pi])\d+) # absolute number + (-(?P(?!(1080|720|480)[pi])\d+))? # "-" 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\d{1,3}))? # "-" as separator and anditional absolute number, all optinal + (?P(?!(1080|720|480)[pi])\d+) # absolute number + (-(?P(?!(1080|720|480)[pi])\d+))? # "-" 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\d{1,3}))? # "-" as separator and anditional absolute number, all optinal + ^(?P(?!(1080|720|480)[pi])\d+) # start of string and absolute number + (-(?P(?!(1080|720|480)[pi])\d+))? # "-" 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\d{1,3}))?[ ._-]*? + (?P(?!(1080|720|480)[pi])\d+) + (-(?P(?!(1080|720|480)[pi])\d+))?[ ._-]*? (?: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\d{3}))? # E02 + (?P(?!(1080|720|480)[pi])\d+) # E01 + (-(?P(?!(1080|720|480)[pi])\d+))? # E02 (v(?P[0-9]))? # v2 .*? # Separator and EOL ''') diff --git a/sickbeard/postProcessor.py b/sickbeard/postProcessor.py index fbe1057d..22c4ab3b 100644 --- a/sickbeard/postProcessor.py +++ b/sickbeard/postProcessor.py @@ -498,7 +498,7 @@ class PostProcessor(object): season = parse_result.season_number episodes = parse_result.episode_numbers - to_return = (parse_result.show, season, episodes, None) + to_return = (parse_result.show, season, episodes, parse_result.quality) self._finalize(parse_result) return to_return diff --git a/sickbeard/providers/generic.py b/sickbeard/providers/generic.py index 24d5c15a..4b0c1364 100644 --- a/sickbeard/providers/generic.py +++ b/sickbeard/providers/generic.py @@ -284,7 +284,7 @@ class GenericProvider: logger.log(u"Unable to parse the filename " + title + " into a valid episode", logger.WARNING) continue - quality = self.getQuality(item, parse_result.is_anime) + quality = parse_result.quality if not (self.show.air_by_date or self.show.sports): if search_mode == 'sponly' and len(parse_result.episode_numbers): diff --git a/sickbeard/tv.py b/sickbeard/tv.py index d31a3c61..85deba45 100644 --- a/sickbeard/tv.py +++ b/sickbeard/tv.py @@ -200,7 +200,7 @@ class TVShow(object): ep = None # if we get an anime get the real season and episode - if self.is_anime and not self.is_scene and absolute_number and not season and not episode: + if self.is_anime and absolute_number and not season and not episode: myDB = db.DBConnection() sql = "SELECT * FROM tv_episodes WHERE showid = ? and absolute_number = ? and season != 0" sqlResults = myDB.select(sql, [self.indexerid, absolute_number]) diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 10e2e9b3..b24899c8 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -2191,6 +2191,8 @@ class NewHomeAddShows: if not lang or lang == 'null': lang = "en" + search_term = search_term.encode('utf-8') + results = {} final_results = []