From 0f0db1c8d820619a9f45cac75a01257789ef9cdb Mon Sep 17 00:00:00 2001 From: Franco0712 Date: Thu, 2 Nov 2023 10:53:44 -0300 Subject: [PATCH] Formatter applied to the files in the video folder --- video/admin.py | 105 +++++++++------ video/models/__init__.py | 2 +- video/models/cuts.py | 90 ++++++++----- video/models/live.py | 281 ++++++++++++++++++++------------------- video/models/media.py | 176 +++++++++++++----------- video/models/tag.py | 15 ++- video/signals.py | 2 +- 7 files changed, 372 insertions(+), 299 deletions(-) diff --git a/video/admin.py b/video/admin.py index ac65f63a..d9015e49 100644 --- a/video/admin.py +++ b/video/admin.py @@ -55,9 +55,11 @@ def change_video_status_to_queued(modeladmin, request, queryset): try: video.to_queued() except TransitionNotAllowed: - modeladmin.message_user(request, - f'The status of the video {video.name} cannot be changed to the one entered.', - level=messages.ERROR, ) + modeladmin.message_user( + request, + f'The status of the video {video.name} cannot be changed to the one entered.', + level=messages.ERROR, + ) def change_video_status_to_queued_failed(modeladmin, request, queryset): @@ -65,9 +67,11 @@ def change_video_status_to_queued_failed(modeladmin, request, queryset): try: video.to_queued_failed() except TransitionNotAllowed: - modeladmin.message_user(request, - f'The status of the video {video.name} cannot be changed to the one entered.', - level=messages.ERROR, ) + modeladmin.message_user( + request, + f'The status of the video {video.name} cannot be changed to the one entered.', + level=messages.ERROR, + ) def change_video_status_to_processing(modeladmin, request, queryset): @@ -75,9 +79,11 @@ def change_video_status_to_processing(modeladmin, request, queryset): try: video.to_processing() except TransitionNotAllowed: - modeladmin.message_user(request, - f'The status of the video {video.name} cannot be changed to the one entered.', - level=messages.ERROR, ) + modeladmin.message_user( + request, + f'The status of the video {video.name} cannot be changed to the one entered.', + level=messages.ERROR, + ) def change_video_status_to_processing_failed(modeladmin, request, queryset): @@ -85,9 +91,11 @@ def change_video_status_to_processing_failed(modeladmin, request, queryset): try: video.to_processing_failed() except TransitionNotAllowed: - modeladmin.message_user(request, - f'The status of the video {video.name} cannot be changed to the one entered.', - level=messages.ERROR, ) + modeladmin.message_user( + request, + f'The status of the video {video.name} cannot be changed to the one entered.', + level=messages.ERROR, + ) def change_video_status_to_finished(modeladmin, request, queryset): @@ -95,9 +103,11 @@ def change_video_status_to_finished(modeladmin, request, queryset): try: video.to_finished() except TransitionNotAllowed: - modeladmin.message_user(request, - f'The status of the video {video.name} cannot be changed to the one entered.', - level=messages.ERROR, ) + modeladmin.message_user( + request, + f'The status of the video {video.name} cannot be changed to the one entered.', + level=messages.ERROR, + ) def re_process_video(modeladmin, request, queryset): @@ -105,9 +115,11 @@ def re_process_video(modeladmin, request, queryset): try: video.re_process() except TransitionNotAllowed: - modeladmin.message_user(request, - f'The status of the video {video.name} cannot be changed to the one entered.', - level=messages.ERROR, ) + modeladmin.message_user( + request, + f'The status of the video {video.name} cannot be changed to the one entered.', + level=messages.ERROR, + ) # Videos status function for live videos @@ -116,9 +128,11 @@ def change_live_video_status_to_on(modeladmin, request, queryset): try: video.to_on() except TransitionNotAllowed: - modeladmin.message_user(request, - f'The status of the live video {video.name} cannot be changed to the one entered.', - level=messages.ERROR, ) + modeladmin.message_user( + request, + f'The status of the live video {video.name} cannot be changed to the one entered.', + level=messages.ERROR, + ) def change_live_video_status_to_off(modeladmin, request, queryset): @@ -126,9 +140,11 @@ def change_live_video_status_to_off(modeladmin, request, queryset): try: video.to_off() except TransitionNotAllowed: - modeladmin.message_user(request, - f'The status of the live video {video.name} cannot be changed to the one entered.', - level=messages.ERROR, ) + modeladmin.message_user( + request, + f'The status of the live video {video.name} cannot be changed to the one entered.', + level=messages.ERROR, + ) def change_live_video_status_to_starting(modeladmin, request, queryset): @@ -136,9 +152,11 @@ def change_live_video_status_to_starting(modeladmin, request, queryset): try: video.to_starting() except TransitionNotAllowed: - modeladmin.message_user(request, - f'The status of the live video {video.name} cannot be changed to the one entered.', - level=messages.ERROR, ) + modeladmin.message_user( + request, + f'The status of the live video {video.name} cannot be changed to the one entered.', + level=messages.ERROR, + ) def change_live_video_status_to_stopping(modeladmin, request, queryset): @@ -146,16 +164,22 @@ def change_live_video_status_to_stopping(modeladmin, request, queryset): try: video.to_stopping() except TransitionNotAllowed: - modeladmin.message_user(request, - f'The status of the live video {video.name} cannot be changed to the one entered.', - level=messages.ERROR, ) + modeladmin.message_user( + request, + f'The status of the live video {video.name} cannot be changed to the one entered.', + level=messages.ERROR, + ) # Videos status description for VOD change_video_status_to_queued.short_description = 'Change status to Queued' -change_video_status_to_queued_failed.short_description = 'Change status to Queued (Failed)' +change_video_status_to_queued_failed.short_description = ( + 'Change status to Queued (Failed)' +) change_video_status_to_processing.short_description = 'Change status to Processing' -change_video_status_to_processing_failed.short_description = 'Change status to Processing (Failed)' +change_video_status_to_processing_failed.short_description = ( + 'Change status to Processing (Failed)' +) change_video_status_to_finished.short_description = 'Change status to Finished' re_process_video.short_description = 'Re-process video' @@ -187,7 +211,7 @@ class VideoAdmin(admin.ModelAdmin): 'organization__name', 'video_id', ) - + readonly_fields = ( 'video_id', 'created_by', @@ -202,7 +226,7 @@ class VideoAdmin(admin.ModelAdmin): change_video_status_to_processing, change_video_status_to_processing_failed, change_video_status_to_finished, - re_process_video + re_process_video, ] form = VideoForm @@ -211,14 +235,9 @@ def save_model(self, request, obj, form, change): # Only set added_by during the first save. obj.created_by = request.user super().save_model(request, obj, form, change) - + def get_readonly_fields(self, request, obj=None): - readonly_fields = [ - 'video_id', - 'created_by', - 'state', - 'created_at' - ] + readonly_fields = ['video_id', 'created_by', 'state', 'created_at'] if obj is not None: readonly_fields.append('media_type') @@ -244,7 +263,7 @@ class LiveVideoAdmin(admin.ModelAdmin): 'organization', 'created_by', 'state', - 'created_at' + 'created_at', ) list_filter = ( 'organization', @@ -259,7 +278,7 @@ class LiveVideoAdmin(admin.ModelAdmin): change_live_video_status_to_on, change_live_video_status_to_off, change_live_video_status_to_starting, - change_live_video_status_to_stopping + change_live_video_status_to_stopping, ] form = LiveVideoForm diff --git a/video/models/__init__.py b/video/models/__init__.py index e58cc2e0..922b2190 100644 --- a/video/models/__init__.py +++ b/video/models/__init__.py @@ -1,4 +1,4 @@ from .tag import Tag from .media import Media from .live import LiveVideo -from .cuts import LiveVideoCut \ No newline at end of file +from .cuts import LiveVideoCut diff --git a/video/models/cuts.py b/video/models/cuts.py index f6bc334d..a720ba3a 100644 --- a/video/models/cuts.py +++ b/video/models/cuts.py @@ -21,31 +21,37 @@ class State: CHOICES = ( (SCHEDULED, SCHEDULED), (EXECUTING, EXECUTING), - (PERFORMED, PERFORMED) + (PERFORMED, PERFORMED), ) - live = models.ForeignKey(LiveVideo, - related_name='cuts', - verbose_name='Video related to the cut', - on_delete=models.CASCADE, - ) - initial_time = models.DateTimeField(null=True, blank=True, - verbose_name='Cut start time') - final_time = models.DateTimeField(null=True, blank=True, - verbose_name='Cut end time') - description = models.CharField(max_length=200, - default='', - verbose_name='Cut reason' - ) - created_by = models.ForeignKey(Account, - models.SET_NULL, - related_name='uploaded_live_video_cut', - verbose_name='Created by', - null=True) - state = FSMField(default=State.SCHEDULED, - verbose_name='Cut state', - choices=State.CHOICES, - protected=True) + live = models.ForeignKey( + LiveVideo, + related_name='cuts', + verbose_name='Video related to the cut', + on_delete=models.CASCADE, + ) + initial_time = models.DateTimeField( + null=True, blank=True, verbose_name='Cut start time' + ) + final_time = models.DateTimeField( + null=True, blank=True, verbose_name='Cut end time' + ) + description = models.CharField( + max_length=200, default='', verbose_name='Cut reason' + ) + created_by = models.ForeignKey( + Account, + models.SET_NULL, + related_name='uploaded_live_video_cut', + verbose_name='Created by', + null=True, + ) + state = FSMField( + default=State.SCHEDULED, + verbose_name='Cut state', + choices=State.CHOICES, + protected=True, + ) def __str__(self): return f'{self.live.name} (executed at:{self.initial_time} resumed at:{self.final_time})' @@ -65,7 +71,10 @@ def _to_performed(self): def to_executing(self): self._to_executing() - if self.live.state not in [LiveVideo.State.STOPPING, LiveVideo.State.OFF]: + if self.live.state not in [ + LiveVideo.State.STOPPING, + LiveVideo.State.OFF, + ]: self.live.to_stopping() self.save(update_fields=['state']) @@ -73,7 +82,10 @@ def to_executing(self): def to_performed(self): self._to_performed() - if self.live.state not in [LiveVideo.State.STARTING, LiveVideo.State.ON]: + if self.live.state not in [ + LiveVideo.State.STARTING, + LiveVideo.State.ON, + ]: self.live.to_starting() self.save(update_fields=['state']) @@ -94,18 +106,22 @@ def live_pre_save_receiver(sender, instance, update_fields, **kwargs): if not validate_dates(instance): raise IntegrityError( - 'There is already a break in the interval entered or the start date is in the past.') + 'There is already a break in the interval entered or the start date is in the past.' + ) def validate_dates(instance): - if instance.final_time <= instance.initial_time or \ - (instance.initial_time < timezone.now() and - instance.state in [LiveVideoCut.State.SCHEDULED]): + if instance.final_time <= instance.initial_time or ( + instance.initial_time < timezone.now() + and instance.state in [LiveVideoCut.State.SCHEDULED] + ): return False - queryset = LiveVideoCut.objects.filter(live=instance.live, - initial_time__lt=instance.final_time, - final_time__gt=instance.initial_time) + queryset = LiveVideoCut.objects.filter( + live=instance.live, + initial_time__lt=instance.final_time, + final_time__gt=instance.initial_time, + ) if instance.id: queryset = queryset.exclude(id=instance.id) @@ -118,9 +134,11 @@ def validate_dates(instance): @shared_task def check_live_cuts(): now = timezone.now() - cuts_to_off = LiveVideoCut.objects.filter(state=LiveVideoCut.State.SCHEDULED, - initial_time__lte=now) - cuts_to_on = LiveVideoCut.objects.filter(state=LiveVideoCut.State.EXECUTING, - final_time__lte=now) + cuts_to_off = LiveVideoCut.objects.filter( + state=LiveVideoCut.State.SCHEDULED, initial_time__lte=now + ) + cuts_to_on = LiveVideoCut.objects.filter( + state=LiveVideoCut.State.EXECUTING, final_time__lte=now + ) list(map(lambda cut: cut.to_executing(), cuts_to_off)) list(map(lambda cut: cut.to_performed(), cuts_to_on)) diff --git a/video/models/live.py b/video/models/live.py index b65efa2f..349c9d32 100644 --- a/video/models/live.py +++ b/video/models/live.py @@ -15,6 +15,7 @@ from utils import cloudfront, medialive, cloudwatchevents, sns, cloudwatchlogs from . import Tag + class LiveVideo(models.Model): ''' Constants to represent the state`s of the Streaming @@ -28,136 +29,128 @@ class State: WAITING_INPUT = 'waiting_input' DELETING = 'deleting' - CHOICES = ( - (OFF, OFF), - (ON, ON), - (STARTING, STARTING), - (STOPPING, STOPPING) - ) + CHOICES = ((OFF, OFF), (ON, ON), (STARTING, STARTING), (STOPPING, STOPPING)) class GeoType: WHITELIST = 'whitelist' BLACKLIST = 'blacklist' NONE = 'none' - CHOICES = ( - (WHITELIST, WHITELIST), - (BLACKLIST, BLACKLIST), - (NONE, NONE) - ) + CHOICES = ((WHITELIST, WHITELIST), (BLACKLIST, BLACKLIST), (NONE, NONE)) AUTOPLAY_CHOICES = (('c', 'Channel'), ('y', 'Yes'), ('n', 'No')) - video_id = models.CharField(max_length=36, - default=uuid.uuid4, - unique=True, - db_index=True, - verbose_name='Video ID') - - name = models.CharField(max_length=254, - verbose_name='Name') - - created_by = models.ForeignKey(Account, - models.SET_NULL, - related_name='uploaded_live_video', - verbose_name='Created by', - null=True) - - organization = models.ForeignKey(Organization, - models.CASCADE, - related_name='live_videos', - verbose_name='Organization') - - channel = models.ForeignKey(Channel, - models.CASCADE, - null=True, - blank=True, - related_name='live_videos', - verbose_name='Channel') - - tags = models.ManyToManyField(Tag, - related_name='live_videos', - verbose_name='Tags', - blank=True) - - state = FSMField(default=State.OFF, - verbose_name='Live Video state', - choices=State.CHOICES, - protected=True) - - input_state = ArrayField(models.CharField(max_length=255, - default='', - verbose_name='Origin state'), - default=list, - blank=True) - - metadata = JSONField(max_length=500, - blank=True, - default=dict, - verbose_name='Metadata') - - ads_vast_url = models.URLField(blank=True, - null=True, - max_length=1024, - verbose_name='VAST URL (ads)') - - enable_ads = models.BooleanField(default=True, - verbose_name='Enable Ads?') - - created_at = models.DateTimeField(editable=False, - default=timezone.now, - verbose_name='Created') - - ml_input_url = models.CharField(max_length=254, - editable=False, - default='', - verbose_name='Input Url') - - ml_input_id = models.CharField(max_length=36, - editable=False, - default='', - verbose_name='Input Id') - - ml_channel_arn = models.CharField(max_length=254, - editable=False, - default='', - verbose_name='Channel Arn') - - sns_topic_arn = models.CharField(max_length=254, - editable=False, - default='', - verbose_name='Topic Arn') - - autoplay = models.CharField(max_length=1, - default='c', - choices=AUTOPLAY_CHOICES, - verbose_name='Autoplay?' - ) - - cf_id = models.CharField(max_length=100, - verbose_name='Cf_id', - editable=False, - default='') - - cf_domain = models.CharField(max_length=100, - verbose_name='Cf_domain', - editable=False, - default='') - - geolocation_type = models.CharField(max_length=20, - editable=True, - choices=GeoType.CHOICES, - default=GeoType.NONE, - verbose_name='Geolocation Type' - ) - - geolocation_countries = ArrayField(models.CharField(max_length=2, - editable=True, - default='', - verbose_name='Geolocation Countries'), - default=list, - blank=True - ) + video_id = models.CharField( + max_length=36, + default=uuid.uuid4, + unique=True, + db_index=True, + verbose_name='Video ID', + ) + + name = models.CharField(max_length=254, verbose_name='Name') + + created_by = models.ForeignKey( + Account, + models.SET_NULL, + related_name='uploaded_live_video', + verbose_name='Created by', + null=True, + ) + + organization = models.ForeignKey( + Organization, + models.CASCADE, + related_name='live_videos', + verbose_name='Organization', + ) + + channel = models.ForeignKey( + Channel, + models.CASCADE, + null=True, + blank=True, + related_name='live_videos', + verbose_name='Channel', + ) + + tags = models.ManyToManyField( + Tag, related_name='live_videos', verbose_name='Tags', blank=True + ) + + state = FSMField( + default=State.OFF, + verbose_name='Live Video state', + choices=State.CHOICES, + protected=True, + ) + + input_state = ArrayField( + models.CharField(max_length=255, default='', verbose_name='Origin state'), + default=list, + blank=True, + ) + + metadata = JSONField( + max_length=500, blank=True, default=dict, verbose_name='Metadata' + ) + + ads_vast_url = models.URLField( + blank=True, null=True, max_length=1024, verbose_name='VAST URL (ads)' + ) + + enable_ads = models.BooleanField(default=True, verbose_name='Enable Ads?') + + created_at = models.DateTimeField( + editable=False, default=timezone.now, verbose_name='Created' + ) + + ml_input_url = models.CharField( + max_length=254, editable=False, default='', verbose_name='Input Url' + ) + + ml_input_id = models.CharField( + max_length=36, editable=False, default='', verbose_name='Input Id' + ) + + ml_channel_arn = models.CharField( + max_length=254, editable=False, default='', verbose_name='Channel Arn' + ) + + sns_topic_arn = models.CharField( + max_length=254, editable=False, default='', verbose_name='Topic Arn' + ) + + autoplay = models.CharField( + max_length=1, default='c', choices=AUTOPLAY_CHOICES, verbose_name='Autoplay?' + ) + + cf_id = models.CharField( + max_length=100, verbose_name='Cf_id', editable=False, default='' + ) + + cf_domain = models.CharField( + max_length=100, verbose_name='Cf_domain', editable=False, default='' + ) + + geolocation_type = models.CharField( + max_length=20, + editable=True, + choices=GeoType.CHOICES, + default=GeoType.NONE, + verbose_name='Geolocation Type', + ) + + geolocation_countries = ArrayField( + models.CharField( + max_length=2, + editable=True, + default='', + verbose_name='Geolocation Countries', + ), + default=list, + blank=True, + ) def __init__(self, *args, **kwargs): super(LiveVideo, self).__init__(*args, **kwargs) @@ -191,14 +184,18 @@ def _to_on(self): def _to_starting(self): pass - @transition(field=state, source=[State.STARTING, State.ON, State.WAITING_INPUT], target=State.STOPPING) + @transition( + field=state, + source=[State.STARTING, State.ON, State.WAITING_INPUT], + target=State.STOPPING, + ) def _to_stopping(self): pass @transition(field=state, source=[State.OFF], target=State.DELETING) def _to_deleting(self): pass - + def to_starting(self): self._to_starting() medialive.start_channel(self) @@ -222,11 +219,11 @@ def to_off(self): self._to_off() self.input_state.clear() self.save() - + def to_deleting(self): self._to_deleting() self.save() - channel_id = self.ml_channel_arn.split(':')[-1] + channel_id = self.ml_channel_arn.split(':')[-1] account_id = self.organization.aws_account.account_id video_id = self.video_id try: @@ -234,14 +231,16 @@ def to_deleting(self): except medialive.ChannelNotFoundException: pass finally: - medialive.delete_input(self.ml_input_id,account_id) + medialive.delete_input(self.ml_input_id, account_id) cloudfront.update_distribution(self.organization, self.cf_id, False) cloudwatchevents.remove_targets(self) cloudwatchevents.delete_rule(self) sns.unsubscribe_all(self) sns.delete_topic(self) - cloudfront._delete_cloudfront_distribution.delay(self.cf_id, account_id, video_id) - + cloudfront._delete_cloudfront_distribution.delay( + self.cf_id, account_id, video_id + ) + @receiver(pre_save, sender=LiveVideo, dispatch_uid='validate_save_fields') def live_pre_save_receiver(sender, instance, **kwargs): @@ -283,7 +282,9 @@ def live_video_post_save_receiver(sender, instance, created, **kwargs): 'defaultTTL': 5, 'maxTTL': 10, } - new_distribution = cloudfront.create_distribution(cf_settings, instance.organization, instance.channel) + new_distribution = cloudfront.create_distribution( + cf_settings, instance.organization, instance.channel + ) instance.cf_id = new_distribution['cf_id'] instance.cf_domain = new_distribution['cf_domain'] @@ -291,15 +292,25 @@ def live_video_post_save_receiver(sender, instance, created, **kwargs): instance.save() # Executed only if geoblocking options are updated - elif instance._old_geolocation_type != instance.geolocation_type or \ - instance._old_geolocation_countries != instance.geolocation_countries: - cloudfront.update_distribution_geoblocking(instance.cf_id, instance.geolocation_type, - instance.geolocation_countries, - instance.organization) + elif ( + instance._old_geolocation_type != instance.geolocation_type + or instance._old_geolocation_countries != instance.geolocation_countries + ): + cloudfront.update_distribution_geoblocking( + instance.cf_id, + instance.geolocation_type, + instance.geolocation_countries, + instance.organization, + ) # Executed only if channel is updated elif instance._old_channel and instance._old_channel.id != instance.channel.id: - cloudfront.tag_distribution(instance.organization, instance.cf_id, [('vh:channel-id', str(instance.channel.id))]) + cloudfront.tag_distribution( + instance.organization, + instance.cf_id, + [('vh:channel-id', str(instance.channel.id))], + ) + @receiver(cloudfront_deleted) def handle_cloudfront_deleted(sender, video_id, **kwargs): diff --git a/video/models/media.py b/video/models/media.py index 1161200f..452a7dcf 100644 --- a/video/models/media.py +++ b/video/models/media.py @@ -34,97 +34,93 @@ class State: (QUEUED, QUEUED), (PROCESSING, PROCESSING), (PROCESSING_FAILED, PROCESSING_FAILED), - (FINISHED, FINISHED) + (FINISHED, FINISHED), ) AUTOPLAY_CHOICES = (('c', 'Channel'), ('y', 'Yes'), ('n', 'No')) MEDIA_TYPE_CHOICES = (('audio', 'Audio'), ('video', 'Video')) - video_id = models.CharField(max_length=36, - default=uuid.uuid4, - unique=True, - db_index=True, - verbose_name='Content ID') - - name = models.CharField(max_length=254, - verbose_name='Name') - - created_by = models.ForeignKey(Account, - models.SET_NULL, - related_name='uploaded_videos', - verbose_name='Created by', - null=True) - - organization = models.ForeignKey(Organization, - models.CASCADE, - related_name='media', - verbose_name='Organization') - - channel = models.ForeignKey(Channel, - models.CASCADE, - null=True, - blank=True, - related_name='media', - verbose_name='Channel') - - tags = models.ManyToManyField(Tag, - related_name='media', - verbose_name='Tags', - blank=True) - - state = FSMField(default=State.WAITING_FILE, - verbose_name='Video State', - choices=State.CHOICES, - protected=True) + video_id = models.CharField( + max_length=36, + default=uuid.uuid4, + unique=True, + db_index=True, + verbose_name='Content ID', + ) - metadata = JSONField( - max_length=500, blank=True, default={}, - verbose_name='Metadata' + name = models.CharField(max_length=254, verbose_name='Name') + + created_by = models.ForeignKey( + Account, + models.SET_NULL, + related_name='uploaded_videos', + verbose_name='Created by', + null=True, ) - ads_vast_url = models.URLField( - blank=True, + organization = models.ForeignKey( + Organization, + models.CASCADE, + related_name='media', + verbose_name='Organization', + ) + + channel = models.ForeignKey( + Channel, + models.CASCADE, null=True, - max_length=1024, - verbose_name='VAST URL (ads)' + blank=True, + related_name='media', + verbose_name='Channel', + ) + + tags = models.ManyToManyField( + Tag, related_name='media', verbose_name='Tags', blank=True + ) + + state = FSMField( + default=State.WAITING_FILE, + verbose_name='Video State', + choices=State.CHOICES, + protected=True, + ) + + metadata = JSONField( + max_length=500, blank=True, default={}, verbose_name='Metadata' ) - enable_ads = models.BooleanField( - default=True, - verbose_name='Enable Ads?' + ads_vast_url = models.URLField( + blank=True, null=True, max_length=1024, verbose_name='VAST URL (ads)' ) + enable_ads = models.BooleanField(default=True, verbose_name='Enable Ads?') + autoplay = models.CharField( max_length=1, default='c', choices=AUTOPLAY_CHOICES, - verbose_name='Autoplay?' + verbose_name='Autoplay?', ) created_at = models.DateTimeField( - editable=False, - default=timezone.now, - verbose_name='Created' + editable=False, default=timezone.now, verbose_name='Created' ) media_type = models.CharField( max_length=5, default='video', choices=MEDIA_TYPE_CHOICES, - verbose_name='Content Type' + verbose_name='Content Type', ) - + has_thumbnail = models.BooleanField( - default=False, - verbose_name='Has custom thumbnail?' + default=False, verbose_name='Has custom thumbnail?' ) - storage = models.BigIntegerField(default=0, - verbose_name='Size in bytes') + storage = models.BigIntegerField(default=0, verbose_name='Size in bytes') - duration = models.IntegerField(default=0, - verbose_name='Duration in seconds') + duration = models.IntegerField(default=0, verbose_name='Duration in seconds') def __str__(self): return f'{self.video_id} ({self.name})' @@ -139,7 +135,7 @@ def get_urls(self): # Hacky patch. Don't know how you'd get into this state! if channel is None: return "", "", "" - + media_url = '' # Default mime type for video @@ -154,7 +150,9 @@ def get_urls(self): media_url = f'https://{channel.cf_domain}/{self.video_id}/audio/output.mp4' mime_type = 'audio/mp4' - thumb_path = 'thumb.jpg' if self.has_thumbnail else 'thumbs/thumb_high.0000000.jpg' + thumb_path = ( + 'thumb.jpg' if self.has_thumbnail else 'thumbs/thumb_high.0000000.jpg' + ) poster_url = f'https://{channel.cf_domain}/{self.video_id}/{thumb_path}' return poster_url, media_url, mime_type @@ -175,14 +173,24 @@ def _to_processing(self): def _to_processing_failed(self): pass - @transition(field=state, source=[State.PROCESSING, State.QUEUED], target=State.FINISHED) + @transition( + field=state, + source=[State.PROCESSING, State.QUEUED], + target=State.FINISHED, + ) def _to_finished(self): pass - @transition(field=state, - source=[State.FINISHED, State.PROCESSING_FAILED, State.FAILED, - State.QUEUING_FAILED], - target=State.QUEUED) + @transition( + field=state, + source=[ + State.FINISHED, + State.PROCESSING_FAILED, + State.FAILED, + State.QUEUING_FAILED, + ], + target=State.QUEUED, + ) def _re_process(self): pass @@ -206,7 +214,9 @@ def to_processing_failed(self): def to_finished(self): self._to_finished() - self.storage = s3.get_size(self.organization, self.organization.bucket_name, self.video_id) + self.storage = s3.get_size( + self.organization, self.organization.bucket_name, self.video_id + ) self.save() def re_process(self): @@ -214,16 +224,26 @@ def re_process(self): self.metadata = {} # Delete files on S3 - s3.delete_object(self.organization.bucket_name, '{}/thumb'.format(self.video_id), - self.organization.aws_account) - s3.delete_object(self.organization.bucket_name, '{}/hls'.format(self.video_id), - self.organization.aws_account) + s3.delete_object( + self.organization.bucket_name, + '{}/thumb'.format(self.video_id), + self.organization.aws_account, + ) + s3.delete_object( + self.organization.bucket_name, + '{}/hls'.format(self.video_id), + self.organization.aws_account, + ) # Invalidate cache on CloudFront - cloudfront.create_invalidation(self.organization, self.channel.cf_id, [ - '/{}/thumb/*'.format(self.video_id), - '/{}/hls/*'.format(self.video_id) - ]) + cloudfront.create_invalidation( + self.organization, + self.channel.cf_id, + [ + '/{}/thumb/*'.format(self.video_id), + '/{}/hls/*'.format(self.video_id), + ], + ) mediaconvert.transcode(self) self.save() @@ -236,4 +256,8 @@ def video_pre_delete_receiver(sender, instance, **kwargs): key = instance.video_id - s3.delete_object(instance.organization.bucket_name, key, instance.organization.aws_account) + s3.delete_object( + instance.organization.bucket_name, + key, + instance.organization.aws_account, + ) diff --git a/video/models/tag.py b/video/models/tag.py index 5f445ac9..e8410523 100644 --- a/video/models/tag.py +++ b/video/models/tag.py @@ -4,13 +4,14 @@ class Tag(models.Model): - name = models.CharField(max_length=254, - verbose_name='Name') - organization = models.ForeignKey(Organization, - models.CASCADE, - null=True, - related_name='tags', - verbose_name='Organization') + name = models.CharField(max_length=254, verbose_name='Name') + organization = models.ForeignKey( + Organization, + models.CASCADE, + null=True, + related_name='tags', + verbose_name='Organization', + ) def __str__(self): return self.name diff --git a/video/signals.py b/video/signals.py index 43a1e1cf..03cc726a 100644 --- a/video/signals.py +++ b/video/signals.py @@ -1,3 +1,3 @@ from django.dispatch import Signal -cloudfront_deleted = Signal() \ No newline at end of file +cloudfront_deleted = Signal()