Skip to content

Commit

Permalink
Merge pull request #4 from jonasundderwolf/rename-package
Browse files Browse the repository at this point in the history
Rename app to django-video-encoder
  • Loading branch information
MRigal authored Oct 22, 2020
2 parents 3295f7b + 5b39521 commit c455678
Show file tree
Hide file tree
Showing 24 changed files with 162 additions and 319 deletions.
39 changes: 24 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
===============
django-zencoder
===============
====================
django-video-encoder
====================

.. image:: https://img.shields.io/pypi/v/django-zencoder.svg
:target: https://pypi.python.org/pypi/django-zencoder
.. image:: https://img.shields.io/pypi/v/django-video-encoder.svg
:target: https://pypi.python.org/pypi/django-video-encoder

.. image:: https://img.shields.io/pypi/pyversions/django-zencoder.svg
:target: https://pypi.python.org/pypi/django-zencoder
.. image:: https://img.shields.io/pypi/pyversions/django-video-encoder.svg
:target: https://pypi.python.org/pypi/django-video-encoder

.. image:: https://img.shields.io/pypi/djversions/django-zencoder
.. image:: https://img.shields.io/pypi/djversions/django-video-encoder
:alt: PyPI - Django Version
:target: https://pypi.python.org/pypi/django-zencoder
:target: https://pypi.python.org/pypi/django-video-encoder


Simple integration with zencoder.com
Simple integration with video encoding backends.

For now only the remote zencoder.com is supported.

Upload videos and asynchronously store the encoded videos.

Expand All @@ -27,17 +29,22 @@ Usage

You will need to add the following to your django settings:

* Add `django_zencoder` to `INSTALLED_APPS`
* Add `ZENCODER_API_KEY` and `ZENCODER_NOTIFICATION_SECRET`
* Set the `ZENCODER_THUMBNAIL_INTERVAL`
* Add `django_video_encoder` to `INSTALLED_APPS`
* Set the `DJANGO_VIDEO_ENCODER_THUMBNAIL_INTERVAL`
* Add the desired formats, for example ::
ZENCODER_FORMATS = [
DJANGO_VIDEO_ENCODER_FORMATS = [
{'label': 'H.264 (HD)', 'codec': 'h264'},
{'label': 'H.264', 'codec': 'h264', 'width': 720, 'height': 404},
{'label': 'VP9 (HD)', 'codec': 'VP9'},
{'label': 'VP9', 'codec': 'VP9', 'width': 720, 'height': 404},
]

And specific settings using the zencoder backend:

* Add `ZENCODER_API_KEY` and `ZENCODER_NOTIFICATION_SECRET`
* You may also specify `ZENCODER_REGION` (default: europe) to the
most suitable for you

Tests
=====

Expand All @@ -49,4 +56,6 @@ Misc

To not be confused with the archived
`theonion/django-zencoder <https://github.com/theonion/django-zencoder>`_
which is installed as `zencoder` (without django- prefix)
which is installed as `zencoder`

See also similar project `escaped/django-video-encoding <https://github.com/escaped/django-video-encoding>`_
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions django_zencoder/api.py → django_video_encoder/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def absolute_url(url):
color_metadata = "discard"

outputs = []
for fmt in settings.ZENCODER_FORMATS:
for fmt in settings.DJANGO_VIDEO_ENCODER_FORMATS:
data = {
"obj": obj.pk,
"ct": content_type.pk,
Expand Down Expand Up @@ -104,7 +104,7 @@ def absolute_url(url):

# get thumbnails for first output only
data["output"][0]["thumbnails"] = {
"interval": settings.ZENCODER_THUMBNAIL_INTERVAL,
"interval": settings.DJANGO_VIDEO_ENCODER_THUMBNAIL_INTERVAL,
"start_at_first_frame": 1,
"format": "jpg",
}
Expand Down Expand Up @@ -160,7 +160,7 @@ def get_video(content_type_id, object_id, field_name, data):
thmb, __ = Thumbnail.objects.get_or_create(
content_type=content_type,
object_id=object_id,
time=i * settings.ZENCODER_THUMBNAIL_INTERVAL,
time=i * settings.DJANGO_VIDEO_ENCODER_THUMBNAIL_INTERVAL,
)
thmb.image.save(basename(filename), File(open(filename, "rb")))
os.unlink(filename)
Expand Down
File renamed without changes.
106 changes: 106 additions & 0 deletions django_video_encoder/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Generated by Django 2.2.16 on 2020-09-30 12:56

import django.db.models.deletion
from django.db import migrations, models

import django_video_encoder.models


class Migration(migrations.Migration):

initial = True

dependencies = [
("contenttypes", "0002_remove_content_type_name"),
]

operations = [
migrations.CreateModel(
name="Thumbnail",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("object_id", models.PositiveIntegerField()),
("time", models.PositiveIntegerField(verbose_name="Time (s)")),
("width", models.PositiveIntegerField(null=True, verbose_name="Width")),
(
"height",
models.PositiveIntegerField(null=True, verbose_name="Height"),
),
(
"image",
models.ImageField(
blank=True,
max_length=512,
null=True,
upload_to=django_video_encoder.models.thumbnail_upload_to,
),
),
(
"content_type",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="contenttypes.ContentType",
),
),
],
),
migrations.CreateModel(
name="Format",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("object_id", models.PositiveIntegerField()),
("field_name", models.CharField(max_length=255)),
(
"format",
models.CharField(choices=[("H.264", "H.264")], max_length=255),
),
(
"file",
models.FileField(
max_length=2048,
upload_to=django_video_encoder.models.format_upload_to,
),
),
("width", models.PositiveIntegerField(null=True, verbose_name="Width")),
(
"height",
models.PositiveIntegerField(null=True, verbose_name="Height"),
),
(
"duration",
models.PositiveIntegerField(
null=True, verbose_name="Duration (ms)"
),
),
(
"extra_info",
models.TextField(
blank=True, verbose_name="Encoder information (JSON)"
),
),
(
"content_type",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="contenttypes.ContentType",
),
),
],
),
]
File renamed without changes.
24 changes: 13 additions & 11 deletions django_zencoder/models.py → django_video_encoder/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from .api import encode

