# Path: portal/signals.py
# def get_remote_filesize(sender, instance, **kwargs):
#     instance.size = _get_remote_filesize_for_url(instance.url)
# 
# def purge_files(sender, instance, **kwargs):
#     shutil.rmtree(settings.ENCODING_OUTPUT_DIR + instance.slug, True)
#     if instance.originalFile:
#         instance.originalFile.delete(False)
# 
# def get_mediatype(sender, instance, **kwargs):
#     instance.mediatype = MEDIA_FORMATS[instance.file_format].mediatype
# 
# Path: portal/licenses.py
# LICENSE_CHOICES = (
#     ("None", _(u"No License")),
#     ("CC0", _(u"Public Domain/CC0")),
#     ("CC-BY", _(u"CreativeCommons - Attribution")),
#     ("CC-BY-NC", _(u"CreativeCommons - Attribution - NonCommercial")),
#     ("CC-BY-NC-ND", _(u"CreativeCommons - Attribution - NonCommercial - NoDerivs")),
#     ("CC-BY-ND", _(u"CreativeCommons - Attribution - NoDerivs")),
# )
# 
# LICENSE_URLS = {'None': "",
#                 'CC0': _(u"https://creativecommons.org/publicdomain/zero/1.0/"),
#                 'CC-BY': _(u"http://creativecommons.org/licenses/by/3.0/"),
#                 'CC-BY-NC': _(u"http://creativecommons.org/licenses/by-nc/3.0/"),
#                 'CC-BY-NC-ND': _(u"http://creativecommons.org/licenses/by-nc-nd/3.0/"),
#                 'CC-BY-ND': _(u"http://creativecommons.org/licenses/by-nd/3.0/")
# }
# 
# Path: portal/media_formats.py
# FILE_FORMATS = (
#     ("MP3", "mp3"),
#     ("OGG", "ogg"),
#     ("OPUS", "Opus"),
#     ("MP4", "mp4"),
#     ("WEBM", "WebM")
# )
# 
# MEDIA_TYPES = (
#     ("audio", "audio"),
#     ("video", "video")
# )
# 
# MEDIA_FORMATS = {}


from django.utils.translation import ugettext_lazy as _
from django.db import models
from django.db.models.signals import pre_save, post_delete
from django.contrib.auth.models import User
from django.utils.formats import localize_input, date_format, time_format
from django.utils import timezone
from django.core.mail import send_mail
from autoslug import AutoSlugField
from taggit.managers import TaggableManager
from pytranscode.ffmpeg import ffmpeg
from portal.signals import get_remote_filesize, purge_files, get_mediatype
from portal.licenses import LICENSE_CHOICES, LICENSE_URLS
from portal.media_formats import FILE_FORMATS, MEDIA_TYPES, MEDIA_FORMATS
from portal.model_helpers import *
from mutagen.mp3 import MP3
from mutagen.id3 import ID3
from threading import Event
from BitTornadoABC.btmakemetafile import make_meta_file
from datetime import date
import djangotasks
import lambdaproject.settings as settings
import subprocess
import decimal
import re
import time
import os.path
import markdown
# -*- coding: utf-8 -*-












class MediaFile(models.Model):
    ''' The model only for the media files '''
    title = models.CharField(_(u"Title"),max_length=200)
    url = models.URLField(_(u"URL to Transcoded File"),  max_length=512, help_text=_(u"Insert the link to the media file"))
    file_format = models.CharField(_(u"File Format"), max_length=20, choices=FILE_FORMATS,default="MP3", help_text=_(u"File format of the media file"))
    size = models.BigIntegerField(_(u"File Size in Bytes"), null=True, blank=True)
    media_item = models.ForeignKey('portal.MediaItem', help_text=_(u"Media Item the file is connected to"))
    mediatype = models.CharField(_(u"Media Type"), max_length=20, choices=MEDIA_TYPES, default="audio", help_text=_(u"File type of the media file (audio or video)"))

    class Meta:
        verbose_name = _('Media File')
        verbose_name_plural = _('Media Files')

    def mime_type(self):
        return MEDIA_FORMATS[self.file_format].mime_type

    def extension(self):

