diff --git a/spa/models/mix.py b/spa/models/mix.py index 43f3f75..c5ca565 100755 --- a/spa/models/mix.py +++ b/spa/models/mix.py @@ -103,17 +103,14 @@ class Mix(BaseModel): self.slug = unique_slugify(self, self.title) self.clean_image('mix_image', Mix) - # Check for the unlikely event that the waveform has been generated - if cdn.file_exists('{0}{1}.png'.format(settings.WAVEFORM_URL, self.uid)): - self.waveform_generated = True - try: - self.duration = mp3_length(self.get_absolute_path()) - except Mp3FileNotFoundException: - # Not really bothered about this in save as it can be called before we have an mp3 - pass - super(Mix, self).save(force_insert, force_update, using, update_fields) + def set_cdn_details(self, path): + self.waveform_generated = True + self.duration = mp3_length(path) + self.save(update_fields=["waveform_generated", "duration"]) + self.update_file_http_headers(self.uid, self.title) + def create_mp3_tags(self, prefix=""): try: tag_mp3( diff --git a/spa/signals.py b/spa/signals.py index 2756d6c..a570e18 100755 --- a/spa/signals.py +++ b/spa/signals.py @@ -1,16 +1,13 @@ +from django.contrib.auth.models import User from django.contrib.sessions.models import Session from django.core.exceptions import ObjectDoesNotExist from django.db.models.signals import post_save, pre_save, m2m_changed from django.dispatch import Signal, receiver -from django.contrib.auth.models import User -from core.realtime import activity - -from core.utils.audio.mp3 import mp3_length from spa.models import SocialAccountLink from spa.models.activity import ActivityFollow -from spa.models.userprofile import UserProfile from spa.models.mix import Mix +from spa.models.userprofile import UserProfile waveform_generated_signal = Signal() @@ -23,10 +20,7 @@ def _waveform_generated_callback(sender, **kwargs): if uid is not None: mix = Mix.objects.get(uid=uid) if mix is not None: - mix.waveform_generated = True - mix.duration = mp3_length(path) - mix.save(update_fields=["waveform_generated", "duration"]) - + mix.set_cdn_details(path) except ObjectDoesNotExist: print("Mix has still not been uploaded") pass diff --git a/spa/tasks.py b/spa/tasks.py index d98688a..1d87cd9 100755 --- a/spa/tasks.py +++ b/spa/tasks.py @@ -36,6 +36,14 @@ def create_waveform_task(in_file, uid): logger.error("Outfile is missing") +@task(time_limit=3600) +def update_file_http_headers(uid, title): + cdn.set_azure_details( + blob_name='{0}.mp3'.format(uid), + download_name='Deep South Sounds - {0}.mp3'.format(title), + container_name='mixes') + + @task(time_limit=3600) def upload_to_cdn_task(filetype, uid, container_name): source_file = os.path.join(settings.CACHE_ROOT, '{0}/{1}.{2}'.format(container_name, uid, filetype))