-
Notifications
You must be signed in to change notification settings - Fork 223
Anki audio download #477
Anki audio download #477
Conversation
@FooSoft I'm looking through some of the audio code, and when loading an Originally added here: c8eb77c#diff-d5a318d27e03a2960299ccc82727e376R186 |
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. |
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, ''); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why "]" is removed is due to how Anki handles them, not necessarily file name restrictions. That is probably a valid thing to do however.
https://github.com/ankitects/anki/blob/913c26870529174b50f4207397ede7444a48dc6e/pylib/anki/utils.py#L94
https://github.com/ankitects/anki/blob/913c26870529174b50f4207397ede7444a48dc6e/pylib/anki/exporting.py#L67
https://github.com/ankitects/anki/blob/913c26870529174b50f4207397ede7444a48dc6e/pylib/anki/media.py#L35
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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
I swear this worked when I tested, but now I can't add anything with |
#498? |
Download audio binary instead of downloading an
Audio
object and testing itsduration
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).