Ask for old CouchPotato database in the wizard. closes #144
This commit is contained in:
+2
-2
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
from .main import V1Importer
|
||||
|
||||
def start():
|
||||
return V1Importer()
|
||||
|
||||
config = []
|
||||
@@ -0,0 +1,30 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="{{ url_for('web.static', filename='style/main.css') }}" type="text/css">
|
||||
<link rel="stylesheet" href="{{ url_for('web.static', filename='style/uniform.generic.css') }}" type="text/css">
|
||||
<link rel="stylesheet" href="{{ url_for('web.static', filename='style/uniform.css') }}" type="text/css">
|
||||
|
||||
<script type="text/javascript" src="{{ url_for('web.static', filename='scripts/library/mootools.js') }}"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
window.addEvent('domready', function(){
|
||||
if($('old_db'))
|
||||
$('old_db').addEvent('change', function(){
|
||||
$('form').submit();
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
{% if message: %}
|
||||
{{ message }}
|
||||
{% else: %}
|
||||
<form id="form" method="post" enctype="multipart/form-data">
|
||||
<input type="file" name="old_db" id="old_db" />
|
||||
</form>
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
@@ -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)
|
||||
|
||||
@@ -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. <br />Maybe first start with importing your movies from the previous CouchPotato',
|
||||
'content': new Element('div', {
|
||||
'styles': {
|
||||
'margin': '0 0 0 30px'
|
||||
}
|
||||
}).adopt(
|
||||
new Element('div', {
|
||||
'html': 'Select the <strong>data.db</strong>. It should be in your CouchPotato root directory.'
|
||||
}),
|
||||
self.import_iframe = new Element('iframe', {
|
||||
'styles': {
|
||||
'height': 40,
|
||||
'width': 300,
|
||||
'border': 0,
|
||||
'overflow': 'hidden'
|
||||
}
|
||||
})
|
||||
),
|
||||
'event': function(){
|
||||
self.import_iframe.set('src', Api.createUrl('v1.import'))
|
||||
}
|
||||
},
|
||||
'general': {
|
||||
'title': 'General',
|
||||
@@ -105,7 +125,7 @@ Page.Wizard = new Class({
|
||||
'text': self.headers[group].title
|
||||
}),
|
||||
self.headers[group].description ? new Element('span.description', {
|
||||
'text': self.headers[group].description
|
||||
'html': self.headers[group].description
|
||||
}) : null,
|
||||
self.headers[group].content ? self.headers[group].content : null
|
||||
).inject(form);
|
||||
@@ -132,6 +152,9 @@ Page.Wizard = new Class({
|
||||
})
|
||||
).inject(tabs);
|
||||
}
|
||||
|
||||
if(self.headers[group] && self.headers[group].event)
|
||||
self.headers[group].event.call()
|
||||
});
|
||||
|
||||
// Remove toggle
|
||||
|
||||
Reference in New Issue
Block a user