def _get_metadata(self, file=None): if not hasattr(self, '_metadata_cache'): if not self: raise MetadataError metadata = get_video_specs(name=self.name) self._metadata_cache = metadata return self._metadata_cache
def to_python(self, value): raise Exception, 'VideoFileField to_python' if value is None: return value tmp, path = tempfile.mkstemp() os.write(tmp, self._file.read(512)) os.close(tmp) specs = get_video_specs(path) os.unlink(path) if not specs: raise exceptions.ValidationError( _('Uploaded file is in an unsupported format.'))
def render(self, name, value, attrs=None): output = ['<div style="margin-left: 106px">'] if value and hasattr(value, 'url'): output.append('<b>%s</b> %s<br />' % (_('Currently:'), value)) specs = get_video_specs(value.path) if specs: output.append('<b>size</b> %sx%s pixels<br />' % (specs['width'], specs['height'])) output.append('<b>duration</b> %s seconds<br />' % specs['duration']) output.append('<b>bitrate</b> %s kb/s<br />' % specs['bitrate']) if specs['video']: output.append('<b>video stream</b> %s<br />' % specs['video']) if specs['audio']: output.append('<b>audio stream</b> %s<br />' % specs['audio']) output.append(_('Change:')) output.append(super(AdminVideoWidget, self).render(name, value, attrs)) output.append('</div>') return mark_safe(u''.join(output))
def _metadata(self): if not hasattr(self, '_metadata_cache'): self._metadata_cache = get_video_specs(name=self.name) return self._metadata_cache