How to convert exporting code in anki?

'm using the latest version, and I found a problem with the code in the file C:\anki-venv\Lib\site-packages\anki\exporting.py.

I want to change it to the modified code as below, but I don’t know how to do it.

I’m not very good at coding, so I’d really appreciate it if you could explain the method in detail.

(existing)
mdir = self.col.media.dir()
self.col.close(downgrade=True)

(correction)
mdir = self.col.media.dir()
self.col.close(downgrade=True)
os.chdir(mdir)

Maybe the edited file wasn’t saved or instead of overwriting the existing exporting.py file it was accidentally saved as a new file, e.g. exporting.py.txt.

Maybe add a few print statements to verify that the code is being executed.

        mdir = self.col.media.dir()
        print('1:', os.getcwd())
        self.col.close(downgrade=True)
        print('2:', os.getcwd())
        os.chdir(mdir)
        print('3:', os.getcwd())

Once you start Anki from pip and export the collection, 1, 2 and 3 will be printed out to the console window.

1 Like

Bro.

as you said
mdir = self.col.media.dir()
self.col.close(downgrade=True)
os.chdir(mdir)

I changed the code, but the problem that the audio does not play after exporting the collection continues to occur.

What code is wrong?

Can you explain in detail how to do it again from the beginning with a video?

please help

I’ll repeat myself, but it’s just easier to temporarily use the add-on that I mentioned to my reply in PM a while ago. It pretty much does the same thing.

https://addon-docs.ankiweb.net/monkey-patching.html

What code is wrong?

I don’t have more ideas but if you do what I said in my previous reply, the output will look like this.

cmd_2J5otgWwNc

I forgot about it, but if you still want to run Anki via Python, you’ll also need to download mpv and add the full path to mpv.exe to the PATH environment variable, otherwise once you’ll try to review a card with sound you’ll receive a message, “Sound and video on cards will not function until mpv or mplayer is installed”.

The latest mpv build for Windows can be downloaded from https://sourceforge.net/projects/mpv-player-windows/files/64bit/ and added to the PATH env using something like this and reopening the Windows Command Prompt (cmd) after doing it.

Instead of the “System Variables” section, I think you can also use the “User Variables” by adding the “Path” variable yourself if it doesn’t exist.

2 Likes

So are you saying that it is better to use it temporarily as an addon?

Will this issue be resolved without addon in the next version?

Thanks for the quick reply.
I always feel grateful to you.

There’s no much difference. It just takes a bit more time to install everything and run Anki from Python and the black Command Prompt window will be always opened.

The issue will be fixed someday, maybe in the next version.

2 Likes

thank you bro.

I don’t know much about coding like you, but I can learn a lot with your help, thank you.

I live in Korea, and if you come to play, I will treat you to a delicious meal.

Really thankful!