# Path: portal/signals.py
# def get_remote_filesize(sender, instance, **kwargs):
#     instance.size = _get_remote_filesize_for_url(instance.url)
# 
# def purge_files(sender, instance, **kwargs):
#     shutil.rmtree(settings.ENCODING_OUTPUT_DIR + instance.slug, True)
#     if instance.originalFile:
#         instance.originalFile.delete(False)
# 
# def get_mediatype(sender, instance, **kwargs):
#     instance.mediatype = MEDIA_FORMATS[instance.file_format].mediatype
# 
# Path: portal/licenses.py
# LICENSE_CHOICES = (
#     ("None", _(u"No License")),
#     ("CC0", _(u"Public Domain/CC0")),
#     ("CC-BY", _(u"CreativeCommons - Attribution")),
#     ("CC-BY-NC", _(u"CreativeCommons - Attribution - NonCommercial")),
#     ("CC-BY-NC-ND", _(u"CreativeCommons - Attribution - NonCommercial - NoDerivs")),
#     ("CC-BY-ND", _(u"CreativeCommons - Attribution - NoDerivs")),
# )
# 
# LICENSE_URLS = {'None': "",
#                 'CC0': _(u"https://creativecommons.org/publicdomain/zero/1.0/"),
#                 'CC-BY': _(u"http://creativecommons.org/licenses/by/3.0/"),
#                 'CC-BY-NC': _(u"http://creativecommons.org/licenses/by-nc/3.0/"),
#                 'CC-BY-NC-ND': _(u"http://creativecommons.org/licenses/by-nc-nd/3.0/"),
#                 'CC-BY-ND': _(u"http://creativecommons.org/licenses/by-nd/3.0/")
# }
# 
# Path: portal/media_formats.py
# FILE_FORMATS = (
#     ("MP3", "mp3"),
#     ("OGG", "ogg"),
#     ("OPUS", "Opus"),
#     ("MP4", "mp4"),
#     ("WEBM", "WebM")
# )
# 
# MEDIA_TYPES = (
#     ("audio", "audio"),
#     ("video", "video")
# )
# 
# MEDIA_FORMATS = {}


# Path: portal/models.py
from django.utils.translation import ugettext_lazy as _
from django.db import models
from django.db.models.signals import pre_save, post_delete
from django.contrib.auth.models import User
from django.utils.formats import localize_input, date_format, time_format
from django.utils import timezone
from django.core.mail import send_mail
from autoslug import AutoSlugField
from taggit.managers import TaggableManager
from pytranscode.ffmpeg import ffmpeg
from portal.signals import get_remote_filesize, purge_files, get_mediatype
from portal.licenses import LICENSE_CHOICES, LICENSE_URLS
from portal.media_formats import FILE_FORMATS, MEDIA_TYPES, MEDIA_FORMATS
from portal.model_helpers import *
from mutagen.mp3 import MP3
from mutagen.id3 import ID3
from threading import Event
from BitTornadoABC.btmakemetafile import make_meta_file
from datetime import date
import djangotasks
import lambdaproject.settings as settings
import subprocess
import decimal
import re
import time
import os.path
import markdown

# -*- coding: utf-8 -*-












class MediaFile(models.Model):
    ''' The model only for the media files '''
    title = models.CharField(_(u"Title"),max_length=200)
    url = models.URLField(_(u"URL to Transcoded File"),  max_length=512, help_text=_(u"Insert the link to the media file"))
    file_format = models.CharField(_(u"File Format"), max_length=20, choices=FILE_FORMATS,default="MP3", help_text=_(u"File format of the media file"))
    size = models.BigIntegerField(_(u"File Size in Bytes"), null=True, blank=True)
    media_item = models.ForeignKey('portal.MediaItem', help_text=_(u"Media Item the file is connected to"))
    mediatype = models.CharField(_(u"Media Type"), max_length=20, choices=MEDIA_TYPES, default="audio", help_text=_(u"File type of the media file (audio or video)"))

    class Meta:
        verbose_name = _('Media File')
        verbose_name_plural = _('Media Files')

    def mime_type(self):
        return MEDIA_FORMATS[self.file_format].mime_type

    def extension(self):

        return MEDIA_FORMATS[self.file_format].extension