1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-08-13 16:53:54 -04:00
SickRage/sickbeard/tvtumbler.py
echel0n 0d9fbc1ad7 Welcome to our SickBeard-TVRage Edition ...
This version of SickBeard uses both TVDB and TVRage to search and gather it's series data from allowing you to now have access to and download shows that you couldn't before because of being locked into only what TheTVDB had to offer.

Also this edition is based off the code we used in our XEM editon so it does come with scene numbering support as well as all the other features our XEM edition has to offer.

Please before using this with your existing database (sickbeard.db) please make a backup copy of it and delete any other database files such as cache.db and failed.db if present, we HIGHLY recommend starting out with no database files at all to make this a fresh start but the choice is at your own risk!

Enjoy!
2014-03-09 22:39:12 -07:00

48 lines
1.4 KiB
Python

'''
Created on Aug 26, 2013
Wrappers around tvtumbler access.
@author: dermot@buckley.ie
'''
import time
from sickbeard import helpers
from sickbeard import logger
try:
import json
except ImportError:
from lib import simplejson as json
UPDATE_INTERVAL = 432000 # 5 days
SHOW_LOOKUP_URL = 'http://show-api.tvtumbler.com/api/show'
_tvtumber_cache = {}
def show_info(indexer_id):
try:
cachedResult = _tvtumber_cache[str(indexer_id)]
if time.time() < (cachedResult['mtime'] + UPDATE_INTERVAL):
# cached result is still considered current, use it
return cachedResult['response']
# otherwise we just fall through to lookup
except KeyError:
pass # no cached value, just fall through to lookup
url = SHOW_LOOKUP_URL + '?indexer_id=' + str(indexer_id)
data = helpers.getURL(url, timeout=60) # give this a longer timeout b/c it may take a while
result = json.loads(data)
if not result:
logger.log(u"Empty lookup result -> failed to find show id", logger.DEBUG)
return None
if result['error']:
logger.log(u"Lookup failed: " + result['errorMessage'], logger.DEBUG)
return None
# result is good, store it for later
_tvtumber_cache[str(indexer_id)] = {'mtime': time.time(),
'response': result['show']}
return result['show']