kerrickstaley / genanki

A Python 3 library for generating Anki decks
MIT License
1.99k stars 150 forks source link

Packaging issues with media files #48

Closed rubic closed 4 years ago

rubic commented 4 years ago

I've reviewed the prior issues and I don't think the problem is related to #46. Neither my sound files nor images appear when the .apkg file is loaded. I'm using genaki version 0.80.

ItalianModel = genanki.Model(
    1300703785,
    'Italian Model',
    fields=[
        {'name': 'Question'},
        {'name': 'Answer'},
        {'name': 'Image'},
        {'name': 'Audio'},
    ],
    templates=[
        {
            'name': 'Card 1',
            'qfmt': '{{Question}}<br><br>{{Image}}',
            'afmt': '{{FrontSide}}<hr id="answer">{{Answer}}<br>{{ Audio}}',
        },
    ],
)

ItalianDeck = genanki.Deck(
    1281791336,
    'My Italian Deck')

def build_anki_deck(*source):
    package = genanki.Package(ItalianDeck)
    for question, answer, image, mp3file in source:
        package.media_files.append(image)
        package.media_files.append(mp3file)
        note = genanki.Note(
            model=ItalianModel,
            fields=[
                question,
                answer,
                '<img src=\"{}\">'.format(image),
                "[sound:{}]".format(mp3file),
            ])
        ItalianDeck.add_note(note)
    genanki.Package(ItalianDeck).write_to_file('output.apkg')

The script is run from the same path where all the media files are located. I'm running Python 3.7.5 on Linux and the libraries are in a virtual environment.

rubic commented 4 years ago

Closing this ticket as the error was a dumb typo. Sorry for the bad report.