https://sppas.org/

SPPAS 4.16

Module sppas.src.anndata

Class sppasMedia

Description

Generic representation of a media file.

Constructor

Create a new sppasMedia instance.

Parameters

  • filename: (str) File name of the media
  • media_id: (str) Identifier of the media
  • mime_type: (str) Mime type of the media
def __init__(self, filename, media_id=None, mime_type=None):
    """Create a new sppasMedia instance.

    :param filename: (str) File name of the media
    :param media_id: (str) Identifier of the media
    :param mime_type: (str) Mime type of the media

    """
    super(sppasMedia, self).__init__()
    self.__url = filename
    self.__mime = ''
    self.__content = ''
    if media_id is not None:
        self.set_meta('id', media_id)
    if mime_type is None:
        m = mimetypes.guess_type(self.__url)
        if m[0] is None:
            mime_type = 'audio/basic'
        else:
            mime_type = m[0]
    self.__mime = mime_type

Public functions

get_filename

Return the URL of the media.

def get_filename(self):
    """Return the URL of the media."""
    return self.__url
get_mime_type

Return the mime type of the media.

def get_mime_type(self):
    """Return the mime type of the media."""
    return self.__mime
get_content

Return the content of the media.

def get_content(self):
    """Return the content of the media."""
    return self.__content
set_content

Set the content of the media.

Parameters

  • content: (str)
def set_content(self, content):
    """Set the content of the media.

        :param content: (str)

        """
    self.__content = u(content)

Overloads

__format__
def __format__(self, fmt):
    return str(self).__format__(fmt)
__repr__
def __repr__(self):
    return 'Media: id={:s} url={:s} mime={:s}'.format(self.get_meta('id'), self.__url, self.__mime)
__eq__

Return True if other is strictly identical to self (even id).

Parameters
  • other
def __eq__(self, other):
    """Return True if other is strictly identical to self (even id)."""
    if isinstance(other, sppasMedia) is False:
        return False
    if self.__url != other.get_filename():
        return False
    if self.__mime != other.get_mime_type():
        return False
    for meta_key in self.get_meta_keys():
        if self.get_meta(meta_key) != other.get_meta(meta_key):
            return False
    for meta_key in other.get_meta_keys():
        if self.get_meta(meta_key) != other.get_meta(meta_key):
            return False
    return True
__ne__
def __ne__(self, other):
    return not self == other