mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
media importing
This commit is contained in:
parent
d7c58f8142
commit
54b8ee059f
2 changed files with 10 additions and 6 deletions
|
@ -240,9 +240,7 @@ insert into revlog values (?,?,?,?,?,?,?,?,?)""", revlog)
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
def _importMedia(self):
|
def _importMedia(self):
|
||||||
self.log.append(
|
self.src.media.copyTo(self.dst.media.dir())
|
||||||
_("%d media imported.") %
|
|
||||||
self.src.media.copyTo(self.dst.media.dir()))
|
|
||||||
|
|
||||||
# Post-import cleanup
|
# Post-import cleanup
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
import zipfile
|
import zipfile, simplejson, os
|
||||||
from anki.utils import tmpfile
|
from anki.utils import tmpfile
|
||||||
from anki.importing.anki2 import Anki2Importer
|
from anki.importing.anki2 import Anki2Importer
|
||||||
|
|
||||||
|
@ -11,9 +11,15 @@ class AnkiPackageImporter(Anki2Importer):
|
||||||
def run(self):
|
def run(self):
|
||||||
# extract the deck from the zip file
|
# extract the deck from the zip file
|
||||||
z = zipfile.ZipFile(self.file)
|
z = zipfile.ZipFile(self.file)
|
||||||
f = z.open("collection.anki2")
|
col = z.read("collection.anki2")
|
||||||
colpath = tmpfile(suffix=".anki2")
|
colpath = tmpfile(suffix=".anki2")
|
||||||
open(colpath, "w").write(f.read())
|
open(colpath, "wb").write(col)
|
||||||
# pass it to the anki2 importer
|
# pass it to the anki2 importer
|
||||||
self.file = colpath
|
self.file = colpath
|
||||||
Anki2Importer.run(self)
|
Anki2Importer.run(self)
|
||||||
|
# import media
|
||||||
|
media = simplejson.loads(z.read("media"))
|
||||||
|
for c, file in media.items():
|
||||||
|
path = os.path.join(self.col.media.dir(), file)
|
||||||
|
if not os.path.exists(path):
|
||||||
|
open(path, "wb").write(z.read(c))
|
||||||
|
|
Loading…
Reference in a new issue