diff --git a/anki/importing/anki2.py b/anki/importing/anki2.py index c48197db3..eaa15e42b 100644 --- a/anki/importing/anki2.py +++ b/anki/importing/anki2.py @@ -240,9 +240,7 @@ insert into revlog values (?,?,?,?,?,?,?,?,?)""", revlog) ###################################################################### def _importMedia(self): - self.log.append( - _("%d media imported.") % - self.src.media.copyTo(self.dst.media.dir())) + self.src.media.copyTo(self.dst.media.dir()) # Post-import cleanup ###################################################################### diff --git a/anki/importing/apkg.py b/anki/importing/apkg.py index af0bdd7fa..c08ac25ab 100644 --- a/anki/importing/apkg.py +++ b/anki/importing/apkg.py @@ -2,7 +2,7 @@ # Copyright: Damien Elmes # 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.importing.anki2 import Anki2Importer @@ -11,9 +11,15 @@ class AnkiPackageImporter(Anki2Importer): def run(self): # extract the deck from the zip file z = zipfile.ZipFile(self.file) - f = z.open("collection.anki2") + col = z.read("collection.anki2") colpath = tmpfile(suffix=".anki2") - open(colpath, "w").write(f.read()) + open(colpath, "wb").write(col) # pass it to the anki2 importer self.file = colpath 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))