diff --git a/couchpotato/api.py b/couchpotato/api.py index 934fa94a..b1dee1b3 100644 --- a/couchpotato/api.py +++ b/couchpotato/api.py @@ -6,8 +6,8 @@ api = Blueprint('api', __name__) api_docs = {} api_docs_missing = [] -def addApiView(route, func, static = False, docs = None): - api.add_url_rule(route + ('' if static else '/'), endpoint = route.replace('.', '::') if route else 'index', view_func = func) +def addApiView(route, func, static = False, docs = None, **kwargs): + api.add_url_rule(route + ('' if static else '/'), endpoint = route.replace('.', '::') if route else 'index', view_func = func, **kwargs) if docs: api_docs[route[4:] if route[0:4] == 'api.' else route] = docs else: diff --git a/couchpotato/core/plugins/movie/main.py b/couchpotato/core/plugins/movie/main.py index 314f7702..fd6cf383 100644 --- a/couchpotato/core/plugins/movie/main.py +++ b/couchpotato/core/plugins/movie/main.py @@ -270,7 +270,7 @@ class MoviePlugin(Plugin): 'movies': movies, }) - def add(self, params = {}, force_readd = True): + def add(self, params = {}, force_readd = True, search_after = True): library = fireEvent('library.add', single = True, attrs = params, update_after = False) @@ -316,7 +316,7 @@ class MoviePlugin(Plugin): movie_dict = m.to_dict(self.default_dict) - if force_readd or do_search: + if (force_readd or do_search) and search_after: fireEventAsync('searcher.single', movie_dict) return movie_dict diff --git a/couchpotato/core/plugins/v1importer/__init__.py b/couchpotato/core/plugins/v1importer/__init__.py new file mode 100644 index 00000000..40c1434b --- /dev/null +++ b/couchpotato/core/plugins/v1importer/__init__.py @@ -0,0 +1,6 @@ +from .main import V1Importer + +def start(): + return V1Importer() + +config = [] diff --git a/couchpotato/core/plugins/v1importer/form.html b/couchpotato/core/plugins/v1importer/form.html new file mode 100644 index 00000000..e27d1c72 --- /dev/null +++ b/couchpotato/core/plugins/v1importer/form.html @@ -0,0 +1,30 @@ + +
+ + + + + + + + + + + {% if message: %} + {{ message }} + {% else: %} + + {% endif %} + + \ No newline at end of file diff --git a/couchpotato/core/plugins/v1importer/main.py b/couchpotato/core/plugins/v1importer/main.py new file mode 100644 index 00000000..08f8ba98 --- /dev/null +++ b/couchpotato/core/plugins/v1importer/main.py @@ -0,0 +1,56 @@ +from couchpotato.api import addApiView +from couchpotato.core.event import fireEventAsync +from couchpotato.core.helpers.variable import getImdb +from couchpotato.core.logger import CPLog +from couchpotato.core.plugins.base import Plugin +from couchpotato.environment import Env +from flask.globals import request +from flask.helpers import url_for +import os + +log = CPLog(__name__) + + +class V1Importer(Plugin): + + def __init__(self): + addApiView('v1.import', self.fromOld, methods = ['GET', 'POST']) + + def fromOld(self): + + if request.method != 'POST': + return self.renderTemplate(__file__, 'form.html', url_for = url_for) + + file = request.files['old_db'] + + uploaded_file = os.path.join(Env.get('cache_dir'), 'v1_database.db') + + if os.path.isfile(uploaded_file): + os.remove(uploaded_file) + + file.save(uploaded_file) + + try: + import sqlite3 + conn = sqlite3.connect(uploaded_file) + + wanted = [] + + t = ('want',) + cur = conn.execute('SELECT status, imdb FROM Movie WHERE status=?', t) + for row in cur: + status, imdb = row + if getImdb(imdb): + wanted.append(imdb) + conn.close() + + wanted = set(wanted) + for imdb in wanted: + fireEventAsync('movie.add', {'identifier': imdb}, search_after = False) + + message = 'Successfully imported %s movie(s)' % len(wanted) + except Exception, e: + message = 'Failed: %s' % e + + return self.renderTemplate(__file__, 'form.html', url_for = url_for, message = message) + diff --git a/couchpotato/core/plugins/wizard/static/wizard.js b/couchpotato/core/plugins/wizard/static/wizard.js index e1e07a87..a4438cba 100644 --- a/couchpotato/core/plugins/wizard/static/wizard.js +++ b/couchpotato/core/plugins/wizard/static/wizard.js @@ -8,8 +8,28 @@ Page.Wizard = new Class({ headers: { 'welcome': { - 'title': 'Welcome to CouchPotato', - 'description': 'To get started, fill in each of the following settings as much as your can.' + 'title': 'Welcome to the new CouchPotato', + 'description': 'To get started, fill in each of the following settings as much as your can.