Problem "unused media" when exporting, Front/Back Fields

Hello,

I wanted to Share a Deck, but some media have not been uploaded …

1. Problem :
In my field, I added audio like this using HTML, for example :
<source src="我_sentence4.mp3" type="audio/mp3">

On my deck, the media are correctly played.
I have several Audio per card and it works well, for example :

However, when I share the shared deck, the audio bar are greyed.
The medias are missing and have not been exported.

When I go to Tools > Check Media :
Unused files: ⁨4196⁩
The following files were found in the media folder, but do not appear to be used on any cards:
Unused: 一_sentence0.mp3
Unused: 一_sentence1.mp3
Unused: 一_sentence2.mp3
Unused: 一下_sentence0.mp3

2. A try for a solution :
I followed the documentation here : Static Sounds/Images

Now i do have :
Tools > Check Media :
Unused files: 0

And modified the field of my cards by adding a “_”, :
<source src="_我_sentence4.mp3" type="audio/mp3">

So again, it works well on my side, but when I export the deck, medias are still missing… (this solution seems to be specific only for Card Template ) …

I do not know what to do :

  • Any solution to manually upload these media ?
  • To tag these media and force export?
  • Other ideas ?

Other observation :
Exporting to a collection package works, the media are exported, and when I import the collection to a new user, everything works. (.colpkg)
This is not the case when exporting to a deck package (.apkg)

.

PS Side Topic : search/replace does not work properly, (Work on partial number of cards, but not the full deck)
I had to export the deck to a text file manually, do the change, then reload it.

Version ⁨24.04 (429bc9e1)⁩
Python 3.9.18 Qt 6.6.2 PyQt 6.6.1

2 Likes

Yes, that’s the regular way to do it for templates and it should work for notes as well. It sounds like this is happening consistently for you, so let’s see if anyone can reproduce it.

  • I try not to assume too many things, so I’m checking – did you make sure to check “include media” when you exported?

  • Where are you importing the deck to test this?

  • I’m wondering if there’s an issue with the non-Latin characters in the your filenames. Do you have any filenames using only English/Latin characters where this is happening?

  • Is there a reason you’re using HTML sound tags instead of Anki’s [sound:…] notation? I’m just exploring that for possible workarounds.

That is a very old add-on, so it’s unlikely anyone will be able to do anything about that. Is there a reason not to use built-in Find and Replace? Browsing - Anki Manual

2 Likes

Thank you for your time, much appreciated,

Yes, I have like 9000~ media files exported with a (.apkg) file. Whereas Ive got 15000~ media files with the (.colpkg). (not the same behavior, looks like a coding issue here ? or/and not using the same methods for exporting ?)

Using Anki Desktop, From the user that got the deck with all the media working, I export to my download directory. I then create a new user in order to create a new instance, and to get a pristine file directory before testing the import. (If it works, then I will re-share the deck on AnkiWeb)

No, they all have at least one non-latin characters

Yes, actually, I wanted to have the “player” which allows to get more commands such as pause, change speed etc… plus it does not play automatically the sound on arrival.
And if I added several [sound:…] notation, it would make all the sounds play one after the other.

My bad, I was actually refeiring to what you pointed out (standard doc). I did not use the good URL

1 Like

Just to make sure we’re clear – is your entire collection 1 deck? Otherwise it wouldn’t be unusual for your COLPKG to have more media than you APKG. It also wouldn’t be unusual if you have other unused media in your collection that Anki is saving until you give it approval to delete it.

But you can’t share a deck with someone using a COLPKG file – it will overwrite their collection.

Have you made sure that’s not the problem then? Are you able to get the same thing to happen using a filename without non-latin characters?

There are ways around some of those issues that would allow you to use regular [sound:] tags. So if we can’t get this working for you, that might be worth exploring.


Find and Replace does generally work pretty well, so if you want help about that, I’ll need you to say a bit more about what you were trying that wasn’t working, and what it was doing instead.

1 Like

