+ def get_icon_url(self):
+ if not self.icon:
+ return ''
+ return urljoin(
+ 'https://' + Site.objects.get_current().domain,
+ self.icon.url
+ )
+
+
+class Config(models.Model):
+ name = models.CharField(max_length=255)
+ intro_flac = models.FileField(upload_to='config/intro_flac', blank=True)
+ intro_min_seconds = models.IntegerField()
+ outro_flac = models.FileField(upload_to='config/outro_flac', blank=True)
+ outro_min_seconds = models.IntegerField()
+
+ class Meta:
+ verbose_name = _("Configuration")
+ verbose_name_plural = _("Configurations")
+
+ def __str__(self):
+ return self.name
+
+ def prepare_audio(self, audiobook):
+ total_duration = audiobook.total_duration
+ files = []
+ if self.intro_flac and total_duration > self.intro_min_seconds and audiobook.is_first:
+ files.append(standardize_audio(self.intro_flac.path))
+ files.append(standardize_audio(audiobook.source_file.path))
+ if self.outro_flac and total_duration > self.outro_min_seconds and audiobook.is_last:
+ files.append(standardize_audio(self.outro_flac.path))
+ output = concat_audio(files)
+ for d in files:
+ unlink(d)
+ return output
+