Utilities

Utilities.

fqn(obj)

Get fully qualified name of obj, eg. encode.util.fqn.

Parameters:obj
Return type:str
get_random_filename(file_extension=u'png', length=12)

Returns a random filename with an optional length and file-extension.

Parameters:
  • file_extension (str) – File extension for the file, e.g. ‘gif’.
  • length (int) – Number of random characters the filename should contain.
Return type:

str

Returns:

A random filename, e.g. 4AwV8Ckn65a3.png.

get_media_upload_to(instance, filename)

Get target path for user file uploads.

Parameters:
  • instance (django.db.models.Model) – Model instance.
  • filename (str) – The filename for the file being uploaded, eg. ‘test.png’.
Return type:

str

parseMedia(data)

Decode base64-encoded media data and return result.

Parameters:data (str) – base64-encoded string
Return type:str
storeMedia(model, inputFileField, title, profiles, fpath)

Encode and store MediaBase object.

Parameters:
  • model (class) – A model object or instance, e.g. Video.
  • title (str) – Name of the file, e.g. test.png.
  • profiles (list) – List of EncodingProfile names.
  • fpath (str) – Location of media file.
Variables:

inputFileField – Name of the model field where the file will be stored.

Return type:

MediaBase subclass.

class TemporaryMediaFile(prefix, model, inputFileField, profiles, extension=u'media')

Container to store a temporary media file for encoding.

Parameters:
  • prefix (str) – The prefix to use for the temporary filename, e.g. video_.
  • model (django.db.models.Model) – The model to store the file on, e.g. a subclass of MediaBase.
  • inputFileField (str) – Name of the model field where the file will be stored.
  • profiles (list) – List of EncodingProfile names, e.g. [u"MP4", u"WebM Audio/Video"]
  • extension (str) – The extension to use for the temporary filename. Defaults to media.
save(fileData)

Save fileData in temporary file and start encoding.

Parameters:fileData (io.BytesIO) – The media bytes.
Return type:MediaBase
Returns:A new instance of type self.model.