Browse Source

Use own cache

pull/2133/head
Ruud 12 years ago
parent
commit
08f44197f3
  1. 14
      couchpotato/core/providers/info/themoviedb/main.py

14
couchpotato/core/providers/info/themoviedb/main.py

@ -3,8 +3,6 @@ from couchpotato.core.helpers.encoding import simplifyString, toUnicode, ss
from couchpotato.core.helpers.variable import md5 from couchpotato.core.helpers.variable import md5
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from couchpotato.core.providers.info.base import MovieProvider from couchpotato.core.providers.info.base import MovieProvider
from couchpotato.environment import Env
import os
import tmdb3 import tmdb3
import traceback import traceback
@ -20,7 +18,7 @@ class TheMovieDb(MovieProvider):
# Configure TMDB settings # Configure TMDB settings
tmdb3.set_key(self.conf('api_key')) tmdb3.set_key(self.conf('api_key'))
tmdb3.set_cache(engine='file', filename=os.path.join(Env.get('cache_dir'), 'python', 'tmdb.cache')) tmdb3.set_cache('null')
def search(self, q, limit = 12): def search(self, q, limit = 12):
""" Find movie by name """ """ Find movie by name """
@ -76,7 +74,7 @@ class TheMovieDb(MovieProvider):
log.debug('Getting info: %s', cache_key) log.debug('Getting info: %s', cache_key)
movie = tmdb3.Movie(identifier) movie = tmdb3.Movie(identifier)
result = self.parseMovie(movie) result = self.parseMovie(movie)
self.setCache(cache_key, result) self.setCache(md5(ss(cache_key)), result)
except: except:
pass pass
@ -84,6 +82,11 @@ class TheMovieDb(MovieProvider):
def parseMovie(self, movie, with_titles = True): def parseMovie(self, movie, with_titles = True):
cache_key = 'tmdb.cache.%s' % movie.id
movie_data = self.getCache(cache_key)
if not movie_data:
# Images # Images
poster = self.getImage(movie, type = 'poster', size = 'poster') poster = self.getImage(movie, type = 'poster', size = 'poster')
poster_original = self.getImage(movie, type = 'poster', size = 'original') poster_original = self.getImage(movie, type = 'poster', size = 'original')
@ -131,6 +134,9 @@ class TheMovieDb(MovieProvider):
movie_data['titles'] = list(set(movie_data['titles'])) movie_data['titles'] = list(set(movie_data['titles']))
# Cache movie parsed
self.setCache(md5(ss(cache_key)), movie_data)
return movie_data return movie_data
def getImage(self, movie, type = 'poster', size = 'poster'): def getImage(self, movie, type = 'poster', size = 'poster'):

Loading…
Cancel
Save