ZENCODER_MODELS = {}
VIDEO_ENCODER_MODELS = {}


def format_upload_to(instance, filename):
Expand All @@ -33,14 +33,16 @@ class Format(models.Model):

format = models.CharField(
max_length=255,
choices=[(f["label"], f["label"]) for f in settings.ZENCODER_FORMATS],
choices=[
(f["label"], f["label"]) for f in settings.DJANGO_VIDEO_ENCODER_FORMATS
],
)
file = models.FileField(upload_to=format_upload_to, max_length=2048)
width = models.PositiveIntegerField("Width", null=True)
height = models.PositiveIntegerField("Height", null=True)
duration = models.PositiveIntegerField("Duration (ms)", null=True)

extra_info = models.TextField("Zencoder information (JSON)", blank=True)
extra_info = models.TextField("Encoder information (JSON)", blank=True)


def thumbnail_upload_to(instance, filename):
Expand All @@ -65,26 +67,26 @@ class Thumbnail(models.Model):


def detect_file_changes(sender, instance, **kwargs):
field_name = ZENCODER_MODELS.get(
field_name = VIDEO_ENCODER_MODELS.get(
"%s.%s" % (sender._meta.app_label, sender._meta.model_name)
)
if field_name:
field = getattr(instance, field_name)
if field and hasattr(field, "file") and isinstance(field.file, UploadedFile):
if hasattr(instance, "_zencoder_updates"):
instance._zencoder_updates.append(field_name)
if hasattr(instance, "_video_encoder_updates"):
instance._video_encoder_updates.append(field_name)
else:
instance._zencoder_updates = [field_name]
instance._video_encoder_updates = [field_name]


def trigger_encoding(sender, instance, **kwargs):
for field in getattr(instance, "_zencoder_updates", ()):
for field in getattr(instance, "_video_encoder_updates", ()):
encode(instance, field)


if getattr(settings, "ZENCODER_MODELS", None):
for name in settings.ZENCODER_MODELS:
if getattr(settings, "VIDEO_ENCODER_MODELS", None):
for name in settings.VIDEO_ENCODER_MODELS:
app_model, field = name.rsplit(".", 1)
ZENCODER_MODELS[app_model.lower()] = field
VIDEO_ENCODER_MODELS[app_model.lower()] = field
models.signals.pre_save.connect(detect_file_changes)
models.signals.post_save.connect(trigger_encoding)
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions django_zencoder/views.py → django_video_encoder/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ def notification(request):
request.META.get("HTTP_X_ZENCODER_NOTIFICATION_SECRET")
!= settings.ZENCODER_NOTIFICATION_SECRET
):
logger.warn("Invalid Zencoder notification secret", extra={"request": request})
logger.warning(
"Invalid Zencoder notification secret", extra={"request": request}
)
return HttpResponse("Invalid notification secret", status=400) # BAD REQUEST

try:
data = signing.loads(request.META["QUERY_STRING"])
except signing.BadSignature:
logger.warn(
logger.warning(
"Invalid payload for Zencoder notification", extra={"request": request}
)
return HttpResponse("Invalid payload", status=400) # BAD REQUEST
Expand Down
6 changes: 0 additions & 6 deletions django_zencoder/apps.py

This file was deleted.

82 changes: 0 additions & 82 deletions django_zencoder/migrations/0001_initial.py

This file was deleted.

Loading

0 comments on commit c455678

Please sign in to comment.