A Django Application to manage the backend features for a Streaming Project.
The application aims to manage the uploading of audio files by users, split them into multiple chunks and generate the APIs to obtain information and chunks from the latter. The chunks will not uploaded into your media dir in order to prevent unauthorized access from users.
- Customize your Audio and AudioChunk Models and Serializers
- Customize Permissions presences and names
- Choose the saving folder
- Choose the format types
By defaults the settings are:
# Audio Delivery Settings
AUDIODELIVERY_CHUNK_DIR = BASE_DIR / "chunks"
AUDIODELIVERY_ALLOWED_FORMATS = ("mp3", )
AUDIODELIVERY_MAX_DURATION = 5*60*1000
AUDIODELIVERY_MAX_SIZE = 10*1024*1024
AUDIODELIVERY_UPLOAD_VALIDATORS = []
AUDIODELIVERY_MAX_CHUNK_DURATION = 9999
AUDIODELIVERY_CHUNK_MODEL = "audiodelivery.AudioChunk"
AUDIODELIVERY_AUDIO_MODEL = "audiodelivery.Audio"
AUDIODELIVERY_PERMISSIONS = {
"retrieve": ("can_retrieve", _("Can User retrieve Audio infos")),
"upload": ("can_upload", _("Can User upload new Audio"))
}
AUDIODELIVERY_CHUNK_SERIALIZER = "audiodelivery.api.serializers.AudioChunkSerializer"
AUDIODELIVERY_AUDIO_SERIALIZER = "audiodelivery.api.serializers.AudioSerializer"
AUDIODELIVERY_UPLOAD_BACKEND = "audiodelivery.backend.default.DefaultStorageAudioUploaderBackend"
AUDIODELIVERY_DELIVER_BACKEND = "audiodelivery.backend.default.CommonAudioDeliverBackend"
But you can create your custom Audio model by importing the Base Abstract Model from: audiodelivery.models.audio.BaseAudio For example:
from django.db import models
from audiodelivery.models.audio import BaseAudio, PERMISSIONS
class MyAudio(BaseAudio):
class Meta:
verbose_name = "MyAudio"
verbose_name_plural = "MyAudios"
permissions = list()
if "retrieve" in PERMISSIONS:
permissions.append(PERMISSIONS["retrieve"])
if "upload" in PERMISSIONS:
permissions.append(PERMISSIONS["upload"])
permissions = tuple(permissions)
# custom fields go here
genre = models.CharField("Genre", max_length=255)
...
And next you've to update the settings.py file with:
...
AUDIODELIVERY_AUDIO_MODEL = "your_app_label.MyAudio"
...
First of all AudioDelivery requires two extra django apps:
- django-rest-framework -> for manage the REST APIs requests
- django-crum -> a middleware for obtain the current user in the thread
And make sure you've installed pydub library and ffmpeg:
- pydub -> helps mp3 chunks generation
Make sure that you've installed apps and middleware in the settings.py file:
INSTALLED_APPS = [
# other apps...
'rest_framework',
'audiodelivery',
]
...
MIDDLEWARE = [
# other middlewares...
'crum.CurrentRequestUserMiddleware',
]
...
REST_FRAMEWORK = {
"EXCEPTION_HANDLER": "audiodelivery.utils.exceptions.api_exception_handler"
}
Next step is to append in the settings file, the default AudioDelivery Settings showed before this section, and follow the previous tutorial if you want to implement custom models/serializers, then run:
python3 manage.py makemigrations
python3 manage.py migrate
Now you can run the project!