def item_export(self, request, public_id, extension=None, mime_type=None, return_availability=False): """Export a given media item in the specified format (OGG, FLAC, ...)""" item = MediaItem.objects.get(public_id=public_id) public_access = get_item_access(item, request.user) raw = False if not extension: extension = item.file.path.split('.')[-1] raw = True if (not public_access == 'full' or not extension in settings.TELEMETA_STREAMING_FORMATS) and \ not (request.user.has_perm('telemeta.can_play_all_items') or request.user.is_superuser): mess = ugettext('Access not allowed') title = 'Item file : ' + public_id + '.' + extension + ' : ' + mess description = ugettext('Please login or contact the website administator to get a private access.') messages.error(request, title) return render(request, 'telemeta/messages.html', {'description': description}) if raw: media = item.file.path response = serve_media(media, content_type=item.mimetype) if return_availability: data = json.dumps({'available': True}) return HttpResponse(data, content_type='application/json') return response (media, mime_type) = self.item_transcode(item, extension) if media: if return_availability: data = json.dumps({'available': True}) return HttpResponse(data, content_type='application/json') response = serve_media(media, content_type=mime_type) return response else: if return_availability: data = json.dumps({'available': False}) return HttpResponse(data, content_type='application/json') mess = ugettext('Transcoding in progress') title = ugettext('Item') + ' : ' + public_id + ' : ' + mess description = ugettext('The media transcoding is in progress. ' 'Please wait for the trancoding process to complete.') messages.info(request, title) response = render(request, 'telemeta/messages.html', {'description': description}) from django.utils.cache import patch_cache_control #patch_cache_control(response, no_cache=True, no_store=True, must_revalidate=True) return response
def item_visualize(self, request, public_id, grapher_id, width, height): try: width = int(width) height = int(height) except: pass if not isinstance(width, int) or not isinstance(height, int): size = self.default_grapher_sizes[0] width = int(size.split('x')[0]) height = int(size.split('x')[1]) item = MediaItem.objects.get(public_id=public_id) mime_type = 'image/png' source, source_type = item.get_source() # if source: # ts_item, c = ts.models.Item.objects.get_or_create(**{source_type: source}) # if c: # ts_item.title = item.title # ts_item.save() # # ts_grapher, c = ts.models.Processor.objects.get_or_create(pid=grapher_id) # ts_preset, c = ts.models.Preset.objects.get_or_create(processor=ts_grapher, # parameters={'width': width, 'height': height}) # ts_experience = ts_preset.get_single_experience() # ts_selection = ts_item.get_single_selection() # ts_task, c = ts.models.Task.objects.get_or_create(experience=ts_experience, # selection=ts_selection) # ts_task.run() grapher = self.get_grapher(grapher_id) if grapher.id() != grapher_id: raise Http404 size = str(width) + '_' + str(height) image_file = '.'.join([public_id, grapher_id, size, 'png']) # FIX waveform grapher name change old_image_file = '.'.join([public_id, 'waveform', size, 'png']) if 'waveform_centroid' in grapher_id and self.cache_data.exists(old_image_file): image_file = old_image_file path = self.cache_data.dir + os.sep + image_file if not self.cache_data.exists(image_file): source, _ = item.get_source() if source: decoder = timeside.core.get_processor('file_decoder')(source) graph = grapher(width=width, height=height) (decoder | graph).run() graph.watermark('timeside', opacity=.6, margin=(5, 5)) #f = open(path, 'w') graph.render(output=path) # f.close() self.cache_data.add_file(image_file) response = serve_media(path, content_type=mime_type) return response
def related_media_item_download(self, request, item_public_id, media_id): item = get_object_or_404(MediaItem, code=item_public_id) media = get_object_or_404(MediaItemRelated, item=item, id=media_id) if media.file: response = serve_media(media.file.path, content_type=media.mime_type) else: raise Http404 return response
def related_media_item_download(self, request, item_public_id, media_id): item = get_object_or_404(MediaItem, code=item_public_id) media = get_object_or_404(MediaItemRelated, item=item, id=media_id) if media.file: response = serve_media(media.file.path, content_type=media.mime_type) else: raise Http404 return response
def related_download(self, request, type, public_id, media_id): self.setup(type) resource = self.model.objects.get(code=public_id) media = self.related.objects.get(resource=resource, id=media_id) if media.file: response = serve_media(media.file.path, content_type=media.mime_type) else: raise Http404 return response
def related_download(self, request, type, public_id, media_id): self.setup(type) resource = self.model.objects.get(code=public_id) media = self.related.objects.get(resource=resource, id=media_id) if media.file: response = serve_media(media.file.path, content_type=media.mime_type) else: raise Http404 return response
def related_media_collection_download(self, request, public_id, media_id): collection = MediaCollection.objects.get(public_id=public_id) media = MediaCollectionRelated.objects.get(collection=collection, id=media_id) response = serve_media(media.file.path, content_type=media.mime_type) return response
def related_media_collection_download(self, request, public_id, media_id): collection = MediaCollection.objects.get(public_id=public_id) media = MediaCollectionRelated.objects.get(collection=collection, id=media_id) response = serve_media(media.file.path, content_type=media.mime_type) return response
def item_export(self, request, public_id, extension, return_availability=False): """Export a given media item in the specified format (OGG, FLAC, ...)""" item = MediaItem.objects.get(public_id=public_id) public_access = get_item_access(item, request.user) if not extension: extension = item.file.path.split('.')[-1] if (not public_access == 'full' or not extension in settings.TELEMETA_STREAMING_FORMATS) and \ not (request.user.has_perm('telemeta.can_play_all_items') or request.user.is_superuser): mess = ugettext('Access not allowed') title = 'Item file : ' + public_id + '.' + extension + ' : ' + mess description = ugettext('Please login or contact the website administator to get a private access.') messages.error(request, title) return render(request, 'telemeta/messages.html', {'description': description}) # FIXME: MP4 handling in TimeSide if 'mp4' in extension: mime_type = 'video/mp4' video = item.file.path response = serve_media(video, content_type=mime_type) # response['Content-Disposition'] = 'attachment' # TF : I don't know why empty attachment was set # TODO: remove if useless if return_availability: data = json.dumps({'available': True}) return HttpResponse(data, content_type='application/json') return response if 'webm' in extension: mime_type = 'video/webm' video = item.file.path response = serve_media(video, content_type=mime_type) # response['Content-Disposition'] = 'attachment' # TF : I don't know why empty attachment was set, # TODO: remove if useless if return_availability: data = json.dumps({'available': True}) return HttpResponse(data, content_type='application/json') return response (media, mime_type) = self.item_transcode(item, extension) #media = None if media: if return_availability: data = json.dumps({'available': True}) return HttpResponse(data, content_type='application/json') response = serve_media(media, content_type=mime_type) return response else: if return_availability: data = json.dumps({'available': False}) return HttpResponse(data, content_type='application/json') mess = ugettext('Transcoding in progress') title = ugettext('Item') + ' : ' + public_id + ' : ' + mess description = ugettext('The media transcoding is in progress. ' 'Please wait for the trancoding process to complete.') messages.info(request, title) response = render(request, 'telemeta/messages.html', {'description': description}) from django.utils.cache import patch_cache_control #patch_cache_control(response, no_cache=True, no_store=True, must_revalidate=True) return response