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.

58 lines
1.7 KiB

from couchpotato.api import addApiView
from couchpotato.core.event import fireEvent
14 years ago
from couchpotato.core.helpers.request import getParam, jsonified
from couchpotato.core.helpers.variable import isDict
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
14 years ago
from flask.globals import request
from flask.helpers import url_for
14 years ago
log = CPLog(__name__)
class Extension(Plugin):
def __init__(self):
addApiView('userscript', self.getExtension)
14 years ago
addApiView('userscript.add_via_url', self.addViaUrl)
def getExtension(self):
params = {
'includes': fireEvent('userscript.get_includes', merge = True),
'excludes': fireEvent('userscript.get_excludes', merge = True),
'version': self.getVersion(),
14 years ago
'host': '%s%suserscript.add_via_url/' % (request.host_url.rstrip('/'), url_for('api.index')),
}
14 years ago
return self.renderTemplate(__file__, 'template.js', **params)
def getVersion(self):
versions = fireEvent('userscript.get_version')
version = 0
for v in versions:
version += v
return version
14 years ago
def addViaUrl(self):
url = getParam('url')
return self.renderTemplate(__file__, 'iframe.html', url = url)
def getViaUrl(self):
14 years ago
url = getParam('url')
params = {
'url': url,
'movie': fireEvent('userscript.get_movie_via_url', url = url, single = True)
}
if not isDict(params['movie']):
log.error('Failed adding movie via url: %s' % url)
params['error'] = params['movie'] if params['movie'] else 'Failed getting movie info'
return jsonified(params)