anki.media#

Attributes#

Classes#

Functions#

media_paths_from_col_path(→ tuple[str, str])

Module Contents#

anki.media.media_paths_from_col_path(col_path: str) tuple[str, str]#
anki.media.CheckMediaResponse#
class anki.media.MediaManager(col: anki.collection.Collection, server: bool)#

Bases: anki._legacy.DeprecatedNamesMixin

sound_regexps = ['(?i)(\\[sound:(?P<fname>[^]]+)\\])']#
html_media_regexps = ['(?i)(<(?:img|audio|source)\\b[^>]* src=(?P<str>[\\"\'])(?P<fname>[^>]+?)(?P=str)[^>]*>)',...#
regexps = ['(?i)(\\[sound:(?P<fname>[^]]+)\\])', '(?i)(<(?:img|audio|source)\\b[^>]*...#
col#
dir() str#
force_resync() None#
empty_trash() None#
restore_trash() None#
strip_av_tags(text: str) str#
add_file(path: str) str#

Add basename of path to the media folder, renaming if not unique.

Returns possibly-renamed filename.

write_data(desired_fname: str, data: bytes) str#

Write the file to the media folder, renaming if not unique.

Returns possibly-renamed filename.

add_extension_based_on_mime(fname: str, content_type: str) str#

Add extension based on mime for common audio and image format if missing extension.

have(fname: str) bool#
trash_files(fnames: list[str]) None#

Move provided files to the trash.

files_in_str(mid: anki.models.NotetypeId, string: str, include_remote: bool = False) list[str]#
extract_static_media_files(mid: anki.models.NotetypeId) collections.abc.Sequence[str]#
transform_names(txt: str, func: collections.abc.Callable) str#
strip(txt: str) str#

Return text with sound and image tags removed.

escape_images(string: str, unescape: bool = False) str#

escape_media_filenames alias for compatibility with add-ons.

escape_media_filenames(string: str, unescape: bool = False) str#

Apply or remove percent encoding to filenames in html tags (audio, image, object).

check() CheckMediaResponse#
render_all_latex(progress_cb: collections.abc.Callable[[int], bool] | None = None) tuple[int, str] | None#

Render any LaTeX that is missing.

If a progress callback is provided and it returns false, the operation will be aborted.

If an error is encountered, returns (note_id, error_message)