mirror of
https://github.com/moparisthebest/SickRage
synced 2024-11-11 03:45:01 -05:00
14c354b551
Provider getURL and downloadResult functions now removed and replaced with ones from helpers.py to help slim the code down plus allow more better control over request sessions. Removed TVTumbler code. Fixed HDBits provider. Fixed config settings that were ment to be booleans but instead where set as str or int, should help resolve random html errors. XEM Refresh check re-coded. NameParser code for creating show object has been changed to only attempt at the very end once its found the bestMatch result, helps on resources and performance.
54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
from __future__ import with_statement
|
|
|
|
import os
|
|
import urllib
|
|
import urlparse
|
|
import re
|
|
import sickbeard
|
|
|
|
from sickbeard import logger
|
|
from sickbeard import encodingKludge as ek
|
|
from contextlib import closing
|
|
from sickbeard.exceptions import ex
|
|
from lib.feedcache import cache
|
|
from shove import Shove
|
|
|
|
|
|
class RSSFeeds:
|
|
def __init__(self, db_name):
|
|
self.db_name = ek.ek(os.path.join, sickbeard.CACHE_DIR, db_name + '.db')
|
|
|
|
def clearCache(self, age=None):
|
|
try:
|
|
with closing(Shove('sqlite:///' + self.db_name, compress=True)) as fs:
|
|
fc = cache.Cache(fs)
|
|
fc.purge(age)
|
|
except Exception as e:
|
|
logger.log(u"RSS cache error: " + ex(e), logger.DEBUG)
|
|
|
|
def getFeed(self, url, post_data=None, request_headers=None):
|
|
parsed = list(urlparse.urlparse(url))
|
|
parsed[2] = re.sub("/{2,}", "/", parsed[2]) # replace two or more / with one
|
|
|
|
if post_data:
|
|
url += urllib.urlencode(post_data)
|
|
|
|
try:
|
|
with closing(Shove('sqlite:///' + self.db_name, compress=True)) as fs:
|
|
fc = cache.Cache(fs)
|
|
feed = fc.fetch(url, False, False, request_headers)
|
|
|
|
if not feed or not feed.entries:
|
|
logger.log(u"RSS cache error loading url: " + url, logger.ERROR)
|
|
return
|
|
elif 'error' in feed.feed:
|
|
err_code = feed.feed['error']['code']
|
|
err_desc = feed.feed['error']['description']
|
|
|
|
logger.log(
|
|
u"RSS ERROR:[%s] CODE:[%s]" % (err_desc, err_code), logger.DEBUG)
|
|
return
|
|
|
|
return feed
|
|
except Exception as e:
|
|
logger.log(u"RSS cache error: " + ex(e), logger.DEBUG) |