anki-apkg-parser - nodejs helper for exploring Anki .apkg
files. You can unpack the deck and get list of notes, cards, media files, models. This library uses sqlite
as a dependency, so you can make any custom SQL query to get the data;
Installation guide. Coming soon...
... install 'anki-apkg-parser'
The library provides two classes Unpack
and Deck
Anki decks are compressed archives, so we should unpack it first using Unpack
class:
import { Unpack, Deck } from 'anki-apkg-parser';
const deckPath = './favorite-cards.apkg';
const outPath = './deck-folder';
try {
const unpack = new Unpack();
// pass the deck path and the output path for unpacking the deck
await unpack.unpack(deckPath, outPath);
}
...
Which files will you see after unpacking the deck?
0
,1
,2
- files with number names are media files (images, audio, video)collection.anki2
- old version of anki databasecollection.anki21
- more modern version of databasecollection.anki21b
- the latest databse versionmedia
- Associative list of media files. Their numbers and real names. (Protocol Buffer or json file)meta
- Meta data (Protocol Buffer or json file)
Quick usage of Deck
class:
import { Unpack, Deck } from 'anki-apkg-parser';
// create deck instance using path to unpacked deck
const outPath = './deck-folder';
const deck = new Deck(outPath);
try {
// open the database
const db = await deck.dbOpen();
// fetch list of all notes
await db.getNotes();
// fetch colleciton raw
await db.getCollection();
/**
* Anki deck contains sqlite databases
* so when you call dbOpen(), you will recieve an instance of sqlite library
* You are free to use any 'sqlite' api
*/
// make an SQL request by native sqlite api
await db.get('SELECT * FROM col');
}
...
TODO: descripbe this part
import { Unpack, Deck } from 'anki-apkg-parser';
const outPath = './deck-folder';
try {
const outPath = './deck-folder';
const deck = new Deck(outPath);
let db;
// get cards from anki2 db file
if (deck.anki2) db = await deck.anki2.open()
db.get('SELECT * FROM cards')
}
...