Skip to main content

Welcome to the documentation for django-medialibrary!

django-medialibrary is a pluggable django app that is able to store different media types (audio, video, image) and several versions of a given file in a transparent way.

The basic problam to solve is to store, retrieve and manage several versions of the same file in a seemless way. E.g. a user uploads a video that you will have to transcode into different formats. For the user you would like to show only a single media in his list of uploaded files, but you still want to serve all the generated files when necessary, moreover, if the user decides to delete his media you would like to delete all its versions.

The idea for this app is to have all this in an app-indepedent and easy to use and extend way.

Features

  • Unique entry point for every media type, user.medialibrary.shelf_set

  • Different shelfs with possible different login for every media type. The shelf_set contains different models, each derived from medialibrary.models.Shelf.

  • Simple access to the original file.:

    myShelf = AudioShelf.objects.get(pk=1)
    myShelf.audio_set.all()  # returns the list of audio files
    isinstance(myShelf.original, Audio)  # return True, if a file is attached to myShelf
    myShelf.original.size, myShelf.original.url
  • Custom manager to query the shelves.

  • Generic relationships to bind the shelves to any object in the project, using the ShelfRelation model

  • Every shelf type can have an ALLOWED_FORMATS property that lists the allowed extensions to be save in the shelf.

  • VideoShelves can have thumbnail images (actually ImageShelf instances) attached. Only one of these can be marked as selected. The myVideoShelf.thumbnail property returns the selected thumbnail.

Frontend API

There is no html frontend on purpose as we are using this app through APIs. The provided APIs out of the box are

  • /audio/, /video/, /image/ - to upload and list media elements of a given type

  • /<pk>/ - to get detailed info about a single media element

  • /<pk>/add/ - adds a relationship to the media element, expects a json of the form:

    {
            'model': 'app_name.model_name',
            'object_id': 1
    }

where app_name.model_name is the natural key of the model you are attaching.

Customizations

Besides the general django settings for file storage, there is a custom setting, the upload_to method used in the FileFields.:

import datetime
def setup_s3_route(instance, filename=None):
    today = datetime.datetime.today()
    return 'media/%s-%02d-%02d/%s' % (today.year, today.month, today.day,
                                          filename)
from medialibrary import utils
utils.setup_upload_route = setup_s3_route

You can set a custom argument for the limit_choices_to attribute on the ShelfRelation model. This way you can define which apps are allowed to have relationships to you media elements. (e.g. if you remove the attached records when you remove the media, you probably don’t want to attach django permission records to media). The default is no restricions!:

from medialibrary import utils
from django.db import models
utils.content_type_restriction = models.Q(app_label='auth', model='user')

Adding new media types

The medialibrary can be easily extended with new media types. Here is an example to add a new DocumentShelf model:

from medialibrary.models import Shelf

class DocumentShelf(Shelf):

    ALLOWED_FORMATS = ('doc', 'docx', 'pdf', 'odf')

    def file_set():
        doc = "The file_set property."
        def fget(self):
            return self.audio_set
        return locals()
    file_set = property(**file_set())

After this simple model definition, the user’s user.medialibrary.shelf_set will contain DocumentShelf instances whenever appropriate.

Installation

pip install django-medialibrary

or you can find the project on github

Running the standalone tests

You can run the tests via:

#create a virtualenv and activate it

pip install -r test_requirements.txt

python runtests.py

Sponsors

This app was written at Pulilab while we were working on Vidzor.

Metadata

Release files for django-medialibrary 1.4.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-medialibrary 1.4.9
File Size Uploaded
django-medialibrary-1.4.9.tar.gz 17.0 kB Details

Release files / django-medialibrary-1.4.9.tar.gz

Download URL django-medialibrary-1.4.9.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
63a37355186fe2f161ed9213e44c207f2a360b1bf07026572f0dfa5da3e0d849
BLAKE2b-256 checksum
How to use checksums
01628ee0990784878f7bcac3b4de5095f1a629d58e6fee29786419d539dbdcf7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.4.9 This release

1 release file

1.4.8

1 release file

1.4.7

1 release file

1.4.6

1 release file

1.4.5

1 release file

1.4.4

1 release file

1.4.3

1 release file

1.4.2

1 release file

1.4.1

1 release file

1.4.0

1 release file

1.3.5

1 release file

1.3.4

1 release file

1.3.3

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page