@Danika_Dakika
If you’re using the Play Store version of AnkiDroid – and you are running a recent version of Android – you no longer have outside access to your collection.media directory. Can you reach it with this other sync process?
I’m using AnkiDroid version 2.20.1 which I downloaded from F-Droid: https://f-droid.org/en/packages/com.ichi2.anki/ . I assume this version is the same as the one available in Play Store.
I have changed the default directory AnkiDroid to a path in my external SD card. In Settings > Advanced, I set “AnkiDroid directory” to /storage/708B-831D/anki-data/test-1/
. Since it is a directory in my SD card, I can edit/add/remove files within that directory.
I just confirmed this by creating two files in my desktop computer, and transfer them from my desktop computer to my Android phone using rsync
(I started a SSH server in my Android phone using Termux). When the transfer process finished, and I showed the back of the card which used image my-image-1.jpg
in AnkiDroid, the image was the one I last sent using rsync
.
$ convert wizard: /tmp/wizard.jpg
$ rsync -Psavv /tmp/wizard.jpg phone-primary:/storage/708B-831D/anki-data/test-1/collection.media/my-image-1.jpg
$ convert netscape: /tmp/netscape.jpg
$ rsync -Psavv /tmp/netscape.jpg phone-primary:/storage/708B-831D/anki-data/test-1/collection.media/my-image-1.jpg
Because I can reach that directory using rsync
, I will be able to reach that directory using Syncthing.
Assuming that you’d turn off media syncing on both devices so you don’t have to sync everything twice (or have the processes fighting over which is the correct version of your media file), you will no longer have a copy of your media on AnkiWeb.
Thanks. I didn’t think of this. I forgot to mention that I’m using a self-hosted sync server, but your comment is still valid for collection.media
that exists in the directory that have the files of the server (in my desktop computer, it is ~/.syncserver/
). If I plan to use Syncthing, I’ll have to turn off “Fetch media on sync” so that syncing by AnkiDroid and Syncthing doesn’t conflict with each other.
Does that need to be kept up-to-date via sync as well or does each app manage that separately? If you aren’t using AnkiWeb for your media sync process, will it be kept up-to-date?
Those are good questions. I thought that no file outside collection.media
referred to files in those directories, but I just learned that collection.media.db
and collection.media.db2
also exist. Perhaps, those databases contain the files that are being used in flashcards, so as to avoid iterating through all fields in all cards to find unused media files (which Anki Desktop might be able to do by simply by reading collection.media.db
). I inspected the source code and I found this code which calls _backend.check_media
, but I couldn’t find a method called check_media
in _backend
(permalink), so I couldn’t confirm whether collection.media.db
is read when pressing the “Delete Unused” button in “Check Media”.
A related fact: In my Android phone, the file is called collection.media.db
.
$ ssh phone-primary ls -la /storage/708B-831D/anki-data/test-1/
total 768
-rwxrwx--- 1 root everybody 0 Apr 23 15:00 .nomedia
drwxrwx--- 2 root everybody 131072 Apr 23 15:00 backup
-rwxrwx--- 1 root everybody 139264 Apr 23 15:00 collection.anki2
-rwxrwx--- 1 root everybody 98912 Apr 23 15:01 collection.anki2-wal
drwxrwx--- 2 root everybody 131072 Apr 23 15:04 collection.media
-rwxrwx--- 1 root everybody 24576 Apr 23 15:01 collection.media.db
while in my desktop computer, the file is called collection.media.db2
.
ls -la ~/.local/share/Anki2/Experiments/
total 1012
drwxrwxr-x 4 rodrigo rodrigo 4096 Mar 26 13:49 .
drwxr-xr-x 18 rodrigo rodrigo 4096 Apr 23 15:27 ..
drwxrwxr-x 2 rodrigo rodrigo 4096 Mar 26 13:49 backups
-rw-r--r-- 1 rodrigo rodrigo 991232 Mar 26 13:49 collection.anki2
drwxrwxr-x 2 rodrigo rodrigo 4096 Jul 12 2024 collection.media
-rw-r--r-- 1 rodrigo rodrigo 24576 Mar 17 14:35 collection.media.db2
-rw-rw-r-- 1 rodrigo rodrigo 3803 Jul 17 2024 deleted.txt
An edited file not syncing is a fairly rare occurrence though, isn’t it? Or is your workflow unique in a way that makes this more common? I question this as someone who frequently edits the audio files on my cards, but since I also regularly add/delete/clean-up my media too, I don’t think I’ve ever been caught without an updated file.
In my use case, it is not a rare ocurrence. I’m using Javascript which are stored in *.js
files which I store in collection.media
. The Javascript code is used in my flashcards to create some HTML elements. I regularly edit these Javascript files in my desktop computer using an external text editor. I want the Javascript code that is run in my desktop to be the same in AnkiDroid.
My final decision: I only add media using Anki Desktop, so for the time being I will disable sync in AnkiDroid and I will give read-only permissions to collection.media
to Syncthing in my phone, so that my phone has an exact copy of collection.media
. I will give read-only permission in my phone, just in case something problematic happens in AnkiDroid due to this hack and I lose all my files in collection.media
in AnkiDroid.
I assume that having an outdated collection.media.db
in my Android phone won’t be a huge problem, but we’ll see. I’ll be sharing my experiences in a few months.
If any of you have another idea for having an exact copy of collection.media between Anki Desktop and AnkiDroid (preferably without much manual work), please let me know.