2014-06-29 10:05:33 +00:00
|
|
|
import urllib
|
|
|
|
import urlparse
|
|
|
|
import re
|
2015-06-06 02:23:39 +00:00
|
|
|
from feedparser import feedparser
|
2014-06-29 10:05:33 +00:00
|
|
|
import sickbeard
|
|
|
|
|
|
|
|
from sickbeard import logger
|
2014-07-15 05:53:32 +00:00
|
|
|
from sickbeard.exceptions import ex
|
2014-07-15 02:00:53 +00:00
|
|
|
|
2015-06-06 02:23:39 +00:00
|
|
|
def getFeed(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
|
2014-07-15 02:00:53 +00:00
|
|
|
|
2015-06-06 02:23:39 +00:00
|
|
|
if post_data:
|
|
|
|
url += urllib.urlencode(post_data)
|
2014-07-15 02:00:53 +00:00
|
|
|
|
2015-06-06 02:23:39 +00:00
|
|
|
try:
|
|
|
|
feed = feedparser.parse(url, False, False, request_headers)
|
2014-08-31 19:56:18 +00:00
|
|
|
|
2015-06-06 02:23:39 +00:00
|
|
|
if feed:
|
|
|
|
if 'entries' in feed:
|
|
|
|
return feed
|
|
|
|
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)
|
|
|
|
else:
|
|
|
|
logger.log(u'RSS error loading url: ' + url, logger.DEBUG)
|
2014-08-31 19:56:18 +00:00
|
|
|
|
2015-06-06 02:23:39 +00:00
|
|
|
except Exception as e:
|
|
|
|
logger.log(u'RSS error: ' + ex(e), logger.DEBUG)
|