You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.9 KiB

14 years ago
from couchpotato import get_session
from couchpotato.api import addApiView
14 years ago
from couchpotato.core.event import addEvent
14 years ago
from couchpotato.core.helpers.request import jsonified, getParams
14 years ago
from couchpotato.core.logger import CPLog
from couchpotato.core.providers.movie.base import MovieProvider
14 years ago
from couchpotato.core.settings.model import Movie
14 years ago
from flask.helpers import json
log = CPLog(__name__)
class CouchPotatoApi(MovieProvider):
apiUrl = 'http://couchpota.to/api/%s/'
14 years ago
def __init__(self):
addEvent('movie.release_date', self.releaseDate)
14 years ago
addApiView('movie.suggest', self.suggestView)
14 years ago
def releaseDate(self, imdb_id):
try:
data = self.urlopen((self.apiUrl % ('eta')) + (id + '/'))
14 years ago
dates = json.loads(data)
log.info('Found ETA for %s: %s' % (imdb_id, dates))
except Exception, e:
log.error('Error getting ETA for %s: %s' % (imdb_id, e))
14 years ago
return dates
def suggest(self, movies = [], ignore = []):
try:
data = self.urlopen((self.apiUrl % ('suggest')) + ','.join(movies) + '/' + ','.join(ignore) + '/')
14 years ago
suggestions = json.loads(data)
log.info('Found Suggestions for %s' % (suggestions))
except Exception, e:
log.error('Error getting suggestions for %s: %s' % (movies, e))
return suggestions
def suggestView(self):
params = getParams()
movies = params.get('movies')
ignore = params.get('ignore', [])
if not movies:
db = get_session()
active_movies = db.query(Movie).filter(Movie.status.has(identifier = 'active')).all()
movies = [x.library.identifier for x in active_movies]
14 years ago
suggestions = self.suggest(movies, ignore)
return jsonified({
'success': True,
'count': len(suggestions),
'suggestions': suggestions
})