# Path: telemeta/views/core.py
# def serve_media(media_path, content_type="", buffering=True, streaming=False):
#     if not settings.DEBUG:
#         return nginx_media_accel(media_path, content_type=content_type,
#                                  buffering=buffering, streaming=streaming)
#     else:
#         try:
#             response = FileResponse(open(media_path, 'rb'))
#         except:    
#             response = StreamingHttpResponse(stream_from_file(media_path), content_type=content_type)
#         filename = os.path.basename(media_path)
#         if not streaming:
#             response['Content-Disposition'] = 'attachment; ' + 'filename=' + filename
#         return response
# 
# Path: telemeta/views/core.py
# class TelemetaBaseMixin(object):
# 
#     MEDIA_ROOT = getattr(settings, 'MEDIA_ROOT')
#     CACHE_DIR = os.path.join(MEDIA_ROOT, 'cache')
#     cache_data = TelemetaCache(getattr(settings, 'TELEMETA_DATA_CACHE_DIR', CACHE_DIR))
#     cache_export = TelemetaCache(getattr(settings, 'TELEMETA_EXPORT_CACHE_DIR', os.path.join(CACHE_DIR, 'export')))
#     cache_tmp = TelemetaCache(getattr(settings, 'FILE_UPLOAD_TEMP_DIR', os.path.join(MEDIA_ROOT, 'tmp')))


import telemeta
import timeside.core
import timeside.server as ts
import sys
import time
from telemeta.views.core import *
from telemeta.views.core import serve_media
from telemeta.views.core import TelemetaBaseMixin
from telemeta.views.marker import *
                from telemeta.tasks import task_transcode
            from django.utils.cache import patch_cache_control
        from django.db.models import get_models
        from django.db.models import get_models
        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')

# Path: telemeta/views/core.py
# def serve_media(media_path, content_type="", buffering=True, streaming=False):
#     if not settings.DEBUG:
#         return nginx_media_accel(media_path, content_type=content_type,
#                                  buffering=buffering, streaming=streaming)
#     else:
#         try:
#             response = FileResponse(open(media_path, 'rb'))
#         except:    
#             response = StreamingHttpResponse(stream_from_file(media_path), content_type=content_type)
#         filename = os.path.basename(media_path)
#         if not streaming:
#             response['Content-Disposition'] = 'attachment; ' + 'filename=' + filename
#         return response
# 
# Path: telemeta/views/core.py
# class TelemetaBaseMixin(object):
# 
#     MEDIA_ROOT = getattr(settings, 'MEDIA_ROOT')
#     CACHE_DIR = os.path.join(MEDIA_ROOT, 'cache')
#     cache_data = TelemetaCache(getattr(settings, 'TELEMETA_DATA_CACHE_DIR', CACHE_DIR))
#     cache_export = TelemetaCache(getattr(settings, 'TELEMETA_EXPORT_CACHE_DIR', os.path.join(CACHE_DIR, 'export')))
#     cache_tmp = TelemetaCache(getattr(settings, 'FILE_UPLOAD_TEMP_DIR', os.path.join(MEDIA_ROOT, 'tmp')))


# Path: telemeta/views/item.py
import telemeta
import timeside.core
import timeside.server as ts
import sys
import time
from telemeta.views.core import *
from telemeta.views.core import serve_media
from telemeta.views.core import TelemetaBaseMixin
from telemeta.views.marker import *
                from telemeta.tasks import task_transcode
            from django.utils.cache import patch_cache_control
        from django.db.models import get_models
        from django.db.models import get_models

        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)