mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-05 17:43:37 +00:00
Added new InvalidShowException to NameParser, Removed isGoodResult search check and now attached parsed result show objects and compare them against the show object we use to search with instead.
This commit is contained in:
parent
a3a3777d33
commit
7a95b0bb14
16 changed files with 70 additions and 56 deletions
|
@ -24,7 +24,7 @@ import os.path
|
|||
from sickbeard import db, common, helpers, logger
|
||||
|
||||
from sickbeard import encodingKludge as ek
|
||||
from sickbeard.name_parser.parser import NameParser, InvalidNameException
|
||||
from sickbeard.name_parser.parser import NameParser, InvalidNameException, InvalidShowException
|
||||
|
||||
MIN_DB_VERSION = 9 # oldest db version we support migrating from
|
||||
MAX_DB_VERSION = 38
|
||||
|
@ -270,7 +270,7 @@ class AddSizeAndSceneNameFields(InitialSchema):
|
|||
try:
|
||||
np = NameParser(False)
|
||||
parse_result = np.parse(cur_name)
|
||||
except InvalidNameException:
|
||||
except (InvalidNameException, InvalidShowException):
|
||||
continue
|
||||
|
||||
if parse_result.series_name and parse_result.season_number != None and parse_result.episode_numbers and parse_result.release_group:
|
||||
|
@ -295,7 +295,7 @@ class AddSizeAndSceneNameFields(InitialSchema):
|
|||
try:
|
||||
np = NameParser(False)
|
||||
parse_result = np.parse(ep_file_name)
|
||||
except InvalidNameException:
|
||||
except (InvalidNameException, InvalidShowException):
|
||||
continue
|
||||
|
||||
if not parse_result.release_group:
|
||||
|
|
|
@ -26,7 +26,7 @@ from sickbeard import search_queue
|
|||
from sickbeard import failed_history
|
||||
from sickbeard import scene_exceptions
|
||||
|
||||
from sickbeard.name_parser.parser import NameParser, InvalidNameException
|
||||
from sickbeard.name_parser.parser import NameParser, InvalidNameException, InvalidShowException
|
||||
|
||||
|
||||
class FailedProcessor(object):
|
||||
|
@ -62,6 +62,9 @@ class FailedProcessor(object):
|
|||
except InvalidNameException:
|
||||
self._log(u"Error: release name is invalid: " + releaseName, logger.WARNING)
|
||||
raise exceptions.FailedProcessingFailed()
|
||||
except InvalidShowException:
|
||||
self._log(u"Error: unable to parse release name " + releaseName + " into a valid show", logger.WARNING)
|
||||
raise exceptions.FailedProcessingFailed
|
||||
|
||||
logger.log(u"name_parser info: ", logger.DEBUG)
|
||||
logger.log(u" - " + str(parsed.series_name), logger.DEBUG)
|
||||
|
|
|
@ -28,20 +28,19 @@ from dateutil import parser
|
|||
|
||||
nameparser_lock = threading.Lock()
|
||||
|
||||
|
||||
class NameParser(object):
|
||||
ALL_REGEX = 0
|
||||
NORMAL_REGEX = 1
|
||||
SPORTS_REGEX = 2
|
||||
ANIME_REGEX = 3
|
||||
|
||||
def __init__(self, file_name=True, showObj=None, epObj=None, useIndexers=False, convert=False,
|
||||
def __init__(self, file_name=True, showObj=None, useIndexers=False, convert=False,
|
||||
naming_pattern=False):
|
||||
|
||||
self.file_name = file_name
|
||||
self.showList = sickbeard.showList or []
|
||||
self.useIndexers = useIndexers
|
||||
self.showObj = showObj
|
||||
self.epObj = epObj
|
||||
self.useIndexers = useIndexers
|
||||
self.convert = convert
|
||||
self.naming_pattern = naming_pattern
|
||||
|
||||
|
@ -121,7 +120,8 @@ class NameParser(object):
|
|||
if not name:
|
||||
return
|
||||
|
||||
if not self.showObj and not self.naming_pattern:
|
||||
self.showObj = None
|
||||
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 = '''(?:(?:\[.*?\])|(?:\d{3}[\.-]))*[ _\.]?(?P<series_name>.*?(?:[ ._-]((?!\d{4}\W\d\d\W\d\d\W)\d{4}))?)(?:(?:(?:[ ._-]+\d+)|(?:[ ._-]+s\d{2}))|(?:\W+(?:(?:S\d[\dE._ -])|(?:\d\d?x)|(?:\d{4}\W\d\d\W\d\d)|(?:(?:part|pt)[\._ -]?(?:\d|[ivx]))|Season\W+\d+\W+|E\d+\W+|(?:\d{1,3}.+\d{1,}[a-zA-Z]{2}\W+[a-zA-Z]{3,}\W+\d{4}.+))))'''
|
||||
show_pattern_alt = '''^(?P<series_name>.*?(?:[ ._-]((?!\d{4}\W\d\d\W\d\d\W)\d{4}))?)(?:(?:(?:[ ._-]+\d+)|(?:[ ._-]+s\d{2}))|(?:\W+(?:(?:S\d[\dE._ -])|(?:\d\d?x)|(?:\d{4}\W\d\d\W\d\d)|(?:(?:part|pt)[\._ -]?(?:\d|[ivx]))|Season\W+\d+\W+|E\d+\W+|(?:\d{1,3}.+\d{1,}[a-zA-Z]{2}\W+[a-zA-Z]{3,}\W+\d{4}.+))))'''
|
||||
|
@ -131,7 +131,7 @@ class NameParser(object):
|
|||
self.showObj = self._matchShowName(name, show_pattern_alt)
|
||||
|
||||
if not self.showObj:
|
||||
return
|
||||
raise InvalidShowException("Unable to parse " + name.encode(sickbeard.SYS_ENCODING, 'xmlcharrefreplace'))
|
||||
|
||||
regexMode = self.ALL_REGEX
|
||||
if self.showObj and self.showObj.is_anime:
|
||||
|
@ -523,7 +523,8 @@ class ParseResult(object):
|
|||
if self.show.is_anime and len(self.ab_episode_numbers):
|
||||
scene_season = scene_exceptions.get_scene_exception_by_name(self.series_name)[1]
|
||||
for epAbsNo in self.ab_episode_numbers:
|
||||
ab = scene_numbering.get_indexer_absolute_numbering(self.show.indexerid, self.show.indexer, epAbsNo, True, scene_season)
|
||||
ab = scene_numbering.get_indexer_absolute_numbering(self.show.indexerid, self.show.indexer, epAbsNo,
|
||||
True, scene_season)
|
||||
if ab:
|
||||
try:
|
||||
(s, e) = helpers.get_all_episodes_from_absolute_number(self.show, None, [ab])
|
||||
|
@ -620,7 +621,13 @@ class NameParserCache(object):
|
|||
logger.log("Using cached parse result for: " + name, logger.DEBUG)
|
||||
return self._previous_parsed[name]
|
||||
|
||||
|
||||
name_parser_cache = NameParserCache()
|
||||
|
||||
|
||||
class InvalidNameException(Exception):
|
||||
"The given name is not valid"
|
||||
|
||||
|
||||
class InvalidShowException(Exception):
|
||||
"The given name is not valid"
|
|
@ -23,7 +23,7 @@ import xml.etree.cElementTree as etree
|
|||
import xml.etree
|
||||
import re
|
||||
|
||||
from name_parser.parser import NameParser, InvalidNameException
|
||||
from name_parser.parser import NameParser, InvalidNameException, InvalidShowException
|
||||
|
||||
from sickbeard import logger, classes, helpers
|
||||
from sickbeard.common import Quality
|
||||
|
@ -118,6 +118,9 @@ def splitResult(result):
|
|||
except InvalidNameException:
|
||||
logger.log(u"Unable to parse the filename " + result.name + " into a valid episode", logger.WARNING)
|
||||
return False
|
||||
except InvalidShowException:
|
||||
logger.log(u"Unable to parse the filename " + result.name + " into a valid show", logger.WARNING)
|
||||
return False
|
||||
|
||||
# bust it up
|
||||
season = parse_result.season_number if parse_result.season_number != None else 1
|
||||
|
@ -137,6 +140,9 @@ def splitResult(result):
|
|||
except InvalidNameException:
|
||||
logger.log(u"Unable to parse the filename " + newNZB + " into a valid episode", logger.WARNING)
|
||||
return False
|
||||
except InvalidShowException:
|
||||
logger.log(u"Unable to parse the filename " + newNZB + " into a valid show", logger.WARNING)
|
||||
return False
|
||||
|
||||
# make sure the result is sane
|
||||
if (parse_result.season_number != None and parse_result.season_number != season) or (
|
||||
|
|
|
@ -40,7 +40,7 @@ from sickbeard import name_cache
|
|||
from sickbeard import encodingKludge as ek
|
||||
from sickbeard.exceptions import ex
|
||||
|
||||
from sickbeard.name_parser.parser import NameParser, InvalidNameException
|
||||
from sickbeard.name_parser.parser import NameParser, InvalidNameException, InvalidShowException
|
||||
|
||||
from lib import adba
|
||||
|
||||
|
@ -480,11 +480,11 @@ class PostProcessor(object):
|
|||
return to_return
|
||||
|
||||
# parse the name to break it into show name, season, and episode
|
||||
np = NameParser(file, useIndexers=True, convert=True)
|
||||
parse_result = np.parse(name)
|
||||
|
||||
# couldn't find this in our show list
|
||||
if not parse_result.show:
|
||||
try:
|
||||
np = NameParser(file, useIndexers=True, convert=True)
|
||||
parse_result = np.parse(name)
|
||||
except InvalidShowException:
|
||||
logger.log(u"Unable to parse the filename " + name + " into a valid show", logger.WARNING)
|
||||
return to_return
|
||||
|
||||
if parse_result.air_by_date:
|
||||
|
|
|
@ -28,7 +28,7 @@ from sickbeard import db, helpers, exceptions
|
|||
from sickbeard import encodingKludge as ek
|
||||
from sickbeard.exceptions import ex
|
||||
from sickbeard import logger
|
||||
from sickbeard.name_parser.parser import NameParser, InvalidNameException
|
||||
from sickbeard.name_parser.parser import NameParser, InvalidNameException, InvalidShowException
|
||||
from sickbeard import common
|
||||
|
||||
from sickbeard import failedProcessor
|
||||
|
@ -269,14 +269,14 @@ def validateDir(path, dirName, nzbNameOriginal, failed):
|
|||
try:
|
||||
NameParser().parse(video, cache_result=False)
|
||||
return True
|
||||
except InvalidNameException:
|
||||
except (InvalidNameException, InvalidShowException):
|
||||
pass
|
||||
|
||||
for dir in allDirs:
|
||||
try:
|
||||
NameParser().parse(dir, cache_result=False)
|
||||
return True
|
||||
except InvalidNameException:
|
||||
except (InvalidNameException, InvalidShowException):
|
||||
pass
|
||||
|
||||
if sickbeard.UNPACK:
|
||||
|
@ -287,7 +287,7 @@ def validateDir(path, dirName, nzbNameOriginal, failed):
|
|||
try:
|
||||
NameParser().parse(packed, cache_result=False)
|
||||
return True
|
||||
except InvalidNameException:
|
||||
except (InvalidNameException, InvalidShowException):
|
||||
pass
|
||||
|
||||
return False
|
||||
|
|
|
@ -33,7 +33,7 @@ from sickbeard import history
|
|||
|
||||
from sickbeard.common import DOWNLOADED, SNATCHED, SNATCHED_PROPER, Quality
|
||||
|
||||
from name_parser.parser import NameParser, InvalidNameException
|
||||
from name_parser.parser import NameParser, InvalidNameException, InvalidShowException
|
||||
|
||||
|
||||
class ProperFinder():
|
||||
|
@ -110,11 +110,11 @@ class ProperFinder():
|
|||
except InvalidNameException:
|
||||
logger.log(u"Unable to parse the filename " + curProper.name + " into a valid episode", logger.DEBUG)
|
||||
continue
|
||||
|
||||
if not parse_result.series_name:
|
||||
except InvalidShowException:
|
||||
logger.log(u"Unable to parse the filename " + curProper.name + " into a valid show", logger.WARNING)
|
||||
continue
|
||||
|
||||
if not parse_result.show:
|
||||
if not parse_result.series_name:
|
||||
continue
|
||||
|
||||
if not parse_result.episode_numbers:
|
||||
|
|
|
@ -36,7 +36,7 @@ from sickbeard import tvcache
|
|||
from sickbeard import encodingKludge as ek
|
||||
from sickbeard.exceptions import ex
|
||||
from lib.hachoir_parser import createParser
|
||||
from sickbeard.name_parser.parser import NameParser, InvalidNameException
|
||||
from sickbeard.name_parser.parser import NameParser, InvalidNameException, InvalidShowException
|
||||
from sickbeard.common import Quality
|
||||
|
||||
|
||||
|
@ -278,12 +278,16 @@ class GenericProvider:
|
|||
|
||||
# parse the file name
|
||||
try:
|
||||
myParser = NameParser(False, showObj=show, epObj=ep_obj, convert=True)
|
||||
myParser = NameParser(False, convert=True)
|
||||
parse_result = myParser.parse(title)
|
||||
except InvalidNameException:
|
||||
logger.log(u"Unable to parse the filename " + title + " into a valid episode", logger.WARNING)
|
||||
continue
|
||||
except InvalidShowException:
|
||||
logger.log(u"Unable to parse the filename " + title + " into a valid show", logger.WARNING)
|
||||
continue
|
||||
|
||||
showObj = parse_result.show
|
||||
quality = parse_result.quality
|
||||
release_group = parse_result.release_group
|
||||
|
||||
|
@ -360,11 +364,11 @@ class GenericProvider:
|
|||
epObj.append(show.getEpisode(actual_season, curEp))
|
||||
|
||||
result = self.getResult(epObj)
|
||||
result.show = showObj
|
||||
result.url = url
|
||||
result.name = title
|
||||
result.quality = quality
|
||||
result.release_group = release_group
|
||||
result.provider = self
|
||||
result.content = None
|
||||
|
||||
if len(epObj) == 1:
|
||||
|
|
|
@ -31,7 +31,7 @@ import urlparse
|
|||
import sickbeard
|
||||
import generic
|
||||
from sickbeard.common import Quality, cpu_presets
|
||||
from sickbeard.name_parser.parser import NameParser, InvalidNameException
|
||||
from sickbeard.name_parser.parser import NameParser, InvalidNameException, InvalidShowException
|
||||
from sickbeard import logger
|
||||
from sickbeard import tvcache
|
||||
from sickbeard import helpers
|
||||
|
@ -156,7 +156,7 @@ class KATProvider(generic.TorrentProvider):
|
|||
try:
|
||||
myParser = NameParser()
|
||||
parse_result = myParser.parse(fileName)
|
||||
except InvalidNameException:
|
||||
except (InvalidNameException, InvalidShowException):
|
||||
return None
|
||||
|
||||
logger.log(u"Season quality for " + title + " is " + Quality.qualityStrings[quality], logger.DEBUG)
|
||||
|
|
|
@ -29,8 +29,7 @@ import datetime
|
|||
import sickbeard
|
||||
import generic
|
||||
|
||||
from sickbeard.common import Quality, cpu_presets
|
||||
from sickbeard.name_parser.parser import NameParser, InvalidNameException
|
||||
from sickbeard.common import Quality
|
||||
from sickbeard import logger
|
||||
from sickbeard import tvcache
|
||||
from sickbeard import helpers
|
||||
|
|
|
@ -28,7 +28,7 @@ import datetime
|
|||
import sickbeard
|
||||
import generic
|
||||
from sickbeard.common import Quality, cpu_presets
|
||||
from sickbeard.name_parser.parser import NameParser, InvalidNameException
|
||||
from sickbeard.name_parser.parser import NameParser, InvalidNameException, InvalidShowException
|
||||
from sickbeard import db
|
||||
from sickbeard import classes
|
||||
from sickbeard import logger
|
||||
|
@ -153,7 +153,7 @@ class ThePirateBayProvider(generic.TorrentProvider):
|
|||
try:
|
||||
myParser = NameParser()
|
||||
parse_result = myParser.parse(fileName)
|
||||
except InvalidNameException:
|
||||
except (InvalidNameException, InvalidShowException):
|
||||
return None
|
||||
|
||||
logger.log(u"Season quality for " + title + " is " + Quality.qualityStrings[quality], logger.DEBUG)
|
||||
|
|
|
@ -328,9 +328,7 @@ def filterSearchResults(show, season, results):
|
|||
for curEp in results:
|
||||
# skip non-tv crap
|
||||
results[curEp] = filter(
|
||||
lambda x: show_name_helpers.filterBadReleases(x.name) and show_name_helpers.isGoodResult(x.name, show,
|
||||
season=season),
|
||||
results[curEp])
|
||||
lambda x: show_name_helpers.filterBadReleases(x.name) and x.show == show,results[curEp])
|
||||
|
||||
if curEp in foundResults:
|
||||
foundResults[curEp] += results[curEp]
|
||||
|
@ -455,10 +453,7 @@ def searchProviders(show, season, episodes, manualSearch=False):
|
|||
for curEp in searchResults:
|
||||
# skip non-tv crap
|
||||
searchResults[curEp] = filter(
|
||||
lambda x: show_name_helpers.filterBadReleases(x.name) and show_name_helpers.isGoodResult(x.name,
|
||||
show,
|
||||
season=season),
|
||||
searchResults[curEp])
|
||||
lambda x: show_name_helpers.filterBadReleases(x.name) and x.show == show, searchResults[curEp])
|
||||
|
||||
if curEp in foundResults:
|
||||
foundResults[provider.name][curEp] += searchResults[curEp]
|
||||
|
@ -547,10 +542,7 @@ def searchProviders(show, season, episodes, manualSearch=False):
|
|||
individualResults = nzbSplitter.splitResult(bestSeasonNZB)
|
||||
|
||||
individualResults = filter(
|
||||
lambda x: show_name_helpers.filterBadReleases(x.name) and show_name_helpers.isGoodResult(x.name,
|
||||
show,
|
||||
season=season),
|
||||
individualResults)
|
||||
lambda x: show_name_helpers.filterBadReleases(x.name) and x.show == show, individualResults)
|
||||
|
||||
for curResult in individualResults:
|
||||
if len(curResult.episodes) == 1:
|
||||
|
|
|
@ -28,7 +28,7 @@ from sickbeard.scene_exceptions import get_scene_exceptions
|
|||
from sickbeard import logger
|
||||
from sickbeard import db
|
||||
from sickbeard import encodingKludge as ek
|
||||
from name_parser.parser import NameParser, InvalidNameException
|
||||
from name_parser.parser import NameParser, InvalidNameException, InvalidShowException
|
||||
from lib.unidecode import unidecode
|
||||
from sickbeard.blackandwhitelist import BlackAndWhiteList
|
||||
|
||||
|
@ -52,6 +52,9 @@ def filterBadReleases(name):
|
|||
except InvalidNameException:
|
||||
logger.log(u"Unable to parse the filename " + name + " into a valid episode", logger.WARNING)
|
||||
return False
|
||||
except InvalidShowException:
|
||||
logger.log(u"Unable to parse the filename " + name + " into a valid show", logger.WARNING)
|
||||
return False
|
||||
|
||||
# if any of the bad strings are in the name then say no
|
||||
if sickbeard.IGNORE_WORDS:
|
||||
|
|
|
@ -29,7 +29,7 @@ import sickbeard
|
|||
|
||||
import xml.etree.cElementTree as etree
|
||||
|
||||
from name_parser.parser import NameParser, InvalidNameException
|
||||
from name_parser.parser import NameParser, InvalidNameException, InvalidShowException
|
||||
|
||||
from lib import subliminal
|
||||
|
||||
|
@ -436,7 +436,7 @@ class TVShow(object):
|
|||
parse_result = None
|
||||
np = NameParser(False)
|
||||
parse_result = np.parse(ep_file_name)
|
||||
except InvalidNameException:
|
||||
except (InvalidNameException, InvalidShowException):
|
||||
pass
|
||||
|
||||
if not ' ' in ep_file_name and parse_result and parse_result.release_group:
|
||||
|
@ -2072,7 +2072,7 @@ class TVEpisode(object):
|
|||
try:
|
||||
np = NameParser(name, naming_pattern=True)
|
||||
parse_result = np.parse(name)
|
||||
except InvalidNameException, e:
|
||||
except (InvalidNameException, InvalidShowException), e:
|
||||
logger.log(u"Unable to get parse release_group: " + ex(e), logger.DEBUG)
|
||||
return ''
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ from sickbeard.common import Quality
|
|||
from sickbeard import helpers, show_name_helpers
|
||||
from sickbeard.exceptions import MultipleShowObjectsException
|
||||
from sickbeard.exceptions import AuthException
|
||||
from name_parser.parser import NameParser, InvalidNameException
|
||||
from name_parser.parser import NameParser, InvalidNameException, InvalidShowException
|
||||
from sickbeard.rssfeeds import RSSFeeds
|
||||
|
||||
cache_lock = threading.Lock()
|
||||
|
@ -246,12 +246,11 @@ class TVCache():
|
|||
except InvalidNameException:
|
||||
logger.log(u"Unable to parse the filename " + name + " into a valid episode", logger.DEBUG)
|
||||
return None
|
||||
|
||||
if not parse_result or not parse_result.series_name:
|
||||
except InvalidShowException:
|
||||
logger.log(u"Unable to parse the filename " + name + " into a valid show", logger.WARNING)
|
||||
return None
|
||||
|
||||
if not parse_result.show:
|
||||
logger.log(u"No match for show: [" + parse_result.series_name + "], not caching ...", logger.DEBUG)
|
||||
if not parse_result or not parse_result.series_name:
|
||||
return None
|
||||
|
||||
season = episodes = None
|
||||
|
@ -359,6 +358,7 @@ class TVCache():
|
|||
logger.log(u"Found result " + title + " at " + url)
|
||||
|
||||
result = self.provider.getResult([epObj])
|
||||
result.show = showObj
|
||||
result.url = url
|
||||
result.name = title
|
||||
result.quality = curQuality
|
||||
|
|
|
@ -72,7 +72,7 @@ class SRWebServer(threading.Thread):
|
|||
|
||||
# Load the app
|
||||
self.app = Application([],
|
||||
debug=False,
|
||||
debug=True,
|
||||
gzip=True,
|
||||
xheaders=sickbeard.HANDLE_REVERSE_PROXY,
|
||||
cookie_secret='61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo='
|
||||
|
|
Loading…
Reference in a new issue