# 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
        context['width'] = width
        context['height'] = height
        context['related_media'] = related_media
        context['mime_type'] = self.mime_type
        context['last_revision'] = last_revision
        context['format'] = item_format
        context['private_extra_types'] = private_extra_types.values()
        context['site'] = 'http://' + Site.objects.all()[0].name
        context['rang_item_playlist'] = rang
        # if ts_item:
        #     context['ts_item_id'] = ts_item.pk
        # else:
        #     context['ts_item_id'] = None

        return context


class DublinCoreToFormatMetadata(object):
    """a mapping class to get item DublinCore metadata dictionaries
    in various audio metadata format (MP3, OGG, etc...)"""

    # FIXME: should be given by timeside
    unavailable_extensions = ['wav', 'aiff', 'aif', 'flac', 'webm']

    metadata_mapping = {
        'mp3': {
            'title': 'TIT2',  # title2
            'creator': 'TCOM',  # composer
            'creator': 'TPE1',  # lead
            'identifier': 'UFID',  # unique ID

# 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

        context['width'] = width
        context['height'] = height
        context['related_media'] = related_media
        context['mime_type'] = self.mime_type
        context['last_revision'] = last_revision
        context['format'] = item_format
        context['private_extra_types'] = private_extra_types.values()
        context['site'] = 'http://' + Site.objects.all()[0].name
        context['rang_item_playlist'] = rang
        # if ts_item:
        #     context['ts_item_id'] = ts_item.pk
        # else:
        #     context['ts_item_id'] = None

        return context


class DublinCoreToFormatMetadata(object):
    """a mapping class to get item DublinCore metadata dictionaries
    in various audio metadata format (MP3, OGG, etc...)"""

    # FIXME: should be given by timeside
    unavailable_extensions = ['wav', 'aiff', 'aif', 'flac', 'webm']

    metadata_mapping = {
        'mp3': {
            'title': 'TIT2',  # title2
            'creator': 'TCOM',  # composer
            'creator': 'TPE1',  # lead
            'identifier': 'UFID',  # unique ID

            'relation': 'TALB',  # album