mirror of
https://github.com/moparisthebest/SickRage
synced 2024-11-16 06:15:09 -05:00
Fix for NameParser invalid show errors.
Fix for NameParserCache and RSSFeed Cache errors.
This commit is contained in:
parent
79f923dc9c
commit
fefcfa0952
@ -16,6 +16,8 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
|
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
@ -25,8 +27,10 @@ import shelve
|
|||||||
import sickbeard
|
import sickbeard
|
||||||
|
|
||||||
from sickbeard import logger, helpers, scene_numbering, common, exceptions, scene_exceptions, encodingKludge as ek
|
from sickbeard import logger, helpers, scene_numbering, common, exceptions, scene_exceptions, encodingKludge as ek
|
||||||
from sickbeard.exceptions import ex
|
from contextlib import closing
|
||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
|
from sickbeard.exceptions import ex
|
||||||
|
|
||||||
|
|
||||||
class NameParser(object):
|
class NameParser(object):
|
||||||
NORMAL_REGEX = 0
|
NORMAL_REGEX = 0
|
||||||
@ -138,7 +142,7 @@ class NameParser(object):
|
|||||||
result.show = helpers.get_show_by_name(result.series_name, useIndexer=self.useIndexers)
|
result.show = helpers.get_show_by_name(result.series_name, useIndexer=self.useIndexers)
|
||||||
|
|
||||||
if not result.show:
|
if not result.show:
|
||||||
return
|
break
|
||||||
|
|
||||||
result.score += 1
|
result.score += 1
|
||||||
|
|
||||||
@ -581,27 +585,31 @@ class ParseResult(object):
|
|||||||
class NameParserCache:
|
class NameParserCache:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.npc_cache_size = 200
|
self.npc_cache_size = 200
|
||||||
|
self.db_name = ek.ek(os.path.join, sickbeard.CACHE_DIR, 'name_parser_cache')
|
||||||
try:
|
|
||||||
self.npc = shelve.open(ek.ek(os.path.join, sickbeard.CACHE_DIR, 'name_parser_cache'))
|
|
||||||
except Exception as e:
|
|
||||||
logger.log(u"NameParser Cache error: " + ex(e), logger.ERROR)
|
|
||||||
raise
|
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
if getattr(self, "npc", None) is not None:
|
|
||||||
self.npc.close()
|
|
||||||
|
|
||||||
def add(self, name, parse_result):
|
def add(self, name, parse_result):
|
||||||
name = name.encode('utf-8', 'ignore')
|
name = name.encode('utf-8', 'ignore')
|
||||||
self.npc[str(name)] = parse_result
|
|
||||||
|
|
||||||
while len(self.npc.items()) > self.npc_cache_size:
|
try :
|
||||||
del self.npc.keys()[0]
|
with closing(shelve.open(self.db_name)) as npc:
|
||||||
|
npc[str(name)] = parse_result
|
||||||
|
|
||||||
|
while len(npc.items()) > self.npc_cache_size:
|
||||||
|
del npc.keys()[0]
|
||||||
|
except Exception as e:
|
||||||
|
logger.log(u"NameParser cache error: " + ex(e), logger.ERROR)
|
||||||
|
logger.log(u"NameParser cache corrupted, please delete " + self.db_name, logger.ERROR)
|
||||||
|
|
||||||
def get(self, name):
|
def get(self, name):
|
||||||
name = name.encode('utf-8', 'ignore')
|
name = name.encode('utf-8', 'ignore')
|
||||||
parse_result = self.npc.get(str(name), None)
|
|
||||||
|
try:
|
||||||
|
with closing(shelve.open(ek.ek(os.path.join, sickbeard.CACHE_DIR, 'name_parser_cache'))) as npc:
|
||||||
|
parse_result = npc.get(str(name), None)
|
||||||
|
except Exception as e:
|
||||||
|
logger.log(u"NameParser cache error: " + ex(e), logger.ERROR)
|
||||||
|
logger.log(u"NameParser cache corrupted, please delete " + self.db_name, logger.ERROR)
|
||||||
|
parse_result = None
|
||||||
|
|
||||||
if parse_result:
|
if parse_result:
|
||||||
logger.log("Using cached parse result for: " + name, logger.DEBUG)
|
logger.log("Using cached parse result for: " + name, logger.DEBUG)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import urllib
|
import urllib
|
||||||
import urlparse
|
import urlparse
|
||||||
@ -7,24 +9,23 @@ import sickbeard
|
|||||||
|
|
||||||
from sickbeard import logger
|
from sickbeard import logger
|
||||||
from sickbeard import encodingKludge as ek
|
from sickbeard import encodingKludge as ek
|
||||||
from sickbeard.exceptions import ex
|
from contextlib import closing
|
||||||
from lib.feedcache import cache
|
from lib.feedcache import cache
|
||||||
|
from sickbeard.exceptions import ex
|
||||||
|
|
||||||
|
|
||||||
class RSSFeeds:
|
class RSSFeeds:
|
||||||
def __init__(self, db_name):
|
def __init__(self, db_name):
|
||||||
try:
|
self.db_name = ek.ek(os.path.join, sickbeard.CACHE_DIR, db_name)
|
||||||
self.fs = shelve.open(ek.ek(os.path.join, sickbeard.CACHE_DIR, db_name))
|
|
||||||
self.fc = cache.Cache(self.fs)
|
|
||||||
except Exception, e:
|
|
||||||
logger.log(u"RSS error: " + ex(e), logger.ERROR)
|
|
||||||
raise
|
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
if getattr(self, "fs", None) is not None:
|
|
||||||
self.fs.close()
|
|
||||||
|
|
||||||
def clearCache(self, age=None):
|
def clearCache(self, age=None):
|
||||||
self.fc.purge(age)
|
try:
|
||||||
|
with closing(shelve.open(ek.ek(os.path.join, sickbeard.CACHE_DIR, self.db_name))) as fs:
|
||||||
|
fc = cache.Cache(fs)
|
||||||
|
fc.purge(age)
|
||||||
|
except Exception as e:
|
||||||
|
logger.log(u"RSS Error: " + ex(e), logger.ERROR)
|
||||||
|
logger.log(u"RSS cache file corrupted, please delete " + self.db_name, logger.ERROR)
|
||||||
|
|
||||||
def getFeed(self, url, post_data=None, request_headers=None):
|
def getFeed(self, url, post_data=None, request_headers=None):
|
||||||
parsed = list(urlparse.urlparse(url))
|
parsed = list(urlparse.urlparse(url))
|
||||||
@ -33,7 +34,14 @@ class RSSFeeds:
|
|||||||
if post_data:
|
if post_data:
|
||||||
url += urllib.urlencode(post_data)
|
url += urllib.urlencode(post_data)
|
||||||
|
|
||||||
feed = self.fc.fetch(url, False, False, request_headers)
|
try:
|
||||||
|
with closing(shelve.open(self.db_name)) as fs:
|
||||||
|
fc = cache.Cache(fs)
|
||||||
|
feed = fc.fetch(url, False, False, request_headers)
|
||||||
|
except Exception as e:
|
||||||
|
logger.log(u"RSS Error: " + ex(e), logger.ERROR)
|
||||||
|
logger.log(u"RSS cache file corrupted, please delete " + self.db_name, logger.ERROR)
|
||||||
|
feed = None
|
||||||
|
|
||||||
if not feed:
|
if not feed:
|
||||||
logger.log(u"RSS Error loading URL: " + url, logger.ERROR)
|
logger.log(u"RSS Error loading URL: " + url, logger.ERROR)
|
||||||
|
Loading…
Reference in New Issue
Block a user