anki.media
==========

.. py:module:: anki.media


Attributes
----------

.. autoapisummary::

   anki.media.CheckMediaResponse


Classes
-------

.. autoapisummary::

   anki.media.MediaManager


Functions
---------

.. autoapisummary::

   anki.media.media_paths_from_col_path


Module Contents
---------------

.. py:function:: media_paths_from_col_path(col_path: str) -> tuple[str, str]

.. py:data:: CheckMediaResponse

.. py:class:: MediaManager(col: anki.collection.Collection, server: bool)

   Bases: :py:obj:`anki._legacy.DeprecatedNamesMixin`


   .. py:attribute:: sound_regexps
      :value: ['(?i)(\\[sound:(?P<fname>[^]]+)\\])']



   .. py:attribute:: html_media_regexps
      :value: ['(?i)(<(?:img|audio|source)\\b[^>]* src=(?P<str>[\\"\'])(?P<fname>[^>]+?)(?P=str)[^>]*>)',...



   .. py:attribute:: regexps
      :value: ['(?i)(\\[sound:(?P<fname>[^]]+)\\])', '(?i)(<(?:img|audio|source)\\b[^>]*...



   .. py:attribute:: col


   .. py:method:: dir() -> str


   .. py:method:: force_resync() -> None


   .. py:method:: empty_trash() -> None


   .. py:method:: restore_trash() -> None


   .. py:method:: strip_av_tags(text: str) -> str


   .. py:method:: add_file(path: str) -> str

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

      Returns possibly-renamed filename.



   .. py:method:: write_data(desired_fname: str, data: bytes) -> str

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

      Returns possibly-renamed filename.



   .. py:method:: 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.



   .. py:method:: have(fname: str) -> bool


   .. py:method:: trash_files(fnames: list[str]) -> None

      Move provided files to the trash.



   .. py:method:: files_in_str(mid: anki.models.NotetypeId, string: str, include_remote: bool = False) -> list[str]


   .. py:method:: extract_static_media_files(mid: anki.models.NotetypeId) -> collections.abc.Sequence[str]


   .. py:method:: transform_names(txt: str, func: collections.abc.Callable) -> str


   .. py:method:: strip(txt: str) -> str

      Return text with sound and image tags removed.



   .. py:method:: escape_images(string: str, unescape: bool = False) -> str

      escape_media_filenames alias for compatibility with add-ons.



   .. py:method:: escape_media_filenames(string: str, unescape: bool = False) -> str

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



   .. py:method:: check() -> CheckMediaResponse


   .. py:method:: 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)



