diff --git a/core/utils/audio/__init__.py b/core/utils/audio/__init__.py new file mode 100644 index 0000000..dfa5fc7 --- /dev/null +++ b/core/utils/audio/__init__.py @@ -0,0 +1 @@ +class Mp3FileNotFoundException(Exception): pass diff --git a/core/utils/audio/mp3.py b/core/utils/audio/mp3.py new file mode 100644 index 0000000..7ea5fa9 --- /dev/null +++ b/core/utils/audio/mp3.py @@ -0,0 +1,10 @@ +from mutagen.mp3 import MP3 +from core.utils.audio import Mp3FileNotFoundException + + +def mp3_length(source_file): + try: + audio = MP3(source_file) + return audio.info.length + except IOError: + raise Mp3FileNotFoundException("Audio file not found: %s" % source_file) \ No newline at end of file diff --git a/dss/settings.py b/dss/settings.py index 4b8a402..2fb61dd 100644 --- a/dss/settings.py +++ b/dss/settings.py @@ -124,13 +124,14 @@ AUTHENTICATION_BACKENDS = global_settings.AUTHENTICATION_BACKENDS + ( ) MIDDLEWARE_CLASSES = ( + 'django.middleware.gzip.GZipMiddleware', + 'htmlmin.middleware.HtmlMinifyMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'django.middleware.gzip.GZipMiddleware', 'spa.middleware.uploadify.SWFUploadMiddleware', #'spa.middleware.sqlprinter.SqlPrintingMiddleware', #'debug_toolbar.middleware.DebugToolbarMiddleware', @@ -251,3 +252,5 @@ COMPRESS_CSS_FILTERS = [ import mimetypes mimetypes.add_type("text/xml", ".plist", False) + +HTML_MINIFY = localsettings.HTML_MINIFY \ No newline at end of file diff --git a/spa/management/commands/cleanup.py b/spa/management/commands/cleanup.py deleted file mode 100644 index 023b4ae..0000000 --- a/spa/management/commands/cleanup.py +++ /dev/null @@ -1,9 +0,0 @@ -from shutil import copyfile -from django.core.management.base import NoArgsCommand -import os -from spa.models import Mix - -class Command(NoArgsCommand): - def handle_noargs(self, **options): - mixes = Mix.objects.all() - diff --git a/spa/management/commands/processaudio.py b/spa/management/commands/processaudio.py new file mode 100644 index 0000000..23d8497 --- /dev/null +++ b/spa/management/commands/processaudio.py @@ -0,0 +1,26 @@ +import os +from django.core.management.base import NoArgsCommand, CommandError +from core.utils.audio import Mp3FileNotFoundException +from core.utils.audio.mp3 import mp3_length +from dss import settings +from spa.models import Mix + + +class Command(NoArgsCommand): + help = "Updates audio files with their durations" + + def handle(self, *args, **options): + try: + candidates = Mix.objects.filter(duration__isnull=True) + for mix in candidates: + try: + print "Finding duration for: %s" % mix.title + length = mp3_length(mix.get_absolute_path()) + print "\tLength: %d" % length + mix.duration = length + mix.save() + except Mp3FileNotFoundException, me: + mix.delete() + print me.message + except Exception, ex: + raise CommandError(ex.message) \ No newline at end of file diff --git a/spa/management/commands/tracklists.py b/spa/management/commands/tracklists.py index aaad0c4..5b13aba 100644 --- a/spa/management/commands/tracklists.py +++ b/spa/management/commands/tracklists.py @@ -1,10 +1,8 @@ -import os -from dss import settings -from core.utils.waveform import generate_waveform +from django.core.management.base import NoArgsCommand + from spa.models import Tracklist from spa.models.Mix import Mix -from spa.models.Release import ReleaseAudio -from django.core.management.base import NoArgsCommand + class Command(NoArgsCommand): help = "Create tracklists for all mixes" diff --git a/spa/management/commands/waveforms.py b/spa/management/commands/waveforms.py index 093981f..0743acd 100644 --- a/spa/management/commands/waveforms.py +++ b/spa/management/commands/waveforms.py @@ -12,10 +12,7 @@ class Command(NoArgsCommand): help = "Generate all outstanding waveforms" def _generateWaveform(self, mix): - fileName, extension = os.path.splitext(mix.local_file.name) - if extension == "" or extension == ".": - extension = ".mp3" - in_file = '%s/%s%s' % (settings.CACHE_ROOT, mix.uid, extension) + in_file = mix.get_absolute_path() try: if os.path.isfile(in_file): create_waveform_task.delay(in_file=in_file, mix_uid=mix.uid) diff --git a/spa/middleware/stripwhitespace.py b/spa/middleware/stripwhitespace.py new file mode 100644 index 0000000..f1450a8 --- /dev/null +++ b/spa/middleware/stripwhitespace.py @@ -0,0 +1,39 @@ +""" +Tightens up response content by removed superflous line breaks and whitespace. +By Doug Van Horn + +---- CHANGES ---- +v1.1 - 31st May 2011 +Cal Leeming [Simplicity Media Ltd] +Modified regex to strip leading/trailing white space from every line, not just those with blank \n. + +---- TODO ---- +* Ensure whitespace isn't stripped from within
or or