diff --git a/deploy/docker/local_settings.py b/deploy/docker/local_settings.py index 7dbad9a..f5da61f 100644 --- a/deploy/docker/local_settings.py +++ b/deploy/docker/local_settings.py @@ -32,3 +32,16 @@ CELERY_RESULT_BACKEND = BROKER_URL MP4HLS_COMMAND = "/home/mediacms.io/bento4/bin/mp4hls" DEBUG = False + +USE_S3_FOR_MEDIA_STORAGE = True +AWS_ACCESS_KEY = 'x' +AWS_SECRET_KEY = 'Y' +S3_BUCKET_NAME = 'Z' + + +# S3 work plan +# 1. Enter settings that you're using S3 OK +# 2. Enter a migration remote_urls on Media/Encode OK +# 3. add task that puts content to S3, removes local file, sets remote_urls +# 4. API response for orig/encod/hls from S3 --> plays?? +# 5. script to migrate existing to S3 diff --git a/files/migrations/0003_remote_urls.py b/files/migrations/0003_remote_urls.py new file mode 100644 index 0000000..de5e39a --- /dev/null +++ b/files/migrations/0003_remote_urls.py @@ -0,0 +1,23 @@ +# Generated by Django 3.1.8 on 2021-07-26 16:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('files', '0002_auto_20201201_0712'), + ] + + operations = [ + migrations.AddField( + model_name='encoding', + name='remote_urls', + field=models.JSONField(default=dict, help_text='This will keep any url'), + ), + migrations.AddField( + model_name='media', + name='remote_urls', + field=models.JSONField(default=dict, help_text='This will keep any url'), + ), + ] diff --git a/files/models.py b/files/models.py index 3339d4d..29d113e 100644 --- a/files/models.py +++ b/files/models.py @@ -284,6 +284,8 @@ class Media(models.Model): video_height = models.IntegerField(default=1) views = models.IntegerField(db_index=True, default=1) + # this will keep any cloud url info, as original_file, probably hls files, encoding files etc + remote_urls = models.JSONField(default=dict, help_text='This will keep any url') # keep track if media file has changed, on saves __original_media_file = None @@ -691,7 +693,11 @@ class Media(models.Model): ep = {} ep["title"] = encoding.profile.name - ep["url"] = encoding.media_encoding_url + if encoding.remote_urls and encoding.remote_urls.get('media_encoding_url'): + url = encoding.remote_urls.get('media_encoding_url') + else: + url = encoding.media_encoding_url + ep["url"] = url ep["progress"] = encoding.progress ep["size"] = encoding.size ep["encoding_id"] = encoding.id @@ -731,11 +737,15 @@ class Media(models.Model): def original_media_url(self): """Property used on serializers""" - if settings.SHOW_ORIGINAL_MEDIA: - return helpers.url_from_path(self.media_file.path) - else: + if not settings.SHOW_ORIGINAL_MEDIA: return None + if self.remote_urls and self.remote_urls.get('original_media_url'): + url = self.remote_urls.get('original_media_url') + else: + url = helpers.url_from_path(self.media_file.path) + return url + @property def thumbnail_url(self): """Property used on serializers @@ -1077,6 +1087,9 @@ class Encoding(models.Model): worker = models.CharField(max_length=100, blank=True) + # this will keep any cloud url info, as original_file, probably hls files, encoding files etc + remote_urls = models.JSONField(default=dict, help_text='This will keep any url') + @property def media_encoding_url(self): if self.media_file: diff --git a/requirements.txt b/requirements.txt index 58ac65d..3619f64 100644 --- a/requirements.txt +++ b/requirements.txt @@ -30,4 +30,6 @@ m3u8 django-ckeditor django-debug-toolbar -django-login-required-middleware==0.6.1 \ No newline at end of file +django-login-required-middleware==0.6.1 + +boto3==1.17.111