Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return {
VideoQuality.lowest: '50',
VideoQuality.default: '22',
VideoQuality.highest: '4'
}[quality]
elif self is MediaFormats.mp4:
return {
VideoQuality.lowest: '28',
VideoQuality.default: '24',
VideoQuality.highest: '18'
}[quality]
elif self is MediaFormats.ogg:
return {
VideoQuality.lowest: '5',
VideoQuality.default: '7',
VideoQuality.highest: '9'
}[quality]
def get_quality_param(self, quality):
if self is MediaFormats.webm:
return {
VideoQuality.lowest: '50',
VideoQuality.default: '22',
VideoQuality.highest: '4'
}[quality]
elif self is MediaFormats.mp4:
return {
VideoQuality.lowest: '28',
VideoQuality.default: '24',
VideoQuality.highest: '18'
}[quality]
elif self is MediaFormats.ogg:
return {
VideoQuality.lowest: '5',
VideoQuality.default: '7',
VideoQuality.highest: '9'
}[quality]
form=BaseVideoForm,
fields=fields,
formfield_callback=formfield_for_dbfield,
# set the 'file' widget to a FileInput rather than the default ClearableFileInput
# so that when editing, we don't get the 'currently: ...' banner which is
# a bit pointless here
widgets={
'tags': widgets.AdminTagWidget,
'file': forms.FileInput(),
'thumbnail': forms.FileInput(),
})
class VideoTranscodeAdminForm(forms.Form):
media_format = EnumField(MediaFormats)
quality = EnumField(VideoQuality)
def __init__(self, video, data=None, **kwargs):
super(VideoTranscodeAdminForm, self).__init__(data=data, **kwargs)
self.video = video
def save(self):
media_format = self.cleaned_data['media_format']
quality = self.cleaned_data['quality']
self.video.do_transcode(media_format, quality)
GroupVideoPermissionFormSet = collection_member_permission_formset_factory(
Video,
[
('add_video', _("Add"), _("Add/edit images you own")),
('change_video', _("Edit"), _("Edit any video")),
with get_local_file(instance.file) as file_path:
if has_changed or instance.thumbnail is None:
instance.thumbnail = ffmpeg.get_thumbnail(file_path)
if has_changed or instance.duration is None:
instance.duration = ffmpeg.get_duration(file_path)
instance.file_size = instance.file.size
instance._from_signal = True
instance.save()
del instance._from_signal
class AbstractVideoTranscode(models.Model):
media_format = EnumChoiceField(MediaFormats)
quality = EnumChoiceField(VideoQuality, default=VideoQuality.default)
processing = models.BooleanField(default=False)
file = models.FileField(null=True, blank=True, verbose_name=_('file'),
upload_to=get_upload_to)
error_message = models.TextField(blank=True)
@property
def url(self):
return self.file.url
def get_upload_to(self, filename):
folder_name = 'video_transcodes'
filename = self.file.field.storage.get_valid_name(filename)
return os.path.join(folder_name, filename)
class Meta:
abstract = True
if self is MediaFormats.webm:
return {
VideoQuality.lowest: '50',
VideoQuality.default: '22',
VideoQuality.highest: '4'
}[quality]
elif self is MediaFormats.mp4:
return {
VideoQuality.lowest: '28',
VideoQuality.default: '24',
VideoQuality.highest: '18'
}[quality]
elif self is MediaFormats.ogg:
return {
VideoQuality.lowest: '5',
VideoQuality.default: '7',
VideoQuality.highest: '9'
}[quality]