Ask for old CouchPotato database in the wizard. closes #144
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user