From 5b39521042ecba9b547bf11ca37a096dce6dd811 Mon Sep 17 00:00:00 2001 From: Matthieu Rigal Date: Wed, 30 Sep 2020 13:18:54 +0200 Subject: [PATCH] Rename app to django-video-encoder --- README.rst | 39 ++++--- .../__init__.py | 0 .../admin.py | 0 .../api.py | 6 +- .../errors.py | 0 .../migrations/0001_initial.py | 106 ++++++++++++++++++ .../migrations/__init__.py | 0 .../models.py | 24 ++-- .../signals.py | 0 .../tasks.py | 0 .../urls.py | 0 .../views.py | 6 +- django_zencoder/apps.py | 6 - django_zencoder/migrations/0001_initial.py | 82 -------------- .../migrations/0002_auto_20161027_1629.py | 93 --------------- .../migrations/0003_auto_20161031_1017.py | 27 ----- .../migrations/0004_auto_20170729_1732.py | 27 ----- .../0005_prepare_migrations_for_app_rename.py | 41 ------- example/models.py | 2 +- example/settings.py | 6 +- example/tests/test_base.py | 6 +- example/urls.py | 2 +- setup.cfg | 2 +- setup.py | 6 +- 24 files changed, 162 insertions(+), 319 deletions(-) rename {django_zencoder => django_video_encoder}/__init__.py (100%) rename {django_zencoder => django_video_encoder}/admin.py (100%) rename {django_zencoder => django_video_encoder}/api.py (97%) rename {django_zencoder => django_video_encoder}/errors.py (100%) create mode 100644 django_video_encoder/migrations/0001_initial.py rename {django_zencoder => django_video_encoder}/migrations/__init__.py (100%) rename {django_zencoder => django_video_encoder}/models.py (78%) rename {django_zencoder => django_video_encoder}/signals.py (100%) rename {django_zencoder => django_video_encoder}/tasks.py (100%) rename {django_zencoder => django_video_encoder}/urls.py (100%) rename {django_zencoder => django_video_encoder}/views.py (88%) delete mode 100644 django_zencoder/apps.py delete mode 100644 django_zencoder/migrations/0001_initial.py delete mode 100644 django_zencoder/migrations/0002_auto_20161027_1629.py delete mode 100644 django_zencoder/migrations/0003_auto_20161031_1017.py delete mode 100644 django_zencoder/migrations/0004_auto_20170729_1732.py delete mode 100644 django_zencoder/migrations/0005_prepare_migrations_for_app_rename.py diff --git a/README.rst b/README.rst index 4179a05..7281a99 100644 --- a/README.rst +++ b/README.rst @@ -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. @@ -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 ===== @@ -49,4 +56,6 @@ Misc To not be confused with the archived `theonion/django-zencoder `_ -which is installed as `zencoder` (without django- prefix) +which is installed as `zencoder` + +See also similar project `escaped/django-video-encoding `_ diff --git a/django_zencoder/__init__.py b/django_video_encoder/__init__.py similarity index 100% rename from django_zencoder/__init__.py rename to django_video_encoder/__init__.py diff --git a/django_zencoder/admin.py b/django_video_encoder/admin.py similarity index 100% rename from django_zencoder/admin.py rename to django_video_encoder/admin.py diff --git a/django_zencoder/api.py b/django_video_encoder/api.py similarity index 97% rename from django_zencoder/api.py rename to django_video_encoder/api.py index 8a5f65d..d1559fd 100644 --- a/django_zencoder/api.py +++ b/django_video_encoder/api.py @@ -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, @@ -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", } @@ -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) diff --git a/django_zencoder/errors.py b/django_video_encoder/errors.py similarity index 100% rename from django_zencoder/errors.py rename to django_video_encoder/errors.py diff --git a/django_video_encoder/migrations/0001_initial.py b/django_video_encoder/migrations/0001_initial.py new file mode 100644 index 0000000..55e0e7d --- /dev/null +++ b/django_video_encoder/migrations/0001_initial.py @@ -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", + ), + ), + ], + ), + ] diff --git a/django_zencoder/migrations/__init__.py b/django_video_encoder/migrations/__init__.py similarity index 100% rename from django_zencoder/migrations/__init__.py rename to django_video_encoder/migrations/__init__.py diff --git a/django_zencoder/models.py b/django_video_encoder/models.py similarity index 78% rename from django_zencoder/models.py rename to django_video_encoder/models.py index dc9d1e4..0333759 100644 --- a/django_zencoder/models.py +++ b/django_video_encoder/models.py @@ -9,7 +9,7 @@ from .api import encode -ZENCODER_MODELS = {} +VIDEO_ENCODER_MODELS = {} def format_upload_to(instance, filename): @@ -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): @@ -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) diff --git a/django_zencoder/signals.py b/django_video_encoder/signals.py similarity index 100% rename from django_zencoder/signals.py rename to django_video_encoder/signals.py diff --git a/django_zencoder/tasks.py b/django_video_encoder/tasks.py similarity index 100% rename from django_zencoder/tasks.py rename to django_video_encoder/tasks.py diff --git a/django_zencoder/urls.py b/django_video_encoder/urls.py similarity index 100% rename from django_zencoder/urls.py rename to django_video_encoder/urls.py diff --git a/django_zencoder/views.py b/django_video_encoder/views.py similarity index 88% rename from django_zencoder/views.py rename to django_video_encoder/views.py index 7211b5c..56cb739 100644 --- a/django_zencoder/views.py +++ b/django_video_encoder/views.py @@ -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 diff --git a/django_zencoder/apps.py b/django_zencoder/apps.py deleted file mode 100644 index 3d68012..0000000 --- a/django_zencoder/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class ZencoderConfig(AppConfig): - name = "django_zencoder" - label = "django_video_encoder" diff --git a/django_zencoder/migrations/0001_initial.py b/django_zencoder/migrations/0001_initial.py deleted file mode 100644 index 45b94e5..0000000 --- a/django_zencoder/migrations/0001_initial.py +++ /dev/null @@ -1,82 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -import django.db.models.deletion -from django.db import migrations, models - -import django_zencoder.models - - -class Migration(migrations.Migration): - - dependencies = [ - ("contenttypes", "0001_initial"), - ] - - operations = [ - migrations.CreateModel( - name="Format", - options={ - "db_table": "django_zencoder_format", - }, - fields=[ - ( - "id", - models.AutoField( - verbose_name="ID", - serialize=False, - auto_created=True, - primary_key=True, - ), - ), - ("object_id", models.PositiveIntegerField()), - ("field_name", models.CharField(max_length=255)), - ( - "format", - models.CharField( - max_length=255, - choices=[ - (b"mp4-high", b"mp4-high"), - (b"mp4-low", b"mp4-low"), - (b"webm-high", b"webm-high"), - (b"webm-low", b"webm-low"), - ], - ), - ), - ( - "file", - models.FileField( - max_length=2048, - upload_to=django_zencoder.models.format_upload_to, - ), - ), - ( - "width", - models.PositiveIntegerField(null=True, verbose_name=b"Width"), - ), - ( - "height", - models.PositiveIntegerField(null=True, verbose_name=b"Height"), - ), - ( - "duration", - models.PositiveIntegerField( - null=True, verbose_name=b"Duration (ms)" - ), - ), - ( - "extra_info", - models.TextField( - verbose_name=b"Zencoder information (JSON)", blank=True - ), - ), - ( - "content_type", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - to="contenttypes.ContentType", - ), - ), - ], - ), - ] diff --git a/django_zencoder/migrations/0002_auto_20161027_1629.py b/django_zencoder/migrations/0002_auto_20161027_1629.py deleted file mode 100644 index de7cca3..0000000 --- a/django_zencoder/migrations/0002_auto_20161027_1629.py +++ /dev/null @@ -1,93 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -import django.db.models.deletion -from django.db import migrations, models - -import django_zencoder.models - - -class Migration(migrations.Migration): - - dependencies = [ - ("contenttypes", "0002_remove_content_type_name"), - ("django_zencoder", "0001_initial"), - ] - - operations = [ - migrations.CreateModel( - name="Thumbnail", - options={ - "db_table": "django_zencoder_thumbnail", - }, - fields=[ - ( - "id", - models.AutoField( - verbose_name="ID", - serialize=False, - primary_key=True, - auto_created=True, - ), - ), - ("object_id", models.PositiveIntegerField()), - ("time", models.PositiveIntegerField(verbose_name="Time (s)")), - ("width", models.PositiveIntegerField(verbose_name="Width", null=True)), - ( - "height", - models.PositiveIntegerField(verbose_name="Height", null=True), - ), - ( - "image", - models.ImageField( - max_length=512, - blank=True, - null=True, - upload_to=django_zencoder.models.thumbnail_upload_to, - ), - ), - ( - "content_type", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - to="contenttypes.ContentType", - ), - ), - ], - ), - migrations.AlterField( - model_name="format", - name="duration", - field=models.PositiveIntegerField(verbose_name="Duration (ms)", null=True), - ), - migrations.AlterField( - model_name="format", - name="extra_info", - field=models.TextField( - verbose_name="Zencoder information (JSON)", blank=True - ), - ), - migrations.AlterField( - model_name="format", - name="format", - field=models.CharField( - max_length=255, - choices=[ - ("mp4-high", "mp4-high"), - ("mp4-low", "mp4-low"), - ("webm-high", "webm-high"), - ("webm-low", "webm-low"), - ], - ), - ), - migrations.AlterField( - model_name="format", - name="height", - field=models.PositiveIntegerField(verbose_name="Height", null=True), - ), - migrations.AlterField( - model_name="format", - name="width", - field=models.PositiveIntegerField(verbose_name="Width", null=True), - ), - ] diff --git a/django_zencoder/migrations/0003_auto_20161031_1017.py b/django_zencoder/migrations/0003_auto_20161031_1017.py deleted file mode 100644 index 77ca8ba..0000000 --- a/django_zencoder/migrations/0003_auto_20161031_1017.py +++ /dev/null @@ -1,27 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("django_zencoder", "0002_auto_20161027_1629"), - ] - - operations = [ - migrations.AlterField( - model_name="format", - name="format", - field=models.CharField( - max_length=255, - choices=[ - ("H.264 (HD)", "H.264 (HD)"), - ("H.264", "H.264"), - ("VP8 (HD)", "VP8 (HD)"), - ("VP8", "VP8"), - ], - ), - ), - ] diff --git a/django_zencoder/migrations/0004_auto_20170729_1732.py b/django_zencoder/migrations/0004_auto_20170729_1732.py deleted file mode 100644 index dd32188..0000000 --- a/django_zencoder/migrations/0004_auto_20170729_1732.py +++ /dev/null @@ -1,27 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("django_zencoder", "0003_auto_20161031_1017"), - ] - - operations = [ - migrations.AlterField( - model_name="format", - name="format", - field=models.CharField( - max_length=255, - choices=[ - ("H.264 (HD)", "H.264 (HD)"), - ("H.264", "H.264"), - ("VP9 (HD)", "VP9 (HD)"), - ("VP9", "VP9"), - ], - ), - ), - ] diff --git a/django_zencoder/migrations/0005_prepare_migrations_for_app_rename.py b/django_zencoder/migrations/0005_prepare_migrations_for_app_rename.py deleted file mode 100644 index 3e544c8..0000000 --- a/django_zencoder/migrations/0005_prepare_migrations_for_app_rename.py +++ /dev/null @@ -1,41 +0,0 @@ -# Generated by Django 2.2.16 on 2020-09-30 13:49 - -from django.db import migrations - - -# This is required for permissions and co -def migrate_content_types(apps, schema_editor): - ContentType = apps.get_model("contenttypes", "ContentType") - ContentType.objects.filter(app_label="django_zencoder").update( - app_label="django_video_encoder" - ) - - -class Migration(migrations.Migration): - - dependencies = [ - ("django_zencoder", "0004_auto_20170729_1732"), - ] - - operations = [ - migrations.RunPython( - migrate_content_types, reverse_code=migrations.RunPython.noop - ), - migrations.AlterModelTable( - name="format", - table="django_video_encoder_format", - ), - migrations.AlterModelTable( - name="thumbnail", - table="django_video_encoder_thumbnail", - ), - # Black doesn't like SQL statements `\"` - # fmt: off - # Pre-faking the initial migrations as the upcoming version breaks also migration - # history - migrations.RunSQL( - "INSERT INTO django_migrations (\"app\", \"name\", \"applied\") " - "VALUES ('django_video_encoder', '0001_initial', NOW());" - ), - # fmt: on - ] diff --git a/example/models.py b/example/models.py index f3574ed..cdba3b9 100644 --- a/example/models.py +++ b/example/models.py @@ -1,7 +1,7 @@ from django.contrib.contenttypes.fields import GenericRelation from django.db import models -from django_zencoder.models import Format +from django_video_encoder.models import Format class Video(models.Model): diff --git a/example/settings.py b/example/settings.py index 5664550..b7c32ef 100644 --- a/example/settings.py +++ b/example/settings.py @@ -30,11 +30,11 @@ INSTALLED_APPS = [ "django.contrib.contenttypes", "django.contrib.sites", - "django_zencoder.apps.ZencoderConfig", + "django_video_encoder", "example", ] -ZENCODER_THUMBNAIL_INTERVAL = 20 -ZENCODER_FORMATS = [ +DJANGO_VIDEO_ENCODER_THUMBNAIL_INTERVAL = 20 +DJANGO_VIDEO_ENCODER_FORMATS = [ {"label": "H.264", "codec": "h264", "width": 720, "height": 480}, ] diff --git a/example/tests/test_base.py b/example/tests/test_base.py index b46ab8c..ee27333 100644 --- a/example/tests/test_base.py +++ b/example/tests/test_base.py @@ -3,16 +3,16 @@ from django.core.files import File from pytest import mark -from django_zencoder.api import encode +from django_video_encoder.api import encode from example.models import Video @mark.django_db def test_encode_called(mocker): - """Assert encode will try to send data to zencoder""" + """Assert encode will try to send data via the api""" file_mock = mock.MagicMock(spec=File) file_mock.name = "video.vid" - mocked_send_request = mocker.patch("django_zencoder.api.send_request") + mocked_send_request = mocker.patch("django_video_encoder.api.send_request") video_obj = Video(video_file=file_mock) encode(video_obj, "video_file") assert mocked_send_request.called diff --git a/example/urls.py b/example/urls.py index bb00a97..e6f0732 100644 --- a/example/urls.py +++ b/example/urls.py @@ -1,6 +1,6 @@ from django.conf.urls import url -from django_zencoder.views import notification +from django_video_encoder.views import notification urlpatterns = [ url(r"notify/", notification, name="zencoder_notification"), diff --git a/setup.cfg b/setup.cfg index 417d563..8f75dc5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,2 @@ [metadata] -version = attr: django_zencoder.__version__ +version = attr: django_video_encoder.__version__ diff --git a/setup.py b/setup.py index 9e3c352..55af6e9 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,12 @@ from setuptools import find_packages, setup setup( - name="django_zencoder", - description="Simple integration of a Django model with a FileField with zencoder.com", + name="django_video_encoder", + description="Simple integration of a Django model with a FileField to encoding backends", long_description=open("README.rst").read(), author="Jonas und der Wolf GmbH", author_email="opensource@jonasundderwolf.de", - url="http://github.com/jonasundderwolf/django-zencoder", + url="http://github.com/jonasundderwolf/django-video-encoder", packages=find_packages(), include_package_data=True, classifiers=[