本文整理汇总了Python中name_parser.parser.NameParser类的典型用法代码示例。如果您正苦于以下问题:Python NameParser类的具体用法?Python NameParser怎么用?Python NameParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NameParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: filterBadReleases
def filterBadReleases(name):
"""
Filters out non-english and just all-around stupid releases by comparing them
to the resultFilters contents.
name: the release name to check
Returns: True if the release name is OK, False if it's bad.
"""
try:
fp = NameParser()
parse_result = fp.parse(name)
except InvalidNameException:
logger.log(u"Unable to parse the filename "+name+" into a valid episode", logger.WARNING)
return False
# if there's no info after the season info then assume it's fine
if not parse_result.extra_info:
return True
# if any of the bad strings are in the name then say no
for x in resultFilters:
if re.search('(^|[\W_])'+x+'($|[\W_])', parse_result.extra_info, re.I):
logger.log(u"Invalid scene release: "+name+" contains "+x+", ignoring it", logger.DEBUG)
return False
return True
示例2: _addCacheEntry
def _addCacheEntry(self, name, url, parse_result=None, indexer_id=0):
# check if we passed in a parsed result or should we try and create one
if not parse_result:
# create showObj from indexer_id if available
showObj=None
if indexer_id:
showObj = helpers.findCertainShow(sickbeard.showList, indexer_id)
try:
myParser = NameParser(showObj=showObj, convert=True)
parse_result = myParser.parse(name)
except InvalidNameException:
logger.log(u"Unable to parse the filename " + name + " into a valid episode", logger.DEBUG)
return None
except InvalidShowException:
logger.log(u"Unable to parse the filename " + name + " into a valid show", logger.DEBUG)
return None
if not parse_result or not parse_result.series_name:
return None
# if we made it this far then lets add the parsed result to cache for usager later on
season = episodes = None
if parse_result.is_air_by_date or parse_result.is_sports:
airdate = parse_result.air_date.toordinal() if parse_result.air_date else parse_result.sports_air_date.toordinal()
myDB = db.DBConnection()
sql_results = myDB.select(
"SELECT season, episode FROM tv_episodes WHERE showid = ? AND indexer = ? AND airdate = ?",
[parse_result.show.indexerid, parse_result.show.indexer, airdate])
if sql_results > 0:
season = int(sql_results[0]["season"])
episodes = [int(sql_results[0]["episode"])]
else:
season = parse_result.season_number if parse_result.season_number else 1
episodes = parse_result.episode_numbers
if season and episodes:
# store episodes as a seperated string
episodeText = "|" + "|".join(map(str, episodes)) + "|"
# get the current timestamp
curTimestamp = int(time.mktime(datetime.datetime.today().timetuple()))
# get quality of release
quality = parse_result.quality
if not isinstance(name, unicode):
name = unicode(name, 'utf-8', 'replace')
# get release group
release_group = parse_result.release_group
logger.log(u"Added RSS item: [" + name + "] to cache: [" + self.providerID + "]", logger.DEBUG)
return [
"INSERT OR IGNORE INTO [" + self.providerID + "] (name, season, episodes, indexerid, url, time, quality, release_group) VALUES (?,?,?,?,?,?,?,?)",
[name, season, episodeText, parse_result.show.indexerid, url, curTimestamp, quality, release_group]]
示例3: filterBadReleases
def filterBadReleases(name, lang="en"):
try:
fp = NameParser()
parse_result = fp.parse(name)
except InvalidNameException:
logger.log(u"Unable to parse the filename "+name+" into a valid episode", logger.WARNING)
return False
# exclude language exceptions from filters
lResultFilters = [f for f in resultFilters]
if lang in filterExceptions and filterExceptions[lang]:
for exception in filterExceptions[lang]:
if exception in lResultFilters:
lResultFilters.remove(exception)
# if there's no info after the season info then assume it's fine, unless there is a whitelist for this language
if not parse_result.extra_info and not lang in requiredFilters:
return True
# if any of the bad strings are in the name then say no
for x in lResultFilters:
if re.search('(^|[\W_])'+x+'($|[\W_])', parse_result.extra_info, re.I):
logger.log(u"Invalid scene release: "+name+" contains "+x+", ignoring it", logger.DEBUG)
return False
# if whitelist exists for language, allow only releases containing a whitelisted word
if lang in requiredFilters and requiredFilters[lang]:
for x in requiredFilters[lang]:
if re.search('(^|[\W_])'+x+'($|[\W_])', parse_result.extra_info, re.I):
return True
logger.log(u"Invalid scene release: "+name+" doesn't contain any of the words "+str(requiredFilters[lang])+", ignoring it", logger.DEBUG)
return False
return True
示例4: filterBadReleases
def filterBadReleases(name):
"""
Filters out non-english and just all-around stupid releases by comparing them
to the resultFilters contents.
name: the release name to check
Returns: True if the release name is OK, False if it's bad.
"""
try:
fp = NameParser()
parse_result = fp.parse(name)
except InvalidNameException:
logger.log(u"Unable to parse the filename " + name + " into a valid episode", logger.WARNING)
return False
# if any of the bad strings are in the name then say no
if sickbeard.IGNORE_WORDS:
resultFilters.extend(sickbeard.IGNORE_WORDS.split(','))
filters = [re.compile('(^|[\W_])%s($|[\W_])' % filter.strip(), re.I) for filter in resultFilters]
for regfilter in filters:
if regfilter.search(name):
logger.log(u"Invalid scene release: " + name + " contains pattern: " + regfilter.pattern + ", ignoring it", logger.DEBUG)
return False
return True
示例5: filterBadReleases
def filterBadReleases(name, show):
"""
Filters out non-english and just all-around stupid releases by comparing them
to the resultFilters contents.
name: the release name to check
Returns: True if the release name is OK, False if it's bad.
"""
try:
fp = NameParser()
parse_result = fp.parse(name)
except InvalidNameException:
logger.log(u"Unable to parse the filename "+name+" into a valid episode", logger.WARNING)
return False
#if language not english, search for mandatory, else add other languages to ignore list
if show.lang != "en":
mandatory = [(langCodes[show.lang])]
if langCodes[show.lang] in resultFilters:
resultFilters.remove(langCodes[show.lang])
logger.log(u"Language for \""+show.name+"\" is "+show.lang+" so im looking for \""+langCodes[show.lang]+"\" in release names", logger.DEBUG)
elif show.lang == "en":
for key in langCodes:
if not langCodes[key] in resultFilters:
resultFilters.append(langCodes[key])
mandatory = []
logger.log(u"Language for \""+show.name+"\" is "+show.lang, logger.DEBUG)
# use the extra info and the scene group to filter against
check_string = ''
if parse_result.extra_info:
check_string = parse_result.extra_info
if parse_result.release_group:
if check_string:
check_string = check_string + '-' + parse_result.release_group
else:
check_string = parse_result.release_group
# if there's no info after the season info then assume it's fine
if not check_string:
return True
# if any of the bad strings are in the name then say no
for x in resultFilters + sickbeard.IGNORE_WORDS.split(','):
if re.search('(^|[\W_])'+x+'($|[\W_])', check_string, re.I):
logger.log(u"Invalid scene release: "+name+" contains "+x+", ignoring it", logger.DEBUG)
return False
# if every of the mandatory words are in there, say yes
if mandatory:
for x in mandatory:
if not re.search('(^|[\W_])'+x+'($|[\W_])', check_string, re.I):
logger.log(u"Mandatory string not found: "+name+" doesnt contains "+x+", ignoring it", logger.DEBUG)
return False
return True
示例6: _addCacheEntry
def _addCacheEntry(self, name, url, quality=None):
cacheDB = self._getDB()
season = None
episodes = None
# if we don't have complete info then parse the filename to get it
try:
myParser = NameParser(0)
parse_result = myParser.parse(name).convert()
except InvalidNameException:
logger.log(u"Unable to parse the filename " + name + " into a valid episode", logger.DEBUG)
return None
if not parse_result:
logger.log(u"Giving up because I'm unable to parse this name: " + name, logger.DEBUG)
return None
if not parse_result.series_name:
logger.log(u"No series name retrieved from " + name + ", unable to cache it", logger.DEBUG)
return None
if not parse_result.show:
logger.log(u"Couldn't find a show in our databases matching " + name + ", unable to cache it", logger.DEBUG)
return None
try:
myDB = db.DBConnection()
if parse_result.show.air_by_date:
airdate = parse_result.sports_event_date.toordinal() if parse_result.show.sports else parse_result.air_date.toordinal()
sql_results = myDB.select("SELECT season, episode FROM tv_episodes WHERE showid = ? AND airdate = ?",
[parse_result.show.indexerid, airdate])
if sql_results > 0:
season = int(sql_results[0]["season"])
episodes = [int(sql_results[0]["episode"])]
else:
season = parse_result.season_number
episodes = parse_result.episode_numbers
if season and episodes:
# store episodes as a seperated string
episodeText = "|" + "|".join(map(str, episodes)) + "|"
# get the current timestamp
curTimestamp = int(time.mktime(datetime.datetime.today().timetuple()))
# get quality of release
if quality is None:
quality = Quality.sceneQuality(name)
if not isinstance(name, unicode):
name = unicode(name, 'utf-8')
cacheDB.action(
"INSERT INTO [" + self.providerID + "] (name, season, episodes, indexerid, url, time, quality) VALUES (?,?,?,?,?,?,?)",
[name, season, episodeText, parse_result.show.indexerid, url, curTimestamp, quality])
except:
return
示例7: _addCacheEntry
def _addCacheEntry(self, name, url, quality=None):
try:
myParser = NameParser(convert=True)
parse_result = myParser.parse(name)
except InvalidNameException:
logger.log(u"Unable to parse the filename " + name + " into a valid episode", logger.DEBUG)
return None
except InvalidShowException:
logger.log(u"Unable to parse the filename " + name + " into a valid show", logger.DEBUG)
return None
if not parse_result or not parse_result.series_name:
return None
season = episodes = None
if parse_result.air_by_date or parse_result.sports:
airdate = parse_result.air_date.toordinal() if parse_result.air_date else parse_result.sports_event_date.toordinal()
myDB = db.DBConnection()
sql_results = myDB.select(
"SELECT season, episode FROM tv_episodes WHERE showid = ? AND indexer = ? AND airdate = ?",
[parse_result.show.indexerid, parse_result.show.indexer, airdate])
if sql_results > 0:
season = int(sql_results[0]["season"])
episodes = [int(sql_results[0]["episode"])]
else:
season = parse_result.season_number if parse_result.season_number != None else 1
episodes = parse_result.episode_numbers
if season and episodes:
# store episodes as a seperated string
episodeText = "|" + "|".join(map(str, episodes)) + "|"
# get the current timestamp
curTimestamp = int(time.mktime(datetime.datetime.today().timetuple()))
# get quality of release
if quality is None:
quality = Quality.sceneQuality(name, parse_result.is_anime)
if not isinstance(name, unicode):
name = unicode(name, 'utf-8')
# get release group
release_group = parse_result.release_group
logger.log(u"Added RSS item: [" + name + "] to cache: [" + self.providerID + "]", logger.DEBUG)
return [
"INSERT OR IGNORE INTO [" + self.providerID + "] (name, season, episodes, indexerid, url, time, quality, release_group) VALUES (?,?,?,?,?,?,?,?)",
[name, season, episodeText, parse_result.show.indexerid, url, curTimestamp, quality, release_group]]
示例8: _addCacheEntry
def _addCacheEntry(self, name, url, parse_result=None, indexer_id=0):
# check if we passed in a parsed result or should we try and create one
if not parse_result:
# create showObj from indexer_id if available
showObj=None
if indexer_id:
showObj = helpers.findCertainShow(sickbeard.showList, indexer_id)
try:
myParser = NameParser(showObj=showObj, convert=True)
parse_result = myParser.parse(name)
except InvalidNameException:
logger.log(u'Unable to parse the filename ' + name + ' into a valid episode', logger.DEBUG)
return None
except InvalidShowException:
logger.log(u'Unable to parse the filename ' + name + ' into a valid show', logger.DEBUG)
return None
if not parse_result or not parse_result.series_name:
return None
# if we made it this far then lets add the parsed result to cache for usager later on
season = parse_result.season_number if parse_result.season_number else 1
episodes = parse_result.episode_numbers
if season and episodes:
# store episodes as a seperated string
episodeText = '|' + '|'.join(map(str, episodes)) + '|'
# get the current timestamp
curTimestamp = int(time.mktime(datetime.datetime.today().timetuple()))
# get quality of release
quality = parse_result.quality
if not isinstance(name, unicode):
name = unicode(name, 'utf-8', 'replace')
# get release group
release_group = parse_result.release_group
# get version
version = parse_result.version
logger.log(u'Added RSS item: [' + name + '] to cache: [' + self.providerID + ']', logger.DEBUG)
return [
'INSERT OR IGNORE INTO provider_cache (provider, name, season, episodes, indexerid, url, time, quality, release_group, version) VALUES (?,?,?,?,?,?,?,?,?,?)',
[self.providerID, name, season, episodeText, parse_result.show.indexerid, url, curTimestamp, quality, release_group, version]]
示例9: _addCacheEntry
def _addCacheEntry(self, name, url, parse_result=None, indexer_id=0):
# check if we passed in a parsed result or should we try and create one
if not parse_result:
# create showObj from indexer_id if available
showObj = None
if indexer_id:
showObj = helpers.findCertainShow(sickbeard.showList, indexer_id)
try:
myParser = NameParser(showObj=showObj)
parse_result = myParser.parse(name)
except InvalidNameException:
logger.log(u"Unable to parse the filename " + name + " into a valid episode", logger.DEBUG)
return None
except InvalidShowException:
logger.log(u"Unable to parse the filename " + name + " into a valid show", logger.DEBUG)
return None
if not parse_result or not parse_result.series_name:
return None
# if we made it this far then lets add the parsed result to cache for usager later on
season = parse_result.season_number if parse_result.season_number else 1
episodes = parse_result.episode_numbers
if season and episodes:
# store episodes as a seperated string
episodeText = "|" + "|".join(map(str, episodes)) + "|"
# get the current timestamp
curTimestamp = int(time.mktime(datetime.datetime.today().timetuple()))
# get quality of release
quality = parse_result.quality
name = ss(name)
# get release group
release_group = parse_result.release_group
# get version
version = parse_result.version
logger.log(u"Added RSS item: [" + name + "] to cache: [" + self.providerID + "]", logger.DEBUG)
return [
"INSERT OR IGNORE INTO [" + self.providerID + "] (name, season, episodes, indexerid, url, time, quality, release_group, version) VALUES (?,?,?,?,?,?,?,?,?)",
[name, season, episodeText, parse_result.show.indexerid, url, curTimestamp, quality, release_group, version]]
示例10: filterBadReleases
def filterBadReleases(name,showLang=u"en"):
"""
Filters out non-english and just all-around stupid releases by comparing them
to the resultFilters contents.
name: the release name to check
Returns: True if the release name is OK, False if it's bad.
"""
additionalFilters = []
if showLang == u"en":
additionalFilters.append("dub(bed)?")
try:
fp = NameParser()
parse_result = fp.parse(name)
except InvalidNameException:
logger.log(u"Unable to parse the filename "+name+" into a valid episode", logger.WARNING)
return False
# use the extra info and the scene group to filter against
check_string = ''
if parse_result.extra_info:
check_string = parse_result.extra_info
if parse_result.release_group:
if check_string:
check_string = check_string + '-' + parse_result.release_group
else:
check_string = parse_result.release_group
# if there's no info after the season info then assume it's fine
if not check_string:
check_string = name
# if any of the bad strings are in the name then say no
if sickbeard.IGNORE_WORDS == "":
ignore_words="ztreyfgut"
else:
ignore_words=sickbeard.IGNORE_WORDS
for x in resultFilters + ignore_words.split(',') + additionalFilters:
if x == showLanguages.get(showLang):
continue
if re.search('(^|[\W_])'+x+'($|[\W_])', check_string, re.I):
logger.log(u"Invalid scene release: "+name+" contains "+x+", ignoring it", logger.DEBUG)
return False
return True
示例11: filterBadReleases
def filterBadReleases(name):
"""
Filters out non-english and just all-around stupid releases by comparing them
to the resultFilters contents.
name: the release name to check
Returns: True if the release name is OK, False if it's bad.
"""
try:
fp = NameParser()
parse_result = fp.parse(name)
except InvalidNameException:
logger.log(u"Unable to parse the filename "+name+" into a valid episode", logger.WARNING)
return False
# use the extra info and the scene group to filter against
check_string = ''
if parse_result.extra_info:
check_string = parse_result.extra_info
if parse_result.release_group:
if check_string:
check_string = check_string + '-' + parse_result.release_group
else:
check_string = parse_result.release_group
# if there's no info after the season info then assume it's fine
if not check_string:
return True
# if any of the bad strings are in the name then say no
for x in resultFilters + sickbeard.IGNORE_WORDS.split(','):
if re.search('(^|[\W_])'+x+'($|[\W_])', check_string, re.I):
logger.log(u"Invalid scene release: "+name+" contains "+x+", ignoring it", logger.DEBUG)
return False
# if every of the mandatory words are in there, say yes
for x in mandatory:
if not re.search('(^|[\W_])'+x+'($|[\W_])', check_string, re.I):
logger.log(u"Mandatory string not found: "+name+" doesnt contains "+x+", ignoring it", logger.DEBUG)
return False
return True
示例12: filterByRequiredWordsReleases
def filterByRequiredWordsReleases(name, requiredWords):
"""
Filters out non-english and just all-around stupid releases by comparing them
to the resultFilters contents.
name: the release name to check
Returns: True if the release name is OK, False if it's bad.
"""
try:
fp = NameParser()
parse_result = fp.parse(name)
except InvalidNameException:
logger.log(u"Unable to parse the filename "+name+" into a valid episode", logger.WARNING)
return False
# use the extra info and the scene group to filter against
check_string = ''
if parse_result.extra_info:
check_string = parse_result.extra_info
if parse_result.release_group:
if check_string:
check_string = check_string + '-' + parse_result.release_group
else:
check_string = parse_result.release_group
# if there's no info after the season info then assume it's fine
if not check_string:
return True
# if any of the bad strings are in the name then say no
logger.log(u"filtered requiredWords", logger.DEBUG)
if ( requiredWords != ""):
for x in requiredWords.split(','):
if re.search('(^|[\W_])'+x+'($|[\W_])', check_string, re.I):
logger.log(u"This scene release: "+name+" contains "+x+", add it", logger.DEBUG)
return True
logger.log(u"Invalid scene release: "+name+" not contains, ignore it", logger.DEBUG)
return False
return True
示例13: filterBadReleases
def filterBadReleases(name):
try:
fp = NameParser()
parse_result = fp.parse(name)
except InvalidNameException:
logger.log(u"Unable to parse the filename "+name+" into a valid episode", logger.WARNING)
return False
# if there's no info after the season info then assume it's fine
if not parse_result.extra_info:
return True
# if any of the bad strings are in the name then say no
for x in resultFilters:
if re.search('(^|[\W_])'+x+'($|[\W_])', parse_result.extra_info, re.I):
logger.log(u"Invalid scene release: "+name+" contains "+x+", ignoring it", logger.DEBUG)
return False
return True
示例14: filterBadReleases
def filterBadReleases(name):
"""
Filters out non-english and just all-around stupid releases by comparing them
to the resultFilters contents.
name: the release name to check
Returns: True if the release name is OK, False if it's bad.
"""
try:
fp = NameParser()
parse_result = fp.parse(name)
except InvalidNameException:
logger.log(u"Unable to parse the filename " + name + " into a valid episode", logger.WARNING)
return False
# # use the extra info and the scene group to filter against
# check_string = ''
# if parse_result.extra_info:
# check_string = parse_result.extra_info
# if parse_result.release_group:
# if check_string:
# check_string = check_string + '-' + parse_result.release_group
# else:
# check_string = parse_result.release_group
#
# # if there's no info after the season info then assume it's fine
# if not check_string:
# return True
# if any of the bad strings are in the name then say no
for ignore_word in resultFilters + sickbeard.IGNORE_WORDS.split(','):
ignore_word = ignore_word.strip()
if ignore_word:
if re.search('(^|[\W_])' + ignore_word + '($|[\W_])', name, re.I):
logger.log(u"Invalid scene release: " + name + " contains " + ignore_word + ", ignoring it", logger.DEBUG)
return False
return True
示例15: _addCacheEntry
def _addCacheEntry(self, name, url, quality=None):
indexerid = None
in_cache = False
# if we don't have complete info then parse the filename to get it
try:
myParser = NameParser()
parse_result = myParser.parse(name).convert()
except InvalidNameException:
logger.log(u"Unable to parse the filename " + name + " into a valid episode", logger.DEBUG)
return None
if not parse_result:
logger.log(u"Giving up because I'm unable to parse this name: " + name, logger.DEBUG)
return None
if not parse_result.series_name:
logger.log(u"No series name retrieved from " + name + ", unable to cache it", logger.DEBUG)
return None
cacheResult = sickbeard.name_cache.retrieveNameFromCache(parse_result.series_name)
if cacheResult:
in_cache = True
indexerid = int(cacheResult)
if not indexerid:
showResult = helpers.searchDBForShow(parse_result.series_name)
if showResult:
indexerid = int(showResult[0])
showObj = None
if indexerid:
showObj = helpers.findCertainShow(sickbeard.showList, indexerid)
if not showObj:
logger.log(u"No match for show: [" + parse_result.series_name + "], not caching ...", logger.DEBUG)
return None
season = episodes = None
if parse_result.air_by_date or parse_result.sports:
myDB = db.DBConnection()
airdate = parse_result.air_date.toordinal() or parse_result.sports_event_date.toordinal()
sql_results = myDB.select(
"SELECT season, episode FROM tv_episodes WHERE showid = ? AND indexer = ? AND airdate = ?",
[indexerid, showObj.indexer, airdate])
if sql_results > 0:
season = int(sql_results[0]["season"])
episodes = [int(sql_results[0]["episode"])]
else:
season = parse_result.season_number if parse_result.season_number != None else 1
episodes = parse_result.episode_numbers
if season and episodes:
# store episodes as a seperated string
episodeText = "|" + "|".join(map(str, episodes)) + "|"
# get the current timestamp
curTimestamp = int(time.mktime(datetime.datetime.today().timetuple()))
# get quality of release
if quality is None:
quality = Quality.sceneQuality(name)
if not isinstance(name, unicode):
name = unicode(name, 'utf-8')
logger.log(u"Added RSS item: [" + name + "] to cache: [" + self.providerID + "]", logger.DEBUG)
if not in_cache:
sickbeard.name_cache.addNameToCache(parse_result.series_name, indexerid)
return [
"INSERT INTO [" + self.providerID + "] (name, season, episodes, indexerid, url, time, quality) VALUES (?,?,?,?,?,?,?)",
[name, season, episodeText, indexerid, url, curTimestamp, quality]]