media().writeData() filename formatting

Just wondering where I can find information about how filenames are formatted by media().writeData(). I understand the value it returns is a filename, so I assume it sanitises the string somehow. More to the point, is there a way to sanitise a string the same way without writing to media?

It’s all in the source code :slight_smile:

If it’s just a raw data, it’ll be formatted with its hash as its filename.

Otherwise, it’s quite complicated. Everyting is done in Rust and at the moment, as far I can see, is not exposed and can’t be used with Python.

Take a look at rslib/src/media/ The whole file with tests in the end is pretty much about filename formatting.

In Anki 2.1.15 it was done in Python. Take a look at


Thanks for the comprehensive and considerate response !