Upload Tasks Management

This module organizes the uploading process to data from the WebUI into the MusicDB Upload directory where it can then be further processed.

The upload is performed chunk-wise. After initiating an Upload, the management thread (Task Management Thread) requests chunks of data via MusicDB Notifications from the clients. All clients are informed about the upload process, not only the client that initiated the upload. So each client can show the progress and state.

UploadManager Class

class musicdb.taskmanagement.uploadmanager.UploadManager(config, database)[source]

This class manages uploading content to the server MusicDB runs on. All data is stored in the uploads-directory configured in the MusicDB configuration. The class is derived from musicdb.taskmanagement.taskmanager.TaskManager.

Parameters
Raises

TypeError – When the arguments are not of the correct type.

AnnotateUpload(taskid, annotations)[source]

This method can be used to add additional information to an upload. This can be done during or after the upload process.

Parameters
  • taskid (str) – ID to identify the upload

  • annotations (dict) – A dictionary with annotations that will be added to the upload task data structure

Returns

True on success, otherwise False

Raises
  • TypeError – When taskid is not of type str

  • ValueError – When taskid is not included in the Task Queue

InitiateUpload(taskid, mimetype, contenttype, filesize, checksum, sourcefilename)[source]

Initiates an upload of a file into a MusicDB managed file space. After calling this method, a notification gets triggered to request the first chunk of data from the clients. In case uploads are deactivated in the MusicDB Configuration, an "InternalError" Notification gets sent to the clients.

Parameters
  • taskid (str) – Unique ID to identify the upload task

  • mimetype (str) – MIME-Type of the file (example: "image/png")

  • contenttype (str) – Type of the content: ("video", "album", "artwork")

  • filesize (int) – Size of the complete file in bytes

  • checksum (str) – SHA-1 check sum of the source file

  • sourcefilename (str) – File name (example: "test.png")

Raises
  • TypeError – When one of the arguments has not the expected type

  • ValueError – When contenttype does not have the expected values

NewChunk(taskid, rawdata)[source]

This method processes a new chunk received from the uploading client.

Parameters
  • taskid (str) – Unique ID to identify the upload task

  • rawdata (bytes) – Raw data to append to the uploaded data

Returns

False in case an error occurs. Otherwise True.

Raises

TypeError – When rawdata is not of type bytes

PreProcessAlbumFile(task)[source]

An album file in general can be anything. It can be a song (normal case) but also a booklet, a music video or anything else. This method identifies music files and reads its meta data using the MetaTags class.

All tags returned by GetAllMetadata() will be annotated to the task, if the file is a music file. To annotate those information, the AnnotateUpload() method will be used.

Parameters

task (dict) – the task object of an upload-task

Returns

True on success, otherwise False.

PreProcessArtwork(task)[source]

This method preprocesses the uploaded artwork. If the uploaded file is not a JPEG file, it will be JPEG encoded. On success, after calling this method, the "preprocessedpath" attribute of the task dictionary is set to a valid JPEG file.

Parameters

task (dict) – the task object of an upload-task

Returns

True on success, otherwise False.

PreProcessUploadedFile(task)[source]

This method initiates pre-processing of an uploaded file. Depending on the contenttype different post processing methods are called:

The task must be in "uploadcomplete" state, otherwise nothing happens but printing an error message. If post processing was successful, the task state gets updated to "readyforintegration". When an error occurred, the state will become "invalidcontent".

Parameters

task (dict) – the task object of an upload-task

Returns

True on success, otherwise False

PreProcessVideo(task)[source]
Parameters

task (dict) – the task object of an upload-task

RequestRemoveUpload(taskid)[source]

This method triggers removing a specific upload. This includes the uploaded file as well as the upload task information and annotations.

The upload task can be in any state. When the remove-operation is triggered, its state gets changed to "remove".

Only the "remove" state gets set. Removing will be done by the Management Thread.

Parameters

taskid (str) – ID of the upload-task

Returns

True on success

UploadCompleted(task)[source]

This method continues the file management after an upload was completed. The following tasks were performed:

  • Checking the checksum of the destination file (SHA1) and compares it with the "sourcechecksum" from the task-dict.

When the upload was successful, it notifies the clients with a "UploadComplete" notification. Otherwise with a "UploadFailed" one.

Parameters

task (dict) – The task that upload was completed

Returns

True When the upload was successfully complete, otherwise False