Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Anki audio download #477

Merged

Conversation

toasted-nutbread
Copy link
Collaborator

Download audio binary instead of downloading an Audio object and testing its duration parameter for validity. This eliminates a redundant download in Anki for a file that has already been downloaded by the web browser.

Resolves #419, and would be necessary for #455. Originally brought up in #277 (comment).

@toasted-nutbread
Copy link
Collaborator Author

@FooSoft I'm looking through some of the audio code, and when loading an Audio object, there are two durations which cause the audio to be ignored: 5.694694 and 5.720718. The first one corresponds to invalid audio from the jpod101 source and the MD5 hash 7e2c2f954ef6051373ba916f000168dc, but I'm not sure what the second one corresponds to. Do you know what the second one is/was for?

Originally added here: c8eb77c#diff-d5a318d27e03a2960299ccc82727e376R186

@FooSoft
Copy link
Owner

FooSoft commented Apr 25, 2020

Ah yes, I remember this. Firefox and Chrome were reporting different audio lengths for the same file for some strange reason. Both exist to catch the invalid audio from jpod101.

@toasted-nutbread
Copy link
Collaborator Author

Thanks, I've updated the comments to clarify this behaviour.

@@ -126,6 +120,7 @@ class AnkiNoteBuilder {
if (reading) { filename += `_${reading}`; }
if (expression) { filename += `_${expression}`; }
filename += '.mp3';
filename = filename.replace(/\]/g, '');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you added it, are there other characters that have to be escaped or sanitized from the filename? If it's actually stored in the filesystem under that name, then / and \ can't be used either, but there are also other characters that are disallowed in filenames.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense that it would remove the ] character since it's used to terminate the [audio:...] block.
(offtopic, Anki seems to ignore empty [audio:] audio blocks in those functions)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there other characters that have to be escaped or sanitized from the filename?

(Just FYI, I consider this out of scope for this change, but will gladly make the update in a follow-up PR.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying, I was waiting for a new commit addressing this issue

@siikamiika
Copy link
Collaborator

I swear this worked when I tested, but now I can't add anything with {audio}. Does it work for you?

@toasted-nutbread
Copy link
Collaborator Author

#498?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

anki cloze note /{audio} problem
3 participants