Yes, I do the tests with only one deck isolated, so yes the collection = the deck.

I did a unit test, yes nothing changes, for example I modified :
_吗_sentence_0 to _ma_sentence_0. Nothing changed.

Some other observations :

  1. Non-latin caracter should not be a problem because
    the audio _吗.mp3 is exported:
    Specifically, this one has a [audio : _吗.mp3] because I wanted it to be played as start. This is not the case for the sentences…

  2. On Anki Web, on my personal space, I have everything, even the audio from the “sentences”. It is only when sharing or exporting that I lose audio for the “sentences” (ie, element that does not have the [audio : ] )

Ok, thank you for this lead, however I would like to avoid it at first as I would need to update the full deck.

Yes looking in details, it was in fact an issue with
Addon : HTML in editor
In the text file exported, I had some html either with
<source src=" or
<source src='

And the addon always showed :
<source src=' (even for <source src=" )

Therefore the Anki Find and Replace , did not update the <source src=" , which is normal.

1 Like

Thank you for all that extra information – it helps a lot! I’m seeing the same thing you are, and I don’t think that’s what it is supposed to be happening.

Version

Anki 24.06.2 (33a92379) (ao)
Python 3.9.18 Qt 6.6.2 PyQt 6.6.1
Platform: Windows-10-10.0.22631

I tried an “iframe” source with leading underscore, because that’s what I already had put together – <iframe src="_test.txt"></iframe> – exported as APKG, including media. If it’s on the template it is exported/imported, but on the note it is not. [Although, I can’t specifically tell whether it’s not being exported in the first place or just not being imported in the new profile.]

I also tried an HTML-audio example like yours, which was not exported/imported – <audio controls=""><source src="_k3714.mp3" type="audio/mpeg"></audio> – and a standard sound tag, which was [as expected] – [sound:_a0302.mp3] .

@Rumo – I’ve seen you on export/import issues, and you just responded to someone last week that this is the way – so I’m picking on you! Isn’t this supposed to work on notes as well as card templates?

From what I understood, the issue is happening at export : the notification show me that I have less media exported when I export a package than when I export a collection (from the same deck).

And, when I go to the Tools > Check Media > View files for the new user, the missing media are not present on the folder after import

As it stands,

<source> tags aren’t currently considered to be html media tags

And from my testing it doesn’t seem to even render/play on desktop. Is the pic above from ankiweb or mobile perhaps?

While waiting for someone to maybe fix this, you could try changing those <source> tags to sound tags like [sound:我_sentence4.mp3] instead

1 Like

The picture comes from AnkiDesktop,
Actually, the correct tags should be :

<audio controls=""><source src="_约_sentence0.mp3"></audio>

example :

I would like to avoid this if possible :

I am currently considering this Bypass idea, but would prefer a fix :
Create a hidden field ( named for example “ressources”, like “front” or “back”) I’ll then put all the [audio:] and not call this field by the card templater. I then hope that the media will be exported.

Opened a pr. But keep in mind that if you’re aiming to share this deck with folks who’re still on old anki versions, it might be good to at least move src into the <audio> tag itself, i.e.
from <audio controls=""><source src="_约_sentence0.mp3"></audio>
to <audio controls="" src="_约_sentence0.mp3"></audio>

That way you can avoid autoplay, drop the initial _ in the filename (which was a media check hack), resolve your issue and ensure no one else using your deck is hit by it

1 Like

Many thanks, this was the mistake. And now it works like a charm.

@llama, @Danika_Dakika , thank you both for your time, you made my day

1 Like

Thanks! Any chance your PR also addresses iframes?

I don’t think media references in iframes are currently recognised by anki, nor added by the pr :sweat_smile: (unless they’re underscored, but this only affects media checking and* template exporting)

*its not that underscored media references are seen and ignored, it’s that underscored files in the media folder aren’t treated as missing

Are they commonly used? I hesitate because iframes might be a source of security concerns (not really up to speed on this), but if the user is doing it then maybe we should assume they know what they’re doing :zap